-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Plan consolidated API for TokenDetectionController + DetectTokensController #1813
Comments
Consolidated
|
@MajorLift Is this essentially blocked by #3625? Would you need to revisit this once that's merged? |
Any changes to the Mostly I need a sign-off on the plan in the comment above before I can get started on #3626. That can wait until after #3625 is merged, though. |
It is good that you've noted some of the ways that each implementation captures data internally, but the list is fairly large for what is a small controller. I wonder if it would be better to list the public API that we want to have rather than all of the private properties and methods that are present. How we end up storing data internally or refactoring the logic, we can decide when we create the consolidated version, but I don't know if that's important for now. Here's what I see as the public API:
That said, I know I'm sort of changing the purpose of this ticket, but in addition to reviewing the public API, perhaps we should also take this time to audit the behavior between the three implementations as well, and capture a list of differences there. When creating a consolidated version of the controller I imagine we'll want to do some refactoring, so we'll want to make sure we preserve any nuances. I see you've done this a bit already: you've alluded to the fact that DetectTokensController (extension implementation) keeps track of the locked/unlocked state of the wallet, and calls the method to detect tokens when the wallet is unlocked, and refuses to detect tokens when it's locked. Besides this, it looks like there may be other slight differences in the constructor in TokenDetectionController vs. DetectTokensController. Specifically, in TokenDetectionController, when TokenListController state changes, the method to detect tokens is called only when the Also,
|
Between what you've noted and what I've noted, I imagine we probably have enough to go on, but if you find any other differences feel free to add them here. I'll let you close this ticket when you feel you have enough information to proceed to #3626. |
…ticIntervalPollingController` (#3609) ## Explanation This upgrades `TokenDetectionController` to extend `BaseControllerV2` and `StaticIntervalPollingController` as a preparation step for merging `TokenDetectionController` with `DetectTokensController`. ## References - See #1813 - See #1509 - Closes #3625 ## Changelog ### Added - `TokenListController` now exports a `TokenListControllerMessenger` type ([#3609](#3609)). - `TokenDetectionController` exports types `TokenDetectionControllerMessenger`, `TokenDetectionControllerActions`, `TokenDetectionControllerGetStateAction`, `TokenDetectionControllerEvents`, `TokenDetectionControllerStateChangeEvent` ([#3609](#3609)). - Add `enable` and `disable` methods to `TokenDetectionController`, which control whether the controller is able to make polling requests or all of its network calls are blocked. ([#3609](#3609)). - Note that if the controller is initiated without the `disabled` constructor option set to `false`, the `enable` method will need to be called before the controller can make polling requests in response to subscribed events. ### Changed - **BREAKING:** `TokenDetectionController` is upgraded to extend `BaseControllerV2` and `StaticIntervalPollingController` ([#3609](#3609)). - The constructor now expects an options object as its only argument, with required properties `messenger`, `networkClientId`, required callbacks `onPreferencesStateChange`, `getBalancesInSingleCall`, `addDetectedTokens`, `getTokenState`, `getPreferencesState`, and optional properties `disabled`, `interval`, `selectedAddress`. ## 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 <[email protected]>
Notes:
|
…` from extension (#3775) ## Explanation Merges the core `TokenDetectionController` with `DetectTokensController` from the extension and patches for this controller from mobile. - Aims to replace the extension and mobile versions of this controller and implement a unified interface that consolidates the functionality of all three iterations. - Generally assumes `DetectTokensController` to be more up-to-date, and prioritizes preserving extension and mobile behavior to minimize disruption. Significant API changes: see [Changelog](https://github.com/MetaMask/core/pull/3775/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab) for details. ## References - Closes #3626 - See #1813 ## Changelog ### [`@metamask/assets-controllers`](https://github.com/MetaMask/core/pull/3775/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab) ### Added - **BREAKING:** Adds `@metamask/accounts-controller` ^8.0.0 and `@metamask/keyring-controller` ^12.0.0 as dependencies and peer dependencies. ([#3775](#3775)). - **BREAKING:** `TokenDetectionController` newly subscribes to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events, and allows the `PreferencesController:getState` messenger action. ([#3775](#3775)) ### Changed - **BREAKING:** `TokenDetectionController` is merged with `DetectTokensController` from the `metamask-extension` repo. ([#3775](#3775)) - **BREAKING:** `TokenDetectionController` now resets its polling interval to the default value of 3 minutes when token detection is triggered by external controller events `KeyringController:unlock`, `TokenListController:stateChange`, `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`. - **BREAKING:** `TokenDetectionController` now refetches tokens on `NetworkController:networkDidChange` if the `networkClientId` is changed instead of `chainId`. - **BREAKING:** `TokenDetectionController` cannot initiate polling or token detection if `KeyringController` state is locked. - **BREAKING:** The `detectTokens` method now excludes tokens that are already included in the `TokensController`'s `detectedTokens` list from the batch of incoming tokens it sends to the `TokensController` `addDetectedTokens` method. - **BREAKING:** The constructor for `TokenDetectionController` expects a new required proprerty `trackMetaMetricsEvent`, which defines the callback that is called in the `detectTokens` method. - **BREAKING:** In Mainnet, even if the `PreferenceController`'s `useTokenDetection` option is set to false, automatic token detection is performed on the legacy token list (token data from the contract-metadata repo). ### Removed - **BREAKING:** `TokenDetectionController` constructor no longer accepts options `onPreferencesStateChange`, `getPreferencesState`. ([#3775](#3775)) - **BREAKING:** `TokenDetectionController` no longer allows the `NetworkController:stateChange` event. The `NetworkController:networkDidChange` event can be used instead. ([#3775](#3775)) ## 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 <[email protected]>
…dates (#3923) ## Explanation As a preparatory step for fully replacing the extension `DetectTokensController` with the consolidated core repo `TokenDetectionController`, `TokenDetectionController` needs to be updated with changes made to the extension `DetectTokensController` since #1813 was closed. #### Diff of `DetectTokensController` state - [MetaMask/metamask-extension@`5d285f7be5f7be981995dfa725aad97d81cc990a..85cd1c89039e900b452edb704ec37e9ccbd3e76a`#diff-323d0cf464](https://github.com/MetaMask/metamask-extension/compare/5d285f7be5f7be981995dfa725aad97d81cc990a..85cd1c89039e900b452edb704ec37e9ccbd3e76a#diff-323d0cf46498be3850b971474905354ea5ccf7fa13745ad1e6eba59c5b586830) ### Differences from extension `DetectTokensController` - Refactors logic for retrieving `chainId`, `networkClientId` into `this.#getCorrectChainIdAndNetworkClientId` - Uses `getNetworkConfigurationByNetworkClientId` action instead of `getNetworkClientById` to retrieve `chainId`. - If `networkClientId` is not supplied to the method, or it's supplied but `getNetworkConfigurationByNetworkClientId` returns `undefined`, finds `chainId` from `providerConfig`. - `detectTokens` replaces `detectNewTokens` - `detectTokens` accepts options object `{ selectedAddress, networkClientId }` instead of `{ selectedAddress, chainId, networkClientId }`. - Does not throw error if `getBalancesInSingleCall` fails. Also does not exit early -- continues looping. - Passes lists of full `Token` types to `TokensController:addDetectedTokens` instead of objects containing only `{ address, decimals, symbol }`. - `#trackMetaMetricsEvents` is a private method instead of protected. - Passes string literals instead of extension shared constants into `_trackMetaMetricsEvent`. ## References - Partially implements #3916 - Blocking #3918 - Changes adopted from: - MetaMask/metamask-extension#22898 - MetaMask/metamask-extension#22814 - #3914 - MetaMask/metamask-extension#21437 - Blocking (Followed by) #3938 ## Changelog ### [`@metamask/assets-controllers`](https://github.com/MetaMask/core/pull/3923/files#diff-ee47d03d53776b8dd530799a8047f5e32e36e35765620aeb50b294adc3339fab) ## 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: jiexi <[email protected]>
Look into how TokenDetectionController (from this repo) is being used in the mobile app (including the patches for this controller in mobile) and how DetectTokensController is being used in the extension, and determine an API for a combined controller that satisfies the requirements that extension and mobile have.
The text was updated successfully, but these errors were encountered: