Skip to content

fix(card): show Card tokens for the current account on account switch#30414

Merged
Brunonascdev merged 6 commits into
mainfrom
fix/card-spending-limit-tokens-on-account-switch
May 20, 2026
Merged

fix(card): show Card tokens for the current account on account switch#30414
Brunonascdev merged 6 commits into
mainfrom
fix/card-spending-limit-tokens-on-account-switch

Conversation

@Brunonascdev

@Brunonascdev Brunonascdev commented May 20, 2026

Copy link
Copy Markdown
Contributor

Description

After switching the selected EVM account, the Spending Limit screen's Token selector rendered the "No tokens available" empty state, even when the new account had supported tokens that could be enabled. The root cause was introduced in #30028: BaanxProvider.buildSupportedTokens synthesized the "Not enabled" placeholder rows once at fetch time and stamped them with the account that was selected during the fetch. cardHomeData is not refetched on a plain account switch, so the stale walletAddress on those placeholders no longer matched the new selected account and the downstream filter in selectCardAvailableTokens removed them all.

Rather than triggering a network refetch on every account change (the getCardHomeData call is heavy), this PR moves the placeholder synthesis into the selector layer so the list is recomputed reactively from data that is already in the store.

  • BaanxProvider.buildSupportedTokens no longer creates inactive placeholders or takes a currentWalletAddress. Its sole responsibility is now to enrich the real fundingAssets with the matching delegationContract from delegationSettings.
  • selectCardAvailableTokens now combines cardHomeData, the selected EVM account, and selectCardFeatureFlag. It returns the filtered real entries plus Inactive placeholders synthesized from delegationSettings via buildDelegationTokenList, each stamped with the currently selected wallet address. Memoization keeps recomputation cheap.
  • selectCardLineaUsdcToken is rebased on selectCardAvailableTokens so the Cashback screen also benefits from the synthesized USDC-on-Linea placeholder.

No data-fetching or controller subscription is added; the selector recomputes from already-cached state.

Changelog

CHANGELOG entry: Fixed a bug where the Card spending-limit token selector incorrectly showed "No tokens available" after switching accounts.

Related issues

Refs: #30028

Manual testing steps

Feature: Card spending-limit token selector reflects the selected account

  Scenario: Token list reflects the new account after switching
    Given the Card feature is enabled
      And I have at least two EVM accounts (Account A and Account B)
      And Account A has at least one Card-supported token enabled (e.g. USDC on Linea)
      And Account B has no Card token enabled yet
      And the Card spending-limit screen is open with Account A selected
      And the Token selector shows the supported tokens

    When I switch the selected account to Account B
      And I open the Token selector

    Then the Token selector lists the Card-supported tokens (e.g. USDC on Linea) as "Not enabled" for Account B
      And it does NOT show the "No tokens available" empty state
      And no Card home-data network refetch is triggered by the account switch

  Scenario: Real funding assets keep being shown alongside placeholders
    Given I have an account with at least one delegated Card token (Active)

    When I open the Card spending-limit screen for that account

    Then the Active token is shown with its enabled state
      And any other Card-supported tokens that are not yet enabled appear as "Not enabled" placeholders
      And the placeholders are stamped with the currently selected wallet address

  Scenario: Cashback Linea USDC continues to work
    Given the Card feature is enabled
      And the selected account has not yet enabled USDC on Linea

    When I open the Cashback flow

    Then USDC on Linea is detected as the cashback token (via the synthesized placeholder)
      And the "Linea funding requirement" path renders as expected

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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
Moves token placeholder synthesis from provider fetch-time to selector projection-time, changing what tokens are shown and how they’re sorted after account switches. Risk is moderate because it affects spending-limit and cashback token selection logic across wallets but is covered by updated tests.

Overview
Fixes an account-switch bug where the spending-limit token picker could show no tokens available by moving “Not enabled” placeholder creation out of BaanxProvider.buildSupportedTokens and into selectCardAvailableTokens, so placeholders are stamped with the currently selected EVM wallet without refetching home data.

BaanxProvider.buildSupportedTokens now only enriches real fundingAssets with delegationContract, while selectors synthesize delegation-derived placeholders via buildDelegationTokenList, dedupe against real entries for the current wallet, and apply a deterministic sort (priority then status). selectCardLineaUsdcToken is updated to fall back to the delegation-derived placeholder (for Cashback/Linea USDC), and tests are updated/expanded to validate placeholder behavior, account switching, and ordering.

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

@Brunonascdev Brunonascdev self-assigned this May 20, 2026
@Brunonascdev Brunonascdev requested a review from a team as a code owner May 20, 2026 01:06
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@Brunonascdev Brunonascdev added the team-card Card Team label May 20, 2026
Comment thread app/selectors/cardController.ts Outdated
@github-actions github-actions Bot added size-L and removed size-M labels May 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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 c28ec40. Configure here.

Comment thread app/selectors/cardController.ts Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.03%. Comparing base (3ee5c69) to head (c28ec40).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
app/selectors/cardController.ts 76.19% 0 Missing and 10 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #30414   +/-   ##
=======================================
  Coverage   82.03%   82.03%           
=======================================
  Files        5454     5455    +1     
  Lines      145830   145899   +69     
  Branches    33411    33436   +25     
=======================================
+ Hits       119629   119691   +62     
+ Misses      18016    18012    -4     
- Partials     8185     8196   +11     

☔ 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

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are focused entirely on the MetaMask Card feature:

  1. BaanxProvider.ts: Removed wallet-address-based inactive token placeholder synthesis from buildSupportedTokens. The method now only enriches existing funding assets with delegationContract from matching networks, without generating per-wallet inactive placeholders.

  2. cardController.ts (selector): selectCardAvailableTokens and selectCardLineaUsdcToken now synthesize inactive token placeholders at the selector level using buildDelegationTokenList + selectCardFeatureFlag. This is a significant architectural shift - placeholder generation moved from the provider/API layer to the Redux selector layer, enabling account-switch-reactive token lists without refetching.

  3. The selector changes affect CardHome, MoneyHomeView, Cashback, and other card components that consume selectCardAvailableTokens and selectCardLineaUsdcToken.

Why SmokeMoney: These changes directly affect the Card home screen token display, Add Funds flow (which tokens are available to fund), and cashback view. The SmokeMoney tag covers card home, navbar entry, Add Funds flows, and card analytics - all of which depend on the modified selectors.

Why not other tags: The changes are isolated to the Card/Money feature domain. No confirmations, swaps, network, or account management code was modified. The SmokeMoney description mentions that when Add Funds flows execute swaps, SmokeSwap and SmokeConfirmations should also be selected - however, the changes here are to token availability display logic, not the swap/confirmation execution path itself. The core card Add Funds flow tests in SmokeMoney will exercise the modified selectors adequately.

Performance Test Selection:
The changes are refactoring of card token placeholder synthesis from the provider layer to the Redux selector layer. While this affects selector computation, it's a logic reorganization rather than a performance-impacting change. The selector uses createSelector (memoized), and the buildDelegationTokenList utility is called at projection time. No UI rendering components, list rendering, animations, or critical user flows (login, startup, swap) were modified. No performance test tags are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@Brunonascdev Brunonascdev added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 9972f49 May 20, 2026
169 of 188 checks passed
@Brunonascdev Brunonascdev deleted the fix/card-spending-limit-tokens-on-account-switch branch May 20, 2026 16:03
@github-actions github-actions Bot locked and limited conversation to collaborators May 20, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-L team-card Card Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants