Skip to content

Conversation

@infiniteflower
Copy link
Contributor

@infiniteflower infiniteflower commented Jan 7, 2026

Description

When switching between Solana tokens in the Bridge/Swaps UI, selecting a token with zero or undefined balance would incorrectly display the previous token's balance. This was caused by stale state not being cleared when switching tokens, and a truthiness check that failed for "0" balance.

Changelog

CHANGELOG entry: Fixed a bug where switching Solana tokens showed incorrect balance

Related issues

Fixes: SWAPS-3686

Manual testing steps

Feature: Solana token balance display

  Scenario: user switches to a token with zero balance
    Given user is on Bridge/Swaps with Solana network selected
    And user has selected a token with non-zero balance

    When user switches to a different token with zero balance
    Then the balance should show zero (not the previous token's balance)

Screenshots/Recordings

Before

Screen.Recording.2026-01-07.at.4.06.09.PM.mov

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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

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-swaps-and-bridge Swaps and Bridge team label Jan 7, 2026
@github-actions github-actions bot added size-S and removed size-XS labels Jan 7, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeTrade
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

The changes are focused on the Bridge UI component and the useLatestBalance hook used in Bridge functionality:

  1. TokenInputArea/index.tsx: A small UI fix that changes when error color is displayed for insufficient balance - now only shows error color for source token (not destination). This is a visual-only change.

  2. useLatestBalance/index.ts:

    • Adds a new assetId field (CAIP-19 format) to the balance object for consistent token matching
    • Adds logic to reset balance when token changes to prevent stale data
    • Fixes a bug where "0" balance was incorrectly treated as falsy
  3. useLatestBalance.test.tsx: Unit test updates to include the new assetId field.

The useLatestBalance hook is used in:

  • BridgeView (main bridge view)
  • QuoteDetailsCard (bridge quote display)
  • SwapsKeypad (swap input)
  • useBridgeQuoteRequest (bridge quote requests)

All these are part of the Bridge/Swap functionality. The E2E tests in e2e/specs/swaps/bridge-action-smoke.spec.ts and e2e/specs/swaps/swap-action-smoke.spec.ts are tagged with SmokeTrade and test the bridge and swap flows that would exercise these changes.

The risk is medium because:

  • The changes affect balance display and tracking in the bridge flow
  • The bug fix for "0" balance handling could affect edge cases
  • The changes are well-scoped to Bridge functionality with good unit test coverage

View GitHub Actions results

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 7, 2026

@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2026
@infiniteflower
Copy link
Contributor Author

Closed in favor of #24329

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size-S team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants