feat(assets-controller): clean and optimize data fetching#7950
Merged
Conversation
94338fd to
789b774
Compare
salimtb
approved these changes
Feb 23, 2026
juanmigdr
approved these changes
Feb 23, 2026
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
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?
Parallel middlewares (
@metamask/assets-controller)createParallelBalanceMiddleware: Runs balance data sources (Accounts API, Snap, RPC) in parallel with chain partitioning and limited concurrency (p-limit, concurrency 3). Failed chains get a fallback round. Responses are merged viamergeDataResponses.createParallelMiddleware: Runs TokenDataSource and PriceDataSource in parallel for the same request and merges their responses.Both use the new
DataResponse.updateModeso merged results preserve'full'when any source uses it.Full vs merge update modes
DataResponsegets an optionalupdateMode:'full'|'merge'(typeAssetsUpdateMode).updateModeis omitted is'merge'.ClientController integration
@metamask/assets-controlleradds a dependency on@metamask/client-controllerand subscribes toClientController:stateChange.Method-action-types script
scripts/generate-method-action-types.tsno longer takes a per-package path. It discovers all controllers withMESSENGER_EXPOSED_METHODSunderpackages/. Thegenerate-method-action-typesscript andtsxdevDependency are removed from individual packages (e.g. assets-controller, client-controller, analytics-controller, etc.) so generation is centralized.Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?
mergeDataResponses: Merges multipleDataResponseobjects (e.g. from parallel balance sources). If any response hasupdateMode: 'full', the merged result is'full'; otherwise it defaults to'merge'.ClientController:getStateandClientController:stateChangeon the assets-controller messenger; otherwise asset tracking will not run when the UI is open.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?
scripts/generate-method-action-types.tsaffects the whole monorepo, so all packages that previously had a localgenerate-method-action-typesscript and used it with a path were updated to drop that script and thetsxdevDependency.assets-controllersCHANGELOG was updated to reflect dependency/version bumps (e.g.network-enablement-controller) that are part of this work.If you had to upgrade a dependency, why did you do so?
@metamask/client-controller: New dependency for assets-controller to gate asset tracking on UI visibility.p-limit: Added to assets-controller to cap concurrency in the parallel balance middleware.tsxfrom several packages: script execution is centralized; the root or a single package can run the generator.Integration PR in extension: MetaMask/metamask-extension#40233
References
Checklist
Note
Medium Risk
Touches core balance/price aggregation and start/stop lifecycle behavior; concurrency and new
updateModesemantics could cause missing/overwritten state if edge cases aren’t covered.Overview
Optimizes assets data fetching and state application. The
AssetsControllernow runs balance sources in parallel with chain partitioning and a fallback retry, and runs token metadata + price enrichment in parallel via newParallelMiddlewareutilities (with concurrency limits viap-limit).Adds
DataResponse.updateMode('full' | 'merge') and updates state writes to respect it (initial/force fetch is treated as full while most subscription updates are merge, preserving custom assets during full refreshes). Asset tracking is now gated by both UI-open and keyring-unlocked state via@metamask/client-controller, and tests/data sources were updated accordingly (including early returns when no accounts/chains).Written by Cursor Bugbot for commit 7e0e148. This will update automatically on new commits. Configure here.