Skip to content

feat(card): add balance properties on SpendingLimit Card Viewed screen#27981

Merged
Brunonascdev merged 3 commits into
mainfrom
feat/add-spending-limit-balances-metrics
Mar 26, 2026
Merged

feat(card): add balance properties on SpendingLimit Card Viewed screen#27981
Brunonascdev merged 3 commits into
mainfrom
feat/add-spending-limit-balances-metrics

Conversation

@Brunonascdev

@Brunonascdev Brunonascdev commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Description

Adds wallet balance context to the Card CARD_VIEWED event when the user opens the Spending limit (or enable-token) flow, and aligns row affordance icons with a down chevron on the settings-style rows.

Why: Product and analytics need to understand Linea mUSD exposure, which card-supported asset has the highest fiat balance for the current account, and which asset is top across the whole wallet (EVM networks plus Solana) at screen view time—without inferring this from other screens.

What changed:

  • useSpendingLimit.ts
    • Calls useTokensWithBalance twice: card chain IDs (CARD_CHAIN_IDS) for walletTokens, and all configured EVM chain IDs plus Solana (via selectEvmNetworkConfigurationsByChainId and cardNetworkInfos.solana.caipChainId) for allWalletTokens.
    • On MetaMetricsEvents.CARD_VIEWED, adds:
      • musd_linea_balance: fiat amount for mUSD on Linea on the selected account, or 0 if absent.
      • top_card_chain_asset: network:symbol (e.g. linea:musd) for the highest fiat token among card-supported balances (allTokens intersection), or null if none / unsupported-only (e.g. top balance not in card list).
      • top_wallet_chain_asset / top_wallet_asset_balance: highest fiat token across all wallet tokens and its fiat value (or null / 0 when applicable). Network label uses caipChainIdToNetwork where mapped, otherwise the CAIP chain id string.
    • Introduces toNetworkAsset to normalize network:symbol for analytics.
    • Analytics effect runs after wallet token hooks; dependency array intentionally limited (with eslint comment) so the viewed snapshot stays stable at mount.
  • SpendingLimit.tsx: Account, Token, and Spending limit row trailing icons ArrowRightArrowDown for clearer expand/dropdown affordance.
  • useSpendingLimit.test.ts: Tests for musd_linea_balance, top_card_chain_asset (including empty list, non-card-supported top token), and top_wallet_chain_asset / top_wallet_asset_balance; clarifies default selector mock comment.

Changelog

CHANGELOG entry: Card Spending limit screen analytics include Linea mUSD fiat balance, top card-supported asset by fiat, and top wallet-wide asset by fiat when the screen is viewed.

Related issues

Fixes:

Manual testing steps

Feature: Spending limit viewed analytics and row icons

  Scenario: CARD_VIEWED includes balance properties
    Given I open Spending limit (or enable flow) with a known Linea mUSD balance and other tokens
    When the screen is tracked as viewed
    Then CARD_VIEWED includes musd_linea_balance, top_card_chain_asset, top_wallet_chain_asset, and top_wallet_asset_balance consistent with the selected account and supported tokens

  Scenario: Row chevrons
    When I view the Spending limit settings rows (Account, Token, Spending limit)
    Then each row shows a down chevron affordance instead of a right arrow

Screenshots/Recordings

Optional: capture the three rows showing down chevrons. For analytics, verify in debug/logs or analytics tooling that CARD_VIEWED payloads include the new properties.

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
Adds new analytics properties derived from wallet token balances and network configuration, including multi-chain sorting logic and a one-time firing guard; mistakes could skew metrics or add minor performance overhead on screen mount.

Overview
Enriches the card Spending Limit/Enable flow CARD_VIEWED analytics event with wallet balance context: musd_linea_balance, the highest-fiat card-supported asset (top_card_chain_asset), and the highest-fiat asset across all configured wallet chains plus Solana (top_wallet_chain_asset + top_wallet_asset_balance).

Updates useSpendingLimit to fetch balances via useTokensWithBalance for both card chains and all wallet chains, normalizes network:symbol formatting, and delays/fires the screen-view event exactly once after allTokens is non-empty to avoid unsupported/empty snapshots; adds unit tests covering these new metrics.

Adjusts the Spending Limit settings rows’ trailing affordance icons from ArrowRight to ArrowDown for Account/Token/Spending limit rows.

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

@Brunonascdev Brunonascdev self-assigned this Mar 26, 2026
@Brunonascdev Brunonascdev requested a review from a team as a code owner March 26, 2026 16:37
@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.

@metamaskbot metamaskbot added the team-card Card Team label Mar 26, 2026
@github-actions github-actions Bot added size-M risk-low Low testing needed · Low bug introduction risk labels Mar 26, 2026
Comment thread app/components/UI/Card/hooks/useSpendingLimit.ts
@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 Mar 26, 2026
Comment thread app/components/UI/Card/hooks/useSpendingLimit.ts Outdated
@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 Mar 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are isolated to the MetaMask Card feature's SpendingLimit component:

  1. SpendingLimit.tsx: Pure cosmetic change - 3 icons changed from ArrowRight to ArrowDown to better indicate dropdown/selector behavior. No logic changes.

  2. useSpendingLimit.ts: Analytics enrichment - adds new properties to the CARD_VIEWED analytics event (musd_linea_balance, top_card_chain_asset, top_wallet_chain_asset, top_wallet_asset_balance). Also adds a screenViewFiredRef guard to ensure the event fires exactly once after token data loads. Adds allWalletTokens using selectEvmNetworkConfigurationsByChainId selector.

  3. useSpendingLimit.test.ts: Unit tests covering the new analytics properties.

SmokeCard is the primary tag as these changes are entirely within the Card feature's SpendingLimit view. Per SmokeCard's description, SmokeTrade and SmokeConfirmations are required dependent tags (Add Funds uses swaps which require transaction confirmations).

No other features are affected - no shared components, no navigation changes, no controller changes, no Engine changes.

Performance Test Selection:
The changes are limited to analytics event enrichment and a cosmetic icon change within the Card SpendingLimit view. No rendering performance impact, no list rendering changes, no state management changes that would affect performance metrics. The new useTokensWithBalance call for allWalletTokens is a minor addition that doesn't warrant performance testing.

View GitHub Actions results

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

Comment thread app/components/UI/Card/hooks/useSpendingLimit.ts
@sonarqubecloud

Copy link
Copy Markdown

@Brunonascdev Brunonascdev enabled auto-merge March 26, 2026 17:51
@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

@Brunonascdev Brunonascdev added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit ae5b5bb Mar 26, 2026
151 of 154 checks passed
@Brunonascdev Brunonascdev deleted the feat/add-spending-limit-balances-metrics branch March 26, 2026 18:28
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 26, 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-low Low testing needed · Low bug introduction risk size-M team-card Card Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants