fix(assets-controller): skip known assets in DetectionMiddleware to prevent redundant token/price fetches#9215
Open
salimtb wants to merge 3 commits into
Open
fix(assets-controller): skip known assets in DetectionMiddleware to prevent redundant token/price fetches#9215salimtb wants to merge 3 commits into
salimtb wants to merge 3 commits into
Conversation
…revent redundant token/price fetches Previously DetectionMiddleware populated `detectedAssets` with every asset from `assetsBalance` and every custom asset on every balance poll cycle. This caused TokenDataSource and PriceDataSource to be invoked on every RPC poll even for assets that were already fully tracked in state, resulting in unnecessary multicall and price API requests. `detectedAssets` now only includes assets that are genuinely new — absent from both `state.assetsBalance` and `state.assetsInfo`. Custom assets follow the same rule. The PriceDataSource subscription already handles periodic price refreshes for all known assets, so excluding them here is correct.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0583627. Configure here.
… and SnapDataSource Using 'full' updateMode caused assets to be wiped on custom networks whenever the API returned an empty or partial response for a chain it didn't fully support. Switching to 'merge' prevents false deletions while still overlaying fresh balance data from each poll.
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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.

Previously DetectionMiddleware populated
detectedAssetswith every asset fromassetsBalanceand every custom asset on every balance poll cycle. This caused TokenDataSource and PriceDataSource to be invoked on every RPC poll even for assets that were already fully tracked in state, resulting in unnecessary multicall and price API requests.detectedAssetsnow only includes assets that are genuinely new — absent from bothstate.assetsBalanceandstate.assetsInfo. Custom assets follow the same rule. The PriceDataSource subscription already handles periodic price refreshes for all known assets, so excluding them here is correct.Explanation
References
Checklist
Note
Medium Risk
Changes asset detection and merge-vs-full state semantics during polling; wrong filtering could skip needed metadata fetches, while incorrect merge behavior could leave stale balances visible on partial network coverage.
Overview
Cuts redundant token metadata and price work on every balance poll by narrowing what
DetectionMiddlewareputs indetectedAssets: balance and custom assets are included only when they are missing from bothstate.assetsBalanceandstate.assetsInfo, on the assumption that PriceDataSource already refreshes known assets.AccountsApiDataSource and SnapDataSource now return
updateMode: 'merge'instead of'full', so partial poll responses no longer treat the payload as authoritative and wipe balances for custom or partially supported networks.Reviewed by Cursor Bugbot for commit 6da9f2b. Bugbot is set up for automated code reviews on this repo. Configure here.