Skip to content

fix: account for POL non-zero native address cp-7.69.0#27052

Merged
bfullam merged 4 commits into
mainfrom
swaps-fix-polygon-gas-token-selection
Mar 6, 2026
Merged

fix: account for POL non-zero native address cp-7.69.0#27052
bfullam merged 4 commits into
mainfrom
swaps-fix-polygon-gas-token-selection

Conversation

@bfullam

@bfullam bfullam commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a bug in the bridge token selector where Polygon's native token (POL) appeared twice in the list — once with balance at the top and once without balance at the bottom. Selecting the balance entry as a destination token caused the quote to show 0 and the rate to display "--".

Root cause: Polygon's native token uses address 0x0000000000000000000000000000000000001010 in wallet state (from getNativeTokenAddress), but the bridge API expects AddressZero (0x0000...0000) for all native assets. The bridge-controller's isNativeAddress() does not recognize 0x...1010 as native, so:

  1. tokenToIncludeAsset sent the wrong asset ID (erc20:0x...1010 instead of slip44:966) to the API, which couldn't deduplicate it with its own native POL entry.
  2. When the user selected POL with 0x...1010, quote matching in useBridgeQuoteData failed because the returned quote used AddressZero for destAsset.address.

Fix: Extracted the existing normalization logic from useTokenAddress into a reusable pure function normalizeTokenAddress, and applied it in useTokensWithBalance when building BridgeToken objects from wallet state. This ensures POL enters the bridge flow with AddressZero from the start, fixing both the duplicate listing and the quote/rate mismatch.

Changelog

CHANGELOG entry: Fixed a bug where Polygon's native token (POL) appeared twice in the bridge token selector and selecting it showed incorrect quote data.

Related issues

Fixes:

Manual testing steps

Feature: Bridge token selector - Polygon native token

  Scenario: user selects POL as destination token on Polygon
    Given user has a POL balance on Polygon
    And user opens the bridge token selector for destination

    When user filters by Polygon network
    Then POL appears only once in the token list with balance displayed

  Scenario: user gets a valid quote after selecting POL destination
    Given user has a source token with balance
    And user has selected POL on Polygon as the destination token

    When the quote loads
    Then the destination input shows a non-zero amount
    And the rate displays a valid exchange rate (not "--")

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
Medium risk because it changes how token addresses are represented in the bridge token list and downstream API/quote matching, which could affect token identification on Polygon. Scope is small and isolated to bridge token normalization.

Overview
Fixes Polygon native token (POL) handling in the bridge UI by normalizing Polygon’s non-zero native token address to the zero address the bridge API expects.

Extracts the Polygon-specific normalization from useTokenAddress into a reusable normalizeTokenAddress utility and applies it when constructing tokens in useTokensWithBalance, preventing duplicate POL entries and quote mismatches caused by inconsistent native-address representations.

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

@bfullam bfullam requested a review from a team as a code owner March 5, 2026 11:15
@github-actions

github-actions Bot commented Mar 5, 2026

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-swaps-and-bridge Swaps and Bridge team label Mar 5, 2026
@github-actions github-actions Bot added the size-S label Mar 5, 2026
Comment thread app/components/UI/Bridge/hooks/useTokenAddress/index.ts Outdated
@GeorgeGkas GeorgeGkas self-requested a review March 5, 2026 16:38
@bfullam bfullam enabled auto-merge March 5, 2026 16:49
@bfullam bfullam changed the title fix: account for POL non-zero native address fix: account for POL non-zero native address cp-7.69.0 Mar 6, 2026
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are a refactoring of the Bridge feature's token address normalization logic. A new utility function normalizeTokenAddress was added to tokenUtils.ts to centralize the logic for handling Polygon's native token address (which uses 0x0000000000000000000000000000000000001010 but the bridge API expects the zero address). Both useTokenAddress and useTokensWithBalance hooks now use this centralized utility instead of having the logic inline.

The changes are purely refactoring with no functional changes - the same logic is preserved, just extracted into a reusable utility. The affected hooks are used in:

  • TokenInputArea component (bridge UI)
  • useShouldRenderMaxOption hook
  • useSortedSourceNetworks hook
  • useBalancesByAssetId hook

SmokeTrade is selected because it covers bridge functionality (tests/smoke/swap/bridge-action-smoke.spec.ts). SmokeConfirmations is selected as a dependent tag per the tag description guidance: "when selecting SmokeTrade for swap or bridge flows, also select SmokeConfirmations".

Performance Test Selection:
The changes are purely refactoring - extracting existing logic into a shared utility function. There are no changes to UI rendering, data loading patterns, state management, or app initialization. The token address normalization is a simple string comparison and replacement operation that has negligible performance impact. No performance tests are needed.

View GitHub Actions results

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ E2E Fixture Validation — Structural changes detected

Category Count
New keys 68
Missing keys 11
Type mismatches 0
Value mismatches 7 (informational)

The committed fixture schema is out of date. To update, comment:

@metamaskbot update-mobile-fixture

View full details | Download diff report

@sonarqubecloud

sonarqubecloud Bot commented Mar 6, 2026

Copy link
Copy Markdown

@bfullam bfullam added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit ec4fbf2 Mar 6, 2026
98 checks passed
@bfullam bfullam deleted the swaps-fix-polygon-gas-token-selection branch March 6, 2026 08:55
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 6, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 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