Skip to content

fix: integrate tokens controllers#32274

Closed
salimtb wants to merge 3 commits into
mainfrom
fix/integrate-tokens-controller
Closed

fix: integrate tokens controllers#32274
salimtb wants to merge 3 commits into
mainfrom
fix/integrate-tokens-controller

Conversation

@salimtb

@salimtb salimtb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

Description

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@socket-security

socket-security Bot commented Apr 25, 2025

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​providers@​22.0.1991009298100

View full report

salimtb added a commit to MetaMask/core that referenced this pull request Apr 25, 2025
## Explanation

The current implementation of `TokensController` relies 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 `TokensController` to eliminate reliance on an
internal `#chainId` property. Instead, all methods that require a
network context now accept a `networkClientId` as an explicit parameter.
This improves the controller’s ability to operate safely and predictably
in a multi-chain environment.

The `#onNetworkDidChange` logic and associated subscription were removed
since network changes are now handled at the method level with explicit
`networkClientId` parameters. All relevant internal state mutations and
token metadata fetches are scoped to the appropriate chain via the
`networkClientId -> chainId` mapping.

This refactor is part of a broader initiative to support simultaneous
multi-chain state handling across the codebase (see recent changes to
`TokenRatesController` and `AccountTrackerController`).

integration with UI:
extension: MetaMask/metamask-extension#32274


<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References
* Fixes #5580 
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:


* Related to #67890
-->

## Changelog

### `@metamask/assets-controllers`

- **UPDATE:** Refactor `TokensController` to support handling multiple
chains in parallel. All network-dependent methods now require an
explicit `networkClientId` parameter, enabling token operations to be
fully scoped to a specific chain. This improves reliability and
predictability when managing tokens across different networks.
- **BREAKING:** Remove internal reliance on a single `chainId` instance
property in `TokensController`. All chain-specific logic has been
externalized. Consumers must now explicitly pass a `networkClientId` to
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.


<!--
THIS SECTION IS NO LONGER NEEDED.

The process for updating changelogs has changed. Please consult the
"Updating changelogs" section of the Contributing doc for more.
-->

## 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 communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@salimtb salimtb closed this Jun 11, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants