Skip to content

[assets-controllers] Upgrade TokensController to fully utilize controller-messenger pattern - #3690

Merged
MajorLift merged 28 commits into
mainfrom
231220-TokensController-v2-migration
Feb 9, 2024
Merged

[assets-controllers] Upgrade TokensController to fully utilize controller-messenger pattern#3690
MajorLift merged 28 commits into
mainfrom
231220-TokensController-v2-migration

Conversation

@MajorLift

@MajorLiftMajorLift commented Dec 20, 2023

Copy link
Copy Markdown
Contributor

Motivation

Remove TokenDetectionController constructor callbacks for TokensController.

  • TokensController features should be exposed as messenger actions/events so that consumers don't need to import the entire class.
  • TokensController should use messenger action/events to consume external controller features instead of callbacks.

Explanation

  • Replaces constructor options callbacks onPreferencesStateChange, onNetworkDidChange, onTokenListStateChange, getNetworkClientById with messenger actions (NetworkController:getNetworkClientById) and events (PreferencesController:stateChange, NetworkController:networkDidChange, TokenListController:stateChange).
  • Replaces tokens-controller callbacks in token-detection-controller and token-balances-controller with TokensController:getState, TokensController:addDetectedTokens actions and TokensController:stateChange event.

References

Changelog

@metamask/assets-controllers

Added

  • TokensController now exports TokensControllerActions, TokensControllerGetStateAction, TokensControllerAddDetectedTokensAction, TokensControllerEvents, TokensControllerStateChangeEvent. (#3690)

Changed

  • BREAKING: The TokensState type is now defined as a type alias rather than an interface. (#3690)
    • This is breaking because it could affect how this type is used with other types, such as Json, which does not support TypeScript interfaces.

Removed

  • BREAKING:TokenDetectionController constructor no longer accepts options onPreferencesStateChange, getPreferencesState, getTokensState, addDetectedTokens. (#3690, #3775)
  • BREAKING:TokensController constructor no longer accepts options onPreferencesStateChange, onNetworkDidChange, onTokenListStateChange, getNetworkClientById. (#3690)
  • BREAKING:TokenBalancesController constructor no longer accepts options onTokensStateChange, getSelectedAddress. (#3690)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@MajorLiftMajorLift added the team-wallet-framework Deprecated: Please use `team-core-platform` instead. label Dec 20, 2023
@MajorLiftMajorLift self-assigned this Dec 20, 2023
Base automatically changed from 231201-token-detection-controller-basecontrollerv2-migration to mainDecember 22, 2023 19:05
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from aa491fd to a49fbb1CompareJanuary 8, 2024 17:33
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from 1d86730 to 1567287CompareJanuary 19, 2024 01:14
@MajorLift
MajorLift changed the base branch from main to 230113-consolidate-TokenDetectionController-DetectTokensControllerJanuary 20, 2024 04:35
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch 2 times, most recently from 1f596d7 to 5695134CompareJanuary 21, 2024 21:09
@MajorLiftMajorLift changed the title Upgrade TokensController to v2Upgrade TokensController to fully utilize controller-messenger patternJan 21, 2024
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from edcf6d7 to bcd731fCompareJanuary 21, 2024 21:42
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from e8b624c to 209effdCompareJanuary 21, 2024 21:44
@MajorLift
MajorLift marked this pull request as ready for review January 21, 2024 21:51
@MajorLift
MajorLift requested a review from a team as a January 21, 2024 21:51
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from 209effd to e9e4a4eCompareJanuary 22, 2024 01:14
@MajorLiftMajorLift changed the title Upgrade TokensController to fully utilize controller-messenger pattern[assets-controllers] Upgrade TokensController to fully utilize controller-messenger patternJan 22, 2024
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from 197e379 to 8231533CompareJanuary 24, 2024 05:39
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch 2 times, most recently from 9a95fb4 to 2575c72CompareJanuary 24, 2024 17:26

@mcmiremcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Had some comments. I believe all of them are relatively minor except for perhaps TokensState.

Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from 1957a33 to ca19f99CompareJanuary 26, 2024 21:25
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch 2 times, most recently from 6e8925b to 51223a2CompareJanuary 29, 2024 17:04
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from 40434c1 to ed74732CompareJanuary 29, 2024 18:32
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from 51223a2 to f149b29CompareJanuary 29, 2024 18:39

@mcmiremcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one comment.

- This is needed to track balances accross chains. It was introduced for the "polling by `networkClientId`" feature, but is useful on its own as well.
- **BREAKING**: `AccountTrackerController` adds a mutex to `refresh` making it only possible for one call to be executed at time ([#3586](https://github.com/MetaMask/core/pull/3586))
- **BREAKING**: `TokensController.watchAsset` now performs on-chain validation of the asset's symbol and decimals, if they're defined in the contract ([#1745](https://github.com/MetaMask/core/pull/1745))
- **BREAKING:** `AccountTrackerController` adds a mutex to `refresh` making it only possible for one call to be executed at time ([#3586](https://github.com/MetaMask/core/pull/3586))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. We have a ticket to check this on the auto-changelog side: MetaMask/auto-changelog#109

Comment threadpackages/assets-controllers/CHANGELOG.md
@MajorLift
MajorLiftforce-pushed the 230113-consolidate-TokenDetectionController-DetectTokensController branch from 754b46f to 88eb7caCompareFebruary 6, 2024 21:46
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from 24f2d73 to 11da214CompareFebruary 6, 2024 22:55
MajorLiftand others added 23 commits February 8, 2024 16:22
… `getState`, `addDetectedTokens` messenger actions
…`TokensController:addDetectedTokens` messenger actions
…ntroller callbacks with messenger actions/events.
- `getSelectedAddress` replaced with `PreferencesController:getState` action
- `onTokensStateChange` replaced with `TokensController:stateChange` event
…` action, `TokensController:stateChange` event
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
…TokensController:getState` calls for `ignoredTokens`
commit 5f9f474d2211de4306ae2507d193d854f3090561
Merge: 2108233 a3863017c
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Feb 8 16:28:06 2024 -0500
Merge remote-tracking branch 'origin/231220-TokensController-v2-migration' into 231220-TokensController-v2-migration
commit a3863017c058ce071d36ce7ba09dc46dd3bef25d
Merge: 5200f854f 582b370
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Feb 8 13:09:06 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit 582b370
Merge: 4a944d8065fd91
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Feb 8 13:08:19 2024 -0500
Merge branch 'main' into 230113-consolidate-TokenDetectionController-DetectTokensController
commit 5200f854f933a809d59f32299ac9a34a7416c685
Merge: 68999bed4 4a944d8
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Feb 7 13:54:44 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit 4a944d8
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Feb 7 13:44:59 2024 -0500
Apply suggestions to CHANGELOG
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
commit 68999bed480b67becf9c90d37e5ff76d7021a46c
Merge: 11da214f5 e01f993
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 17:58:58 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit e01f993
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 17:56:39 2024 -0500
test: adjust coverage thresholds
commit 11da214f5cf173d15b3a657353f89b6ae96071d5
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 17:54:53 2024 -0500
test: adjust coverage thresholds
commit 01cf7967c948244a6a95d16b72c3511dd3ecae5e
Merge: d501062c5 88eb7ca
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 17:53:49 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit d501062c585dc3716c45b541369e0f3e63f10853
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 16:50:02 2024 -0500
[token-detection-controller] Fix typing for `STATIC_MAINNET_TOKEN_LIST`
commit 8556d7af546cf9f0aa19c107f7160fd73bdde487
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 16:49:37 2024 -0500
[token-detection-controller] Fix `detectTokens` to remove redundant `TokensController:getState` calls for `ignoredTokens`
commit 88eb7ca
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 15:31:40 2024 -0500
Replace `detectTokens` with `#restartTokenDetection` in `networkDidChange` listener
commit 91be385
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Feb 6 09:19:18 2024 -0500
Include `#stopPolling()` call in `KeyringController:lock` listener
commit 9a4ae93
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 31 10:28:32 2024 -0500
In changelog, move new actions/events under "Added" heading
commit 312e450
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 13:31:43 2024 -0500
In networkDidChange event listener, detect tokens if `networkClientId` is changed instead of `chainId`, and avoid resetting polling interval
commit 04df278
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 16:24:46 2024 -0500
Changelog linter fix
commit 907b4df
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 11:02:38 2024 -0500
test: remove unnecessary action handler unregisters
commit f1af71a
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 10:51:50 2024 -0500
Use `networkClientId` instead of `chainId` in `#restartTokenDetection`
commit 7c25f3c
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 10:49:10 2024 -0500
Extract `findCaseInsensitiveMatch` helper function
commit 2db0081
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:08:17 2024 -0500
Update packages/assets-controllers/CHANGELOG.md
Update packages/assets-controllers/CHANGELOG.md
commit 968c0c0
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:05:04 2024 -0500
[assets-controllers] Bump `@metamask/kerying-api` to ^3.0.0 and remove yarn resolutions entry for `@metamask/providers`
commit 2be2e24
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 20:14:09 2024 -0500
Add CHANGELOG entries
commit 1173eb9
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:39:47 2024 -0500
test: adjust for removal of `getPreferencesState` callback
commit c90de3e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:38:58 2024 -0500
test: add callbacks for all allowed actions, events as `WithControllerCallback` arguments
commit ad11ac7
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:36:59 2024 -0500
test: adjust action,event allowlist in `buildTokenDetectionControllerMessenger`
commit 4b303b4
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:32:46 2024 -0500
Minor refactors to event listeners for consistency
commit beacf9b
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:31:23 2024 -0500
Replace preferences controller callbacks in constructor with `getState` action and `stateChange` event
commit b5bd0e8
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:29:42 2024 -0500
Remove unused `NetworkControllerStateChange` event
- **BREAKING**: use `NetworkControllerNetworkDidChangeEvent` instead
commit 3fbdffa
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:25:37 2024 -0500
Add `@metamask/keyring-api` as devDep (for `InternalAccount` type in tests)
commit a44ccf7
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 20:31:40 2024 -0500
Add yarn resolutions entry to resolve conflicting `@metamask/providers` versions used by `@metamask/accounts-controller`
commit 7016835
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 17:04:04 2024 -0500
Define `#registerEventListeners` constructor helper private method
commit adc8dca
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 16:09:45 2024 -0500
Make `#isUnlocked` property non-optional
commit 78e9fde
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:56:10 2024 -0500
test: adjust coverage thresholds
commit 3fd2138
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:39:20 2024 -0500
test: Fix incorrect mock for `KeyringController:getState`
commit 5df6b81
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 12 14:33:07 2024 -0500
test: add actions, events, callbacks to test messenger
commit 33818aa
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:53:02 2024 -0500
Exclude `detectedTokens` already stored in tokens-controller state from `tokensToDetect`
commit 129c82e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:46:43 2024 -0500
Use legacy token list from contract-metadata repo to perform auto-detection if active network is mainnet and token detection is disabled in preferences
commit 0f46fdc
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:35:16 2024 -0500
Add `#trackMetaMetricsEvent` tracker property and call
commit 2485341
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:28:33 2024 -0500
Define `#registerKeyringListeners`, `isActive` methods
commit 8e204e6
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:56:20 2024 -0500
Subscribe to `AccountsController:selectedAccountChange` event
commit ea96025
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:54:47 2024 -0500
Define and apply `#restartTokenDetection` method
commit 2d31cce
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:48:41 2024 -0500
[assets-controllers] Install `{accounts,keyring}-controller` as deps and peerDeps
commit 6fde161
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Feb 5 10:05:23 2024 -0500
[token-detection-controller] test: remove unnecessary `as unknown as` cast
commit e504d2e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Feb 2 16:45:08 2024 -0500
Update packages/assets-controllers/CHANGELOG.md
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
commit 129fda6
Merge: 1d7a5805efcc1e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 31 10:30:13 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit 5efcc1e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 31 10:28:32 2024 -0500
In changelog, move new actions/events under "Added" heading
commit 1d7a580
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 15:25:17 2024 -0500
test: adjust coverage thresholds
commit f149b29
Merge: 1b7d9a5ed74732
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 13:38:56 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit ed74732
Merge: aed885a8c09b16
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 13:31:47 2024 -0500
Merge branch 'main' into 230113-consolidate-TokenDetectionController-DetectTokensController
commit aed885a
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 13:31:43 2024 -0500
In networkDidChange event listener, detect tokens if `networkClientId` is changed instead of `chainId`, and avoid resetting polling interval
commit 1b7d9a5
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 12:03:39 2024 -0500
test: rename `registerListeners` to `promiseForApprovals`
commit 41f4f1d
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 12:03:19 2024 -0500
test: move `addRequestHandler` initialization to individual test
commit 1c86179
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 12:02:35 2024 -0500
test: initialize `getNetworkClientByIdHandler` in `beforeEach`
commit a66fd26
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 29 12:01:48 2024 -0500
test: remove unnecessary action handler unregisters
commit 25fe76d
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 18:20:23 2024 -0500
Remove `BaseState` from `TokensState`
commit c8f9a71
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 16:59:59 2024 -0500
Linter fix
commit d4a65de
Merge: 2575c72ca19f99
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 16:59:13 2024 -0500
Merge branch '230113-consolidate-TokenDetectionController-DetectTokensController' into 231220-TokensController-v2-migration
commit ca19f99
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 16:24:46 2024 -0500
Changelog linter fix
commit b49a545
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 11:02:38 2024 -0500
test: remove unnecessary action handler unregisters
commit 571c3b2
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 10:51:50 2024 -0500
Use `networkClientId` instead of `chainId` in `#restartTokenDetection`
commit 8eff112
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 26 10:49:10 2024 -0500
Extract `findCaseInsensitiveMatch` helper function
commit 6df8aa4
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:08:17 2024 -0500
Update packages/assets-controllers/CHANGELOG.md
Update packages/assets-controllers/CHANGELOG.md
commit d77bce0
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:05:04 2024 -0500
[assets-controllers] Bump `@metamask/kerying-api` to ^3.0.0 and remove yarn resolutions entry for `@metamask/providers`
commit c434e8f
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 20:14:09 2024 -0500
Add CHANGELOG entries
commit 392140e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:39:47 2024 -0500
test: adjust for removal of `getPreferencesState` callback
commit 169554f
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:38:58 2024 -0500
test: add callbacks for all allowed actions, events as `WithControllerCallback` arguments
commit fc9b631
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:36:59 2024 -0500
test: adjust action,event allowlist in `buildTokenDetectionControllerMessenger`
commit 99d35f3
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:32:46 2024 -0500
Minor refactors to event listeners for consistency
commit 3d74e54
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:31:23 2024 -0500
Replace preferences controller callbacks in constructor with `getState` action and `stateChange` event
commit b92cd73
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:29:42 2024 -0500
Remove unused `NetworkControllerStateChange` event
- **BREAKING**: use `NetworkControllerNetworkDidChangeEvent` instead
commit e947207
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:25:37 2024 -0500
Add `@metamask/keyring-api` as devDep (for `InternalAccount` type in tests)
commit f436032
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 20:31:40 2024 -0500
Add yarn resolutions entry to resolve conflicting `@metamask/providers` versions used by `@metamask/accounts-controller`
commit d19f5d6
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 17:04:04 2024 -0500
Define `#registerEventListeners` constructor helper private method
commit 1270aca
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 16:09:45 2024 -0500
Make `#isUnlocked` property non-optional
commit f6c2ef0
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:56:10 2024 -0500
test: adjust coverage thresholds
commit 41fee27
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:39:20 2024 -0500
test: Fix incorrect mock for `KeyringController:getState`
commit a590dcc
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 12 14:33:07 2024 -0500
test: add actions, events, callbacks to test messenger
commit 6ba98de
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:53:02 2024 -0500
Exclude `detectedTokens` already stored in tokens-controller state from `tokensToDetect`
commit 32465fd
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:46:43 2024 -0500
Use legacy token list from contract-metadata repo to perform auto-detection if active network is mainnet and token detection is disabled in preferences
commit 2673a3b
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:35:16 2024 -0500
Add `#trackMetaMetricsEvent` tracker property and call
commit 0ded3cb
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:28:33 2024 -0500
Define `#registerKeyringListeners`, `isActive` methods
commit f7718fd
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:56:20 2024 -0500
Subscribe to `AccountsController:selectedAccountChange` event
commit 78e82e7
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:54:47 2024 -0500
Define and apply `#restartTokenDetection` method
commit 2d08c2d
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:48:41 2024 -0500
[assets-controllers] Install `{accounts,keyring}-controller` as deps and peerDeps
commit 2575c72
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 24 12:04:03 2024 -0500
[assets-controllers] test: adjust coverage thresholds
commit 9c61747
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 16:42:21 2024 -0500
Add changelog entries
commit 0d50480
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 16:40:58 2024 -0500
[token-list-controller,token-rates-controller] Enumerate package-level exports
commit 669bb4f
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 16:08:39 2024 -0500
[token-balances-controller] test: Use `PreferencesController:getState` action, `TokensController:stateChange` event
commit 12971a5
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 16:00:35 2024 -0500
[token-balances-controller] Replace tokens-controller, preferences-controller callbacks with messenger actions/events.
- `getSelectedAddress` replaced with `PreferencesController:getState` action
- `onTokensStateChange` replaced with `TokensController:stateChange` event
commit d1a303a
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:57:51 2024 -0500
[token-balances-controller] Rename and export `getDefaultTokenBalancesState`
commit 1b0cf68
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:56:15 2024 -0500
[token-detection-controller] test: Mock `TokensController:getState`, `TokensController:addDetectedTokens` messenger actions
commit 83e87ad
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:54:00 2024 -0500
[token-detection-controller] Replace tokens-controller callbacks with `getState`, `addDetectedTokens` messenger actions
commit bf87104
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:52:38 2024 -0500
test: Use `PreferencesController:stateChange` event instead of `onPreferencesStateChange` callback
commit f230718
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:51:25 2024 -0500
Expose `addDetectedTokens` action
commit 5aed7e0
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 15:48:31 2024 -0500
Replace `onPreferencesStateChange` callback with messenger event
commit 5b8fb07
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 15:33:43 2024 -0500
test: Adjust tests to updates in tokens-controller
commit dccfe62
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 11:56:47 2024 -0500
Add `TokensControllerGetStateAction`, `TokensControllerActions` types
commit 48551b9
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 11:56:28 2024 -0500
Fix typing for `TokensState`
commit 4d65ee6
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Dec 19 14:42:48 2023 -0800
[token-detection-controller] test: Restore publishes for `networkDidChange` event, mock polygon network client
commit 56813f4
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Dec 19 12:36:28 2023 -0800
Remove unnecessary `?` operator
commit 1405a53
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Dec 19 12:36:04 2023 -0800
Use type assertion to mock `getNetworkClientById` return value
commit e6c9663
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Dec 19 05:28:34 2023 -0800
test: Mock `NetworkController:getNetworkClientById` action handler
commit 8039cb8
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Dec 19 05:27:52 2023 -0800
test: Mock `TokenListController:stateChange` event
commit 77a8531
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Dec 18 17:19:43 2023 -0800
[token-balances-controller] Adjust tests to updates in tokens-controller
commit 2d58e1e
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Dec 18 16:30:07 2023 -0800
Replace callbacks `onNetworkDidChange`, `onTokenListStateChange`, `getNetworkClientById` with messenger actions/events
commit 8231533
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:08:17 2024 -0500
Update packages/assets-controllers/CHANGELOG.md
Update packages/assets-controllers/CHANGELOG.md
commit 396d010
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Mon Jan 22 10:05:04 2024 -0500
[assets-controllers] Bump `@metamask/kerying-api` to ^3.0.0 and remove yarn resolutions entry for `@metamask/providers`
commit 4097960
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Sun Jan 21 20:14:09 2024 -0500
Add CHANGELOG entries
commit 524b1b9
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:39:47 2024 -0500
test: adjust for removal of `getPreferencesState` callback
commit c08cadd
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:38:58 2024 -0500
test: add callbacks for all allowed actions, events as `WithControllerCallback` arguments
commit 324aa97
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:36:59 2024 -0500
test: adjust action,event allowlist in `buildTokenDetectionControllerMessenger`
commit 412bb68
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:32:46 2024 -0500
Minor refactors to event listeners for consistency
commit f1dd425
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:31:23 2024 -0500
Replace preferences controller callbacks in constructor with `getState` action and `stateChange` event
commit 7ec7246
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:29:42 2024 -0500
Remove unused `NetworkControllerStateChange` event
- **BREAKING**: use `NetworkControllerNetworkDidChangeEvent` instead
commit f0ba761
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 19 21:25:37 2024 -0500
Add `@metamask/keyring-api` as devDep (for `InternalAccount` type in tests)
commit 9354e69
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 18 20:31:40 2024 -0500
Add yarn resolutions entry to resolve conflicting `@metamask/providers` versions used by `@metamask/accounts-controller`
commit c6ba49a
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 17:04:04 2024 -0500
Define `#registerEventListeners` constructor helper private method
commit e217169
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Wed Jan 17 16:09:45 2024 -0500
Make `#isUnlocked` property non-optional
commit 68533dd
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:56:10 2024 -0500
test: adjust coverage thresholds
commit 2acc5a1
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Tue Jan 16 19:39:20 2024 -0500
test: Fix incorrect mock for `KeyringController:getState`
commit 284c976
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Fri Jan 12 14:33:07 2024 -0500
test: add actions, events, callbacks to test messenger
commit d3448d0
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:53:02 2024 -0500
Exclude `detectedTokens` already stored in tokens-controller state from `tokensToDetect`
commit 1e9e2a3
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 18:46:43 2024 -0500
Use legacy token list from contract-metadata repo to perform auto-detection if active network is mainnet and token detection is disabled in preferences
commit 48d733a
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:35:16 2024 -0500
Add `#trackMetaMetricsEvent` tracker property and call
commit 3eb9a64
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 11:28:33 2024 -0500
Define `#registerKeyringListeners`, `isActive` methods
commit feb1ff9
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:56:20 2024 -0500
Subscribe to `AccountsController:selectedAccountChange` event
commit 3b987d1
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:54:47 2024 -0500
Define and apply `#restartTokenDetection` method
commit 26e461f
Author: Jongsun Suh <jongsun.suh@icloud.com>
Date: Thu Jan 11 10:48:41 2024 -0500
[assets-controllers] Install `{accounts,keyring}-controller` as deps and peerDeps
@MajorLift
MajorLiftforce-pushed the 231220-TokensController-v2-migration branch from 5f9f474 to 09cac7fCompareFebruary 8, 2024 21:35

@mcmiremcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

if (ignored === undefined) {
const { decimals, symbol, aggregators, iconUrl, name } =
tokenList[caseInsensitiveTokenKey];
tokenListUsed[caseInsensitiveTokenKey];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch.

@MajorLift
MajorLift merged commit 4433150 into mainFeb 9, 2024
@MajorLift
MajorLift deleted the 231220-TokensController-v2-migration branch February 9, 2024 02:36
@MajorLift
MajorLift restored the 231220-TokensController-v2-migration branch February 9, 2024 02:36
@MajorLift
MajorLift deleted the 231220-TokensController-v2-migration branch February 9, 2024 02:40
MajorLift added a commit that referenced this pull request Feb 9, 2024
…h `DetectTokensController` (#3867)
## Explanation
- This PR adds unit tests for the token-detection-controller API changes
implemented in #3775.
- The following changes are covered in the new tests:
- Don't detect if keyring-controller `isUnlocked` state is false.
- Subscribe to `KeyringController:unlock`, `KeyringController:lock`
events
- Subscribe to `AccountsController:selectedAccountChange` event
- Detect tokens using `@metamask/contract-metadata` static token list if
on mainnet and `useTokenDetection` is false.
- Call `trackMetaMetricsEvent` for every detected token.
- The aim of this PR isn't to achieve 100% test coverage for
token-detection-controller. That will be the goal of follow-up ticket
#1615
## References
- Closes#3626 - Follows from:
- #3775
- #3690
- Followed by #1615 ## Changelog
N/A
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-wallet-frameworkDeprecated: Please use `team-core-platform` instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@MajorLift@mcmire