Skip to content

chore: remove tokens chains cache usages#8519

Open
juanmigdr wants to merge 2 commits intomainfrom
chore/remove-tokensChainsCache-usages
Open

chore: remove tokens chains cache usages#8519
juanmigdr wants to merge 2 commits intomainfrom
chore/remove-tokensChainsCache-usages

Conversation

@juanmigdr
Copy link
Copy Markdown
Member

@juanmigdr juanmigdr commented Apr 20, 2026

Explanation

References

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes token detection/enrichment data sources and caching behavior, which can affect which tokens are auto-added and when metadata appears; also introduces new external API calls and filtering logic that could impact detection rates if the v3 endpoint/threshold behaves unexpectedly.

Overview
Token detection via WS/polling now fetches ERC-20 metadata directly from the v3 Tokens API (tokens-api-v3.ts) instead of relying on TokenListController’s tokensChainsCache, and filters out unverified tokens using an occurrences threshold (spam prevention).

TokenListController stops persisting/loading tokensChainsCache for Accounts API v4-supported chains (including purging any stale persisted entries), publishes a new TokenListController:tokenListFetched event with the processed token list, and always treats the cache as invalid for those chains. TokensController switches from enriching token state on TokenListController:stateChange to enriching only when tokenListFetched fires, via a dedicated #enrichTokensFromTokenList helper.

Reviewed by Cursor Bugbot for commit 41acf1e. Bugbot is set up for automated code reviews on this repo. Configure here.

@juanmigdr juanmigdr requested a review from a team as a code owner April 20, 2026 09:32
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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 41acf1e. Configure here.

// Check map of validated tokens (cache keys are lowercase)
const tokenData =
this.#tokensChainsCache[chainId]?.data?.[lowercaseTokenAddress];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raw v3 API data missing icon proxy and aggregator formatting

Medium Severity

The old code read token data from tokensChainsCache, where iconUrl had been replaced by formatIconUrlWithProxy (producing a proxy URL like https://static.cx.metamask.io/api/v1/tokenIcons/{chainId}/{address}.png) and aggregators had been run through formatAggregatorNames. The new fetchVerifiedTokensByAddresses call returns raw v3 API data with neither transformation applied. This means the image field on detected tokens will contain whatever raw URL the v3 API returns instead of the expected proxy URL, and aggregators will contain raw API keys instead of formatted display names.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 41acf1e. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant