Skip to content

chore: remove tokens chains cache usages#8519

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

chore: remove tokens chains cache usages#8519
juanmigdr wants to merge 16 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
Refactors token detection and token metadata enrichment to use new API-backed caches and a new v3 verification endpoint; mistakes could impact token auto-detection results, caching staleness, or add/ignore behavior across networks.

Overview
Removes reliance on TokenListController’s tokensChainsCache for both token detection and token metadata updates, switching to direct token-list fetching via a new fetchAndBuildTokenListMap helper with an internal 4-hour cache and abort support.

Token detection now fetches token lists on-demand (with mainnet preference-aware cache invalidation) and updates websocket/polling-based token additions to pull metadata from a new tokens-api-v3 verifier, filtering out likely-spam tokens by occurrences < 3 and returning early when token detection or external services are disabled.

TokensController metadata updates are reworked: instead of reacting to TokenListController:stateChange, it periodically enriches stored tokens’ missing name/rwaData from the fetched token list, adds API-backed fallbacks in addToken/addTokens, and ensures destroy() clears intervals and aborts in-flight fetches. Tests and ESLint suppression counts are updated accordingly.

Reviewed by Cursor Bugbot for commit d04fb37. 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
Comment thread packages/assets-controllers/src/TokenDetectionController.ts
Comment thread packages/assets-controllers/src/TokensController.ts
Comment thread packages/assets-controllers/src/TokensController.ts
Comment thread packages/assets-controllers/src/TokenDetectionController.ts
Comment thread packages/assets-controllers/src/TokenDetectionController.ts
Comment thread packages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment thread packages/assets-controllers/src/TokenDetectionController.ts Outdated
allTokens: updatedAllTokens,
}));
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Async enrichment overwrites concurrent state mutations

Medium Severity

#enrichTokenMetadata clones allTokens at the start, then awaits network requests via #getTokenListForChain, and finally overwrites allTokens with the stale clone. Any tokens added or ignored by concurrent calls to addToken, addTokens, or addDetectedTokens during those awaits are silently lost. The old synchronous TokenListController:stateChange subscriber didn't have this problem because there was no await between reading and writing state. The risk is amplified because addToken and addTokens fire #enrichTokenMetadata as a non-awaited side effect immediately after mutating state.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5ebba43. Configure here.

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.

There are 2 total unresolved issues (including 1 from previous review).

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 2c0fce8. Configure here.

TokenListStateChange,
TokensChainsCache,
} from './TokenListController';
import type { TokenListMap, TokensChainsCache } from './TokenListController';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused mapChainIdWithTokenListMap function and lodash imports remain

Low Severity

mapChainIdWithTokenListMap was only used by the now-removed #compareTokensChainsCache method. It's no longer called in production code (not exported from index.ts), making it dead code. The TokensChainsCache type import and the lodash imports mapValues, isObject, and get are also only needed by this dead function.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2c0fce8. Configure here.

@juanmigdr juanmigdr force-pushed the chore/remove-tokensChainsCache-usages branch from 82519d6 to a96ca4e Compare April 24, 2026 11:26
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