fix: remove usage current network from tokens controller#5659
Merged
Conversation
f457cdf to
530f9e5
Compare
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Prithpal-Sooriya
previously approved these changes
Apr 25, 2025
cryptodev-2s
requested changes
Apr 25, 2025
f8813f3 to
83a6970
Compare
Prithpal-Sooriya
approved these changes
Apr 25, 2025
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
This was referenced Apr 28, 2025
7 tasks
github-merge-queue Bot
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
May 1, 2025
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This update upgrades the asset controllers to version 60, which introduces important changes to the `TokensController`: - Refactored `TokensController` to eliminate reliance on a single selected network ([#5659](MetaMask/core#5659)). - `TokensController` methods now require `networkClientId` to be explicitly passed as a parameter. - Token management logic is now fully parameterized by `chainId`, enabling multi-chain token handling and improving reliability across network changes. - Internal state updates and token metadata fetching are now scoped to the appropriate `chainId`. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [](https://codespaces.new/MetaMask/metamask-extension/pull/32321?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to MM 2. Test add tokens , hide tokens, and other flows ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: sahar-fehri <sahar.fehri@consensys.net>
github-merge-queue Bot
pushed a commit
to MetaMask/metamask-mobile
that referenced
this pull request
May 6, 2025
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** # Upgrade Asset Controllers to v60 This update upgrades the asset controllers to version 59, which introduces important changes to the `TokensController`: - Refactored `TokensController` to eliminate reliance on a single selected network ([#5659](MetaMask/core#5659)). - `TokensController` methods now require `networkClientId` to be explicitly passed as a parameter. - Token management logic is now fully parameterized by `chainId`, enabling multi-chain token handling and improving reliability across network changes. - Internal state updates and token metadata fetching are now scoped to the appropriate `chainId`. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to MM wallet 2. Test the assets part ( import token, hide tokens, add tokens ...etc ) ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: sahar-fehri <sahar.fehri@consensys.net>
theceo1
pushed a commit
to theceo1/metamask-mobile
that referenced
this pull request
Jun 24, 2025
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** # Upgrade Asset Controllers to v60 This update upgrades the asset controllers to version 59, which introduces important changes to the `TokensController`: - Refactored `TokensController` to eliminate reliance on a single selected network ([MetaMask#5659](MetaMask/core#5659)). - `TokensController` methods now require `networkClientId` to be explicitly passed as a parameter. - Token management logic is now fully parameterized by `chainId`, enabling multi-chain token handling and improving reliability across network changes. - Internal state updates and token metadata fetching are now scoped to the appropriate `chainId`. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to MM wallet 2. Test the assets part ( import token, hide tokens, add tokens ...etc ) ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: sahar-fehri <sahar.fehri@consensys.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
The current implementation of
TokensControllerrelies heavily on a single selected network (chainId) as an instance property, which makes multi-chain token handling brittle and hard to scale. Additionally, some token operations unintentionally assume a persistent network context, introducing potential bugs when switching networks or performing actions concurrently across different chains.This PR refactors the
TokensControllerto eliminate reliance on an internal#chainIdproperty. Instead, all methods that require a network context now accept anetworkClientIdas an explicit parameter. This improves the controller’s ability to operate safely and predictably in a multi-chain environment.The
#onNetworkDidChangelogic and associated subscription were removed since network changes are now handled at the method level with explicitnetworkClientIdparameters. All relevant internal state mutations and token metadata fetches are scoped to the appropriate chain via thenetworkClientId -> chainIdmapping.This refactor is part of a broader initiative to support simultaneous multi-chain state handling across the codebase (see recent changes to
TokenRatesControllerandAccountTrackerController).integration with UI:
extension: MetaMask/metamask-extension#32274
mobile: MetaMask/metamask-mobile#14913
References
Changelog
@metamask/assets-controllersTokensControllerto support handling multiple chains in parallel. All network-dependent methods now require an explicitnetworkClientIdparameter, enabling token operations to be fully scoped to a specific chain. This improves reliability and predictability when managing tokens across different networks.chainIdinstance property inTokensController. All chain-specific logic has been externalized. Consumers must now explicitly pass anetworkClientIdto methods that interact with the token state. This change may require updates on the client side to ensure correct chain context is provided during token actions.Checklist