-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[token-detection-controller] Consolidate with DetectTokensController
from extension
#3775
[token-detection-controller] Consolidate with DetectTokensController
from extension
#3775
Conversation
2444b95
to
db6974c
Compare
e8b624c
to
209effd
Compare
209effd
to
e9e4a4e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
db13e83
to
f8df3d5
Compare
@SocketSecurity ignore npm/@metamask/object-multiplex@1.3.0 (Internal tooling) |
TokenDetectionController
and extension DetectTokensController
DetectTokensController
from extension
197e379
to
8231533
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job sorting all of these differences out. I did a first pass and made some notes. I noticed that some tests are missing for the added behavior. I know we have another ticket to ensure that there are comprehensive tests for this controller, but do we want to add tests for the changes added here? Then that other tickets would cover behavior that is out of scope of this consolidation work.
0ae2ffd
to
fbc1a83
Compare
Hmm CI changelog:validate is not running on the current state of the changelog file: |
@MajorLift That's strange. |
@MajorLift Is this commit present in this branch? f4d4047 |
1957a33
to
ca19f99
Compare
It looks like changelog:validate was correctly alerting us that my changelog wasn't conforming to prettier rules. Adding newlines after the unreleased category headings fixed the issue. The current way changelog:validate shows diffs is a bit confusing. Would it make sense to reverse the diff source and target so that suggested additions show up as positive diffs and removals as negative diffs? |
Absolutely, yes. This is an issue that we've been meaning to fix for a while. |
…s` versions used by `@metamask/accounts-controller`
- **BREAKING**: use `NetworkControllerNetworkDidChangeEvent` instead
…e` action and `stateChange` event
…rCallback` arguments
…e yarn resolutions entry for `@metamask/providers`
Update packages/assets-controllers/CHANGELOG.md
…` is changed instead of `chainId`, and avoid resetting polling interval
754b46f
to
88eb7ca
Compare
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
…DetectTokensController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 🎉
…roller-messenger pattern (#3690) ## 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 - Extracted from #3775 - Contributes to #3626 ## Changelog ### [`@metamask/assets-controllers`](https://github.com/MetaMask/core/pull/3690/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab) ### Added - `TokensController` now exports `TokensControllerActions`, `TokensControllerGetStateAction`, `TokensControllerAddDetectedTokensAction`, `TokensControllerEvents`, `TokensControllerStateChangeEvent`. ([#3690](#3690)) ### Changed - **BREAKING:** The `TokensState` type is now defined as a type alias rather than an interface. ([#3690](#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](#3690), [#3775](#3775)) - **BREAKING:** `TokensController` constructor no longer accepts options `onPreferencesStateChange`, `onNetworkDidChange`, `onTokenListStateChange`, `getNetworkClientById`. ([#3690](#3690)) - **BREAKING:** `TokenBalancesController` constructor no longer accepts options `onTokensStateChange`, `getSelectedAddress`. ([#3690](#3690)) ## 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 --------- Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
…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
Explanation
Merges the core
TokenDetectionController
withDetectTokensController
from the extension and patches for this controller from mobile.DetectTokensController
to be more up-to-date, and prioritizes preserving extension and mobile behavior to minimize disruption.Significant API changes: see Changelog for details.
References
DetectTokensController
into coreTokenDetectionController
#3626Changelog
@metamask/assets-controllers
Added
@metamask/accounts-controller
^8.0.0 and@metamask/keyring-controller
^12.0.0 as dependencies and peer dependencies. (#3775).TokenDetectionController
newly subscribes to thePreferencesController:stateChange
,AccountsController:selectedAccountChange
,KeyringController:lock
,KeyringController:unlock
events, and allows thePreferencesController:getState
messenger action. (#3775)Changed
TokenDetectionController
is merged withDetectTokensController
from themetamask-extension
repo. (#3775)TokenDetectionController
now resets its polling interval to the default value of 3 minutes when token detection is triggered by external controller eventsKeyringController:unlock
,TokenListController:stateChange
,PreferencesController:stateChange
,AccountsController:selectedAccountChange
.TokenDetectionController
now refetches tokens onNetworkController:networkDidChange
if thenetworkClientId
is changed instead ofchainId
.TokenDetectionController
cannot initiate polling or token detection ifKeyringController
state is locked.detectTokens
method now excludes tokens that are already included in theTokensController
'sdetectedTokens
list from the batch of incoming tokens it sends to theTokensController
addDetectedTokens
method.TokenDetectionController
expects a new required proprertytrackMetaMetricsEvent
, which defines the callback that is called in thedetectTokens
method.PreferenceController
'suseTokenDetection
option is set to false, automatic token detection is performed on the legacy token list (token data from the contract-metadata repo).Removed
TokenDetectionController
constructor no longer accepts optionsonPreferencesStateChange
,getPreferencesState
. (#3775)TokenDetectionController
no longer allows theNetworkController:stateChange
event. TheNetworkController:networkDidChange
event can be used instead. (#3775)Checklist