Skip to content

chore: remove tokensChainsCache usage from usePerpsPaymentTokens#28639

Merged
juanmigdr merged 5 commits intomainfrom
chore/remove-tokensChainsCache-from-usePerpsPaymentTokens
Apr 10, 2026
Merged

chore: remove tokensChainsCache usage from usePerpsPaymentTokens#28639
juanmigdr merged 5 commits intomainfrom
chore/remove-tokensChainsCache-from-usePerpsPaymentTokens

Conversation

@juanmigdr
Copy link
Copy Markdown
Member

@juanmigdr juanmigdr commented Apr 10, 2026

Description

Removes the dependency on selectTokenList (backed by tokensChainsCache) and selectIsIpfsGatewayEnabled from the usePerpsPaymentTokens hook, as part of the broader effort to eliminate tokensChainsCache usage across the codebase.

The tokenList selector was used in two places inside the hook, both of which were effectively dead code:

  1. Hyperliquid USDC entryenhanceTokenWithIcon was called with the current EVM chain's token list to look up the USDC icon. This lookup would virtually never succeed because Hyperliquid tokens don't appear in EVM chain token lists. The symbol-based cross-chain fallback might occasionally match, but USDC_TOKEN_ICON_URL (already exported from @metamask/perps-controller and used elsewhere in the codebase for this exact purpose) is the correct, always-available icon. Replaced with the hardcoded constant.
  2. Other wallet tokensenhanceTokenWithIcon was guarded by tokenList && !token.image. However, useTokensWithBalance already populates token.image via getTokenIconUrl (constructing the MetaMask static CDN URL from the CAIP-19 asset ID) for every token it returns. The !token.image condition was therefore almost never true, making the entire enhancement block a no-op. Removed; tokens now pass through as-is from useTokensWithBalance.

Changelog

CHANGELOG entry: remove tokensChainsCache usage from usePerpsPaymentTokens

Related issues

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

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

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
Moderate risk because it changes how token icons are sourced in the Perps payment token list (now relying on USDC_TOKEN_ICON_URL and useTokensWithBalance images) and removes token-list/IPFS fallbacks, which could affect UI rendering if assumptions are wrong.

Overview
Removes tokensChainsCache-backed dependencies from usePerpsPaymentTokens by dropping selectTokenList/selectIsIpfsGatewayEnabled and the enhanceTokenWithIcon flow.

Hyperliquid USDC now always uses USDC_TOKEN_ICON_URL for its image, and non-Hyperliquid tokens are passed through from useTokensWithBalance with only balance/balanceFiat fallbacks. Associated tests are updated, and tokenIconUtils (and its unit tests) are deleted.

Reviewed by Cursor Bugbot for commit f73a8f0. 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 10, 2026 07:52
@juanmigdr juanmigdr enabled auto-merge April 10, 2026 07:52
@github-actions github-actions bot added size-M risk-low Low testing needed · Low bug introduction risk labels Apr 10, 2026
…ns' of github.com:MetaMask/metamask-mobile into chore/remove-tokensChainsCache-from-usePerpsPaymentTokens
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 10, 2026
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 f58dff2. Configure here.

enhanceTokenWithIcon and its supporting types/imports are no longer used
by any production code after removing the last caller in usePerpsPaymentTokens.

Made-with: Cursor
@github-actions github-actions bot added size-L risk-low Low testing needed · Low bug introduction risk and removed size-M risk-low Low testing needed · Low bug introduction risk labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 95%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are entirely within the Perps feature's payment token handling:

  1. tokenIconUtils.ts deleted: The enhanceTokenWithIcon utility was removed. Grep confirms it had zero other consumers in the codebase, so no cascade effects.

  2. usePerpsPaymentTokens.ts simplified: Removed dynamic icon resolution via token list lookup (which required selectTokenList and selectIsIpfsGatewayEnabled selectors). The Hyperliquid USDC token now uses a static USDC_TOKEN_ICON_URL constant from @metamask/perps-controller. Other tokens pass through their image from useTokensWithBalance unchanged.

  3. Test files updated: Both test files updated/deleted to match the simplified implementation.

Tag selection rationale:

  • SmokePerps: Primary tag — changes directly affect the Perps payment token hook used in the Add Funds flow
  • SmokeWalletPlatform: Required by SmokePerps description (Perps is a section inside Trending tab)
  • SmokeConfirmations: Required by SmokePerps description (Add Funds deposits are on-chain transactions)

The risk is low because: (1) the change is a simplification (static URL vs dynamic lookup), (2) USDC is the primary token used in Perps and its icon URL is now hardcoded from the controller package, (3) no shared infrastructure or cross-feature components are affected.

Performance Test Selection:
The changes remove a dynamic token icon resolution utility and replace it with a static URL constant. This is a simplification that reduces computation (no more token list iteration for icon lookup). No UI rendering components, list components, account selectors, or performance-critical paths were modified. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

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

@juanmigdr juanmigdr added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 2ff2004 Apr 10, 2026
103 checks passed
@juanmigdr juanmigdr deleted the chore/remove-tokensChainsCache-from-usePerpsPaymentTokens branch April 10, 2026 15:57
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-low Low testing needed · Low bug introduction risk size-L team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants