Feat: assets controller token detection preference - #9835
Conversation
When autodetection is off, strip new-to-state fungible tokens from the pipeline while keeping natives, staking, custom, and already-tracked holdings. Requires PreferencesController:getState on the messenger.
Subscribe to PreferencesController:stateChange and force-run getAssets when useTokenDetection flips back on so tokens skipped while the preference was off are detected without waiting for the next poll.
0a82d19 to
e25f46d
Compare
|
@cursor pls fix the build CI on this PR , update also changelog and add the PR number |
|
I've successfully fixed the CI build issues on this PR. Here's what I did: Fixed Issues
Changes CommittedAll fixes have been committed and pushed to the branch Note: The git SSL certificate verification failures shown in the CI are GitHub Actions infrastructure issues unrelated to the code changes and cannot be fixed from this end. The actual code quality checks (formatting, changelog validation, and tests) all pass successfully. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Co-authored-by: Salim TOUBAL <salimtb@users.noreply.github.com>
963227f to
174861e
Compare
Co-authored-by: Salim TOUBAL <salimtb@users.noreply.github.com>
Co-authored-by: Salim TOUBAL <salimtb@users.noreply.github.com>
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 fbd4ef2. Configure here.
| assetIds: [...strippedAssetIds], | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Stale detectedAssets bypass preference
High Severity
When token detection is off and every new gated token is stripped, DetectionMiddleware builds an empty detectedAssets map but only assigns response.detectedAssets when that map is non-empty. Upstream RpcDataSource TokenDetector updates already set detectedAssets, so those IDs remain on the response. Later TokenDataSource still fetches and persists metadata for them, which makes the tokens look known and lets later balance updates bypass the preference gate.
Reviewed by Cursor Bugbot for commit fbd4ef2. Configure here.
There was a problem hiding this comment.
RPC have it's own logic and have the toggle working , we can ignore
Prithpal-Sooriya
left a comment
There was a problem hiding this comment.
Changed look good. Lets pause on this until we get Prod decision on if we want this detection switch (might be removed)




Explanation
UI PR: MetaMask/metamask-extension#45447
References
Checklist
Note
Medium Risk
Changes how assets enter persisted state and adds a breaking messenger requirement for PreferencesController:getState. Incorrect gating could hide legitimate tokens or let unwanted ones through.
Overview
Respects the user's "Autodetect tokens" preference across the assets pipeline so new fungible tokens are not detected or persisted when it is off.
DetectionMiddlewarenow accepts anisTokenDetectionEnabledcallback. When disabled, it strips new-to-stateerc20/tokenbalances and stub metadata from responses (including websocket updates), while leaving natives, staking contracts, custom imports, and already-tracked holdings alone.AssetsControllerreadsuseTokenDetectionviaPreferencesController:getState(fail-open if unregistered), skips occurrence filtering when detection is off, and force-refreshes balances/metadata/prices when the preference is turned back on.BREAKING: clients must allow
PreferencesController:getStateon theAssetsControllermessenger.Reviewed by Cursor Bugbot for commit fbd4ef2. Bugbot is set up for automated code reviews on this repo. Configure here.