Skip to content

Conversation

@runway-github
Copy link
Contributor

@runway-github runway-github bot commented Nov 21, 2025

Description

Fix conversion rate for POL native token.

Changelog

CHANGELOG entry:

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/6327

Manual testing steps

  1. Trigger swap including POL native token
  2. Check that metrics are recorded correctly and dapp-swap UI shows
    correct values

Screenshots/Recordings

TODO

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

Fixes USD rate lookup for Polygon native token by mapping native address to 0x0000000000000000000000000000000000001010 and adds tests.

  • Hooks:
    • Update ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.ts to adjust fiat rate fetching:
      • When chainId === CHAIN_IDS.POLYGON, map the native asset address to the rate from 0x0000000000000000000000000000000000001010.
      • Wrap rate fetching in an async function to inject the Polygon-specific mapping.
  • Tests:
    • Enhance useDappSwapUSDValues.test.ts:
      • Allow runHook to accept custom tokenAddresses and mockConfirmation.
      • Add Polygon-specific test asserting correct fiat rates for native POL (0x...0000) and 0x0000000000000000000000000000000000001010.

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

0aa98dc

…38102)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

Fix conversion rate for POL native token.

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry:

Fixes: MetaMask/MetaMask-planning#6327

1. Trigger swap including POL native token
2. Check that metrics are recorded correctly and dapp-swap UI shows
correct values

TODO

- [X] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [X] I've completed the PR template to the best of my ability
- [X] I’ve included tests if applicable
- [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] 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.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Fixes USD conversion for Polygon native token by mapping POL’s special
address and adds targeted unit tests.
>
> - **Hook `useDappSwapUSDValues`
(`ui/pages/.../useDappSwapUSDValues.ts`)**:
> - Map Polygon native token USD rate: when `chainId ===
CHAIN_IDS.POLYGON`, set the native asset’s address rate from
`0x0000000000000000000000000000000000001010`.
> - Switch `isNativeAddress` to `helpers/utils/token-insights` and
import `CHAIN_IDS`.
> - Refactor exchange-rate fetch to async IIFE within `useAsyncResult`.
> - **Tests (`ui/pages/.../useDappSwapUSDValues.test.ts`)**:
> - Enhance `runHook` to accept custom token addresses and confirmation.
> - Add Polygon-specific test asserting fiat rates include both native
addresses with correct USD value.
>   - Mock token details and rates accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ccd13a6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@runway-github runway-github bot requested a review from a team as a code owner November 21, 2025 16:45
@github-actions
Copy link
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-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Nov 21, 2025
if (chainId === CHAIN_IDS.POLYGON) {
const nativeAddress = getNativeAssetForChainId(chainId).address;
exchangeRates[nativeAddress] = exchangeRates[POLYGON_NATIVE_ASSET];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing zero address mapping for Polygon native token rates

When on Polygon, the code maps the exchange rate from POLYGON_NATIVE_ASSET (0x0000000000000000000000000000000000001010) to the chain's native asset address. However, callers may also reference the universal zero address (0x0000000000000000000000000000000000000000) for the native token. The current implementation only populates the Polygon native asset address, leaving lookups by the zero address without a rate value, causing incorrect USD value calculations.

Fix in Cursor Fix in Web

@metamaskbot
Copy link
Collaborator

✨ Files requiring CODEOWNER review ✨

@MetaMask/confirmations (2 files, +57 -6)
  • 📁 ui/
    • 📁 pages/
      • 📁 confirmations/
        • 📁 hooks/
          • 📁 transactions/
            • 📁 dapp-swap-comparison/
              • 📄 useDappSwapUSDValues.test.ts +41 -3
              • 📄 useDappSwapUSDValues.ts +16 -3

@metamaskbot
Copy link
Collaborator

Builds ready [c7fe193]
UI Startup Metrics (1216 ± 85 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1216107914818512721370
load105392012597811101196
domContentLoaded104791712507711011188
domInteractive221486171971
firstPaint65070125742210581167
backgroundConnect2322202557237247
firstReactRender29207382945
getState2185892535
initialActions103111
loadScripts820697102577881953
setupStore1152941221
numNetworkReqs1367419669
BrowserifyPower User HomeuiStartup19931632297234123332972
load1082924153818512771538
domContentLoaded1071914152318412691523
domInteractive50171704598170
firstPaint70120913974239941397
backgroundConnect24022827110244271
firstReactRender56486766067
getState22315534254245342
initialActions104124
loadScripts841689126717810401267
setupStore20134482144
numNetworkReqs956817441156174
WebpackStandard HomeuiStartup86572712281058561151
load63057597993629935
domContentLoaded62257196188620906
domInteractive191295151561
firstPaint20965964215206920
backgroundConnect271278152964
firstReactRender32207193740
getState1163741317
initialActions104112
loadScripts61956995186617895
setupStore1263241417
numNetworkReqs1367419871
WebpackPower User HomeuiStartup1057878171425812841714
load636551990136697990
domContentLoaded622542958126667958
domInteractive33121323778132
firstPaint38064916269567916
backgroundConnect61921668152216
firstReactRender38363913839
getState1348815021148150
initialActions101011
loadScripts618540948123657948
setupStore96256825
numNetworkReqs805913427121134
FirefoxBrowserifyStandard HomeuiStartup15891397226816016231917
load1313119315959613511551
domContentLoaded1312119215959613501550
domInteractive61353985946220
firstPaint------
backgroundConnect49242193252129
firstReactRender31256373246
getState1487291429
initialActions203123
loadScripts1284117215518813161507
setupStore218229311755
numNetworkReqs1267016862
BrowserifyPower User HomeuiStartup28192076423760032234237
load14941264174615716631746
domContentLoaded14931263174515716631745
domInteractive23069530140330530
firstPaint------
backgroundConnect3375711453455181145
firstReactRender72471372280137
getState17341488124299488
initialActions213123
loadScripts14501237171515016331715
setupStore89273538089353
numNetworkReqs1166125472177254
WebpackStandard HomeuiStartup16861481227816316822104
load14271272195512114521700
domContentLoaded14271272195312114521700
domInteractive63322212976115
firstPaint------
backgroundConnect49252213152126
firstReactRender382589153780
getState137128131222
initialActions203123
loadScripts13961242187010714201648
setupStore187193271453
numNetworkReqs1367218770
WebpackPower User HomeuiStartup29502399412050631874120
load16351462198615417741986
domContentLoaded16341462198615417741986
domInteractive20067527134295527
firstPaint------
backgroundConnect28959951269383951
firstReactRender76521111687111
getState210105643147210643
initialActions52327332
loadScripts15821426185113816891851
setupStore13349633142121633
numNetworkReqs1155722662200226
📊 Page Load Benchmark Results

Current Commit: c7fe193 | Date: 11/21/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.09s (±76ms) 🟡 | historical mean value: 1.05s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 762ms (±74ms) 🟢 | historical mean value: 731ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 81ms (±11ms) 🟢 | historical mean value: 80ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.09s 76ms 1.03s 1.38s 1.33s 1.38s
domContentLoaded 762ms 74ms 715ms 1.05s 993ms 1.05s
firstPaint 81ms 11ms 72ms 176ms 88ms 176ms
firstContentfulPaint 81ms 11ms 72ms 176ms 88ms 176ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms

import { Hex } from '@metamask/utils';
import {
getNativeAssetForChainId,
isNativeAddress,
Copy link
Contributor

@gauthierpetetin gauthierpetetin Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to facilitate the future stable-sync PR:

In the original PR on main, isNativeAddress is imported from a different location:

import { isNativeAddress } from '../../../../../helpers/utils/token-insights';

This is because the location of isNativeAddress was moved in this PR, which is part of 13.11.0 but is not included in 13.10.1.

@gauthierpetetin gauthierpetetin merged commit 8f631e6 into release/13.10.1 Nov 21, 2025
176 of 177 checks passed
@gauthierpetetin gauthierpetetin deleted the cherry-pick-13-10-1-0aa98dc branch November 21, 2025 17:30
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2025
@metamaskbot metamaskbot added the release-13.10.1 Issue or pull request that will be included in release 13.10.1 label Nov 21, 2025
@metamaskbot
Copy link
Collaborator

No release label on PR. Adding release label release-13.10.1 on PR, as PR was cherry-picked in branch 13.10.1.

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

Labels

release-13.10.1 Issue or pull request that will be included in release 13.10.1 team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants