Skip to content

chore: stop using tokensChainsCache in confirmations#27611

Merged
juanmigdr merged 13 commits into
mainfrom
chore/stop-using-tokensChainsCache-confirmations
Mar 23, 2026
Merged

chore: stop using tokensChainsCache in confirmations#27611
juanmigdr merged 13 commits into
mainfrom
chore/stop-using-tokensChainsCache-confirmations

Conversation

@juanmigdr
Copy link
Copy Markdown
Member

@juanmigdr juanmigdr commented Mar 18, 2026

Description

This work is part of removing the tokensChainsCache entirely

The useERC20Tokens hook was the sole internal consumer of selectTokenListArray and was only called in useDisplayName. I have updated the hook to resolve this metadata using the /assets/v3 endpoint (which caches data and is very performant)

Changelog

CHANGELOG entry: modified useERC20Tokens to make an API call instead of reading from the cache

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-2954

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Screen.Recording.2026-03-20.at.13.48.52.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Introduces a new client-side token-metadata fetch/caching layer and shifts useERC20Tokens from Redux cache reads to network-backed data, which could affect confirmations display names/images and add runtime dependency on the tokens API.

Overview
Updates useERC20Tokens to stop reading ERC-20 metadata from tokensChainsCache and instead resolve names/symbols/icons via a new useTokensData hook backed by the tokens API v3/assets endpoint (using CAIP-19 asset IDs).

Adds buildEvmCaip19AssetId for consistent lowercased asset ID construction, plus a batched/deduped module-level cache in useTokensData (25 IDs per request, shared in-flight promises). Tests are rewritten/added accordingly, CODEOWNERS is updated for the new hook, and E2E token API mocks now include the new v3 endpoint.

Written by Cursor Bugbot for commit 4d2eace. This will update automatically on new commits. Configure here.

@github-actions github-actions Bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
Comment thread app/components/hooks/DisplayName/useERC20Tokens.ts Outdated
Comment thread app/components/hooks/DisplayName/useERC20Tokens.ts Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.31%. Comparing base (bb5bfa8) to head (9712024).
⚠️ Report is 53 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27611      +/-   ##
==========================================
+ Coverage   82.19%   82.31%   +0.11%     
==========================================
  Files        4788     4782       -6     
  Lines      123512   123416      -96     
  Branches    27364    27449      +85     
==========================================
+ Hits       101516   101585      +69     
+ Misses      14962    14793     -169     
- Partials     7034     7038       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 19, 2026
@juanmigdr juanmigdr requested a review from a team as a code owner March 19, 2026 09:02
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 19, 2026
Comment thread app/components/hooks/DisplayName/useERC20Tokens.test.ts
@juanmigdr juanmigdr requested a review from a team March 19, 2026 09:36
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 19, 2026
Comment thread app/components/hooks/DisplayName/useERC20Tokens.ts Outdated
@juanmigdr juanmigdr requested a review from matthewwalsh0 March 20, 2026 11:49
Comment thread app/components/hooks/DisplayName/useERC20Tokens.ts Outdated
@juanmigdr juanmigdr requested a review from a team as a code owner March 20, 2026 12:42
@github-actions github-actions Bot added size-L risk-medium Moderate testing recommended · Possible bug introduction risk and removed size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
matthewwalsh0
matthewwalsh0 previously approved these changes Mar 20, 2026
Comment thread app/components/hooks/DisplayName/useERC20Tokens.ts Outdated
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 23, 2026
@juanmigdr juanmigdr enabled auto-merge March 23, 2026 10:58
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 23, 2026
Copy link
Copy Markdown
Contributor

@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.

Comment thread app/components/hooks/useTokensData/useTokensData.ts
Copy link
Copy Markdown
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

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

If tokensChainsCache entry is no longer needed, shouldn't we clean it from our users devices with a migration?

@juanmigdr
Copy link
Copy Markdown
Member Author

If tokensChainsCache entry is no longer needed, shouldn't we clean it from our users devices with a migration?

Yes but its use is bing gradually removed, it has not yet been fully removed, this is a PR that will allow this to be fully removed

@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeConfirmations, FlaskBuildTests
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 80%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes refactor useERC20Tokens to use a new useTokensData hook that fetches token metadata from the MetaMask tokens API v3 (instead of reading from Redux state via selectERC20TokensByChain). This is a behavioral change in how ERC-20 token names/symbols/icons are resolved for display.

Impact chain:

  • useERC20TokensuseDisplayName → used in confirmation UI components (from-to-row, address display, account-row, advanced-details-row, nested-transaction-data, SimulationDetails/useSimulationMetrics)
  • useDisplayName → also used in Snaps UI (SnapUIAddress, SnapUIAddressInput)

SmokeConfirmations is selected because:

  • The from-to-row component in confirmations uses useDisplayName which calls useERC20Tokens
  • Token approval confirmations (ERC-20 approve, ERC-721/ERC-1155) display contract names resolved via this hook
  • SimulationDetails uses useSimulationMetrics which also uses useDisplayName
  • The token API mock change in tests/api-mocking/mock-responses/defaults/token-apis.ts adds a new v3 endpoint mock that affects all tests using default mocks - this needs validation

FlaskBuildTests is selected because:

  • SnapUIAddress and SnapUIAddressInput use useDisplayName which calls useERC20Tokens
  • Snap UI address display could be affected by the token resolution change

Not selected:

  • SmokeAccounts, SmokeIdentity, SmokeWalletPlatform: The changes don't affect account management, identity sync, or wallet platform features directly
  • SmokeTrade: While swaps involve confirmations, the core change is in token name display which is primarily a confirmation UI concern
  • SmokeNetworkAbstractions/SmokeNetworkExpansion/SmokeMultiChainAPI: No direct impact on network management or multi-chain provider
  • SmokeRamps, SmokeCard, SmokePerps, SmokePredictions: No direct impact on these features

The API mock change is a global default mock change, but since it returns an empty array (same as before for the existing endpoints), it shouldn't break other test suites - it just prevents real network calls to the new v3 endpoint.

Performance Test Selection:
The changes are primarily about refactoring token metadata fetching from Redux state to an API call. While this introduces async data fetching, the new hook includes caching and deduplication to minimize performance impact. The changes don't affect core rendering performance, account/network list components, app startup, or other performance-sensitive areas. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@christopherferreira9 christopherferreira9 left a comment

Choose a reason for hiding this comment

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

Looks good for QA

@juanmigdr juanmigdr added this pull request to the merge queue Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

Merged via the queue into main with commit 436bbbc Mar 23, 2026
179 of 181 checks passed
@juanmigdr juanmigdr deleted the chore/stop-using-tokensChainsCache-confirmations branch March 23, 2026 15:54
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-L team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants