-
Notifications
You must be signed in to change notification settings - Fork 5.4k
release(runway): cherry-pick fix: dapp swap fix conversion rate for pol native token #38136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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 -->
|
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. |
| if (chainId === CHAIN_IDS.POLYGON) { | ||
| const nativeAddress = getNativeAssetForChainId(chainId).address; | ||
| exchangeRates[nativeAddress] = exchangeRates[POLYGON_NATIVE_ASSET]; | ||
| } |
There was a problem hiding this comment.
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.
✨ Files requiring CODEOWNER review ✨✅ @MetaMask/confirmations (2 files, +57 -6)
|
Builds ready [c7fe193]
UI Startup Metrics (1216 ± 85 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
| import { Hex } from '@metamask/utils'; | ||
| import { | ||
| getNativeAssetForChainId, | ||
| isNativeAddress, |
There was a problem hiding this comment.
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.
|
No release label on PR. Adding release label release-13.10.1 on PR, as PR was cherry-picked in branch 13.10.1. |
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
correct values
Screenshots/Recordings
TODO
Pre-merge author checklist
Docs and MetaMask
Extension Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
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
0x0000000000000000000000000000000000001010and adds tests.ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.tsto adjust fiat rate fetching:chainId === CHAIN_IDS.POLYGON, map the native asset address to the rate from0x0000000000000000000000000000000000001010.useDappSwapUSDValues.test.ts:runHookto accept customtokenAddressesandmockConfirmation.0x...0000) and0x0000000000000000000000000000000000001010.Written by Cursor Bugbot for commit c7fe193. This will update automatically on new commits. Configure here.
0aa98dc