-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix: cp-13.10.1 cp-13.11.0 dapp swap fix conversion rate for pol native token #38102
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
|
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. |
✨ Files requiring CODEOWNER review ✨✅ @MetaMask/confirmations (2 files, +59 -10)
|
| 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.
This fixes the issue for pol token only, I could not find a more generic fix.
| } from '../../../utils/token'; | ||
| import { useConfirmContext } from '../../../context/confirm'; | ||
|
|
||
| const POLYGON_NATIVE_ASSET = '0x0000000000000000000000000000000000001010'; |
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.
We can delegate to getNativeTokenAddress for this?
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.
the function is returning different address 0x0000000000000000000000000000000000000000
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.
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.
We should use getNativeTokenAddress.. it should return 0x0000000000000000000000000000000000001010 for Polygon network and 0x0000000000000000000000000000000000000000 for anything else.
| chainId, | ||
| ); | ||
|
|
||
| if (chainId === CHAIN_IDS.POLYGON) { |
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.
Should this be encapsulated inside fetchTokenExchangeRates for all usages?
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.
I am not sure of other code will need this too.
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.
Ideally the dedupe should be done in the controller side.. but I have just noticed that there was a massive breaking change added to the codefi-v2.ts in core https://github.com/MetaMask/core/pull/7119/files#diff-5801aea8052edaaf64cbe9cbe48734d6e35865a36f37d8a96c4e538536c7b1c2
As this filtering should be short lived I think we can keep it in the useDappSwapUSDValues.ts
|
|
||
| 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.
What is the difference between nativeAddress and 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.
0x0000000000000000000000000000000000001010 vs 0x0000000000000000000000000000000000000000
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.
Price service is using first one.
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.
0x0000000000000000000000000000000000001010 is the native address for Polygon.. are we not getting that address when swapping Pol on Polygon? 🤔
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.
ok the reason for it is because our Bridge API and the dapp swap considers the zero address as the native address for Polygon
| chainId, | ||
| ); | ||
|
|
||
| if (chainId === CHAIN_IDS.POLYGON) { |
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.
Unit test?
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.
yep adding those
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.
PR is upadated
ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.ts
Show resolved
Hide resolved
Builds ready [95a3a69]
UI Startup Metrics (1230 ± 97 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [e7a4726]
UI Startup Metrics (1241 ± 89 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| jest.spyOn(Utils, 'fetchTokenExchangeRates').mockResolvedValue({ | ||
| '0x0000000000000000000000000000000000001010': 4052.27, | ||
| '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 0.999804, | ||
| }); |
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: Test mocks unrequested data masking logic bug
The test mocks fetchTokenExchangeRates to return a rate for the Polygon native asset (0x...1010), even though the hook implementation does not request this address. This mismatch between the mock and the actual implementation masks the bug where the rate is never fetched in production.
Builds ready [ccd13a6]
UI Startup Metrics (1208 ± 100 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
…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. --> ## **Description** Fix conversion rate for POL native token. ## **Changelog** <!-- 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: ## **Related issues** Fixes: MetaMask/MetaMask-planning#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** - [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. ## **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. <!-- 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 -->
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
Screenshots/Recordings
TODO
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Fixes USD conversion for Polygon native token by mapping POL’s special address and adds targeted unit tests.
useDappSwapUSDValues(ui/pages/.../useDappSwapUSDValues.ts):chainId === CHAIN_IDS.POLYGON, set the native asset’s address rate from0x0000000000000000000000000000000000001010.isNativeAddresstohelpers/utils/token-insightsand importCHAIN_IDS.useAsyncResult.ui/pages/.../useDappSwapUSDValues.test.ts):runHookto accept custom token addresses and confirmation.Written by Cursor Bugbot for commit ccd13a6. This will update automatically on new commits. Configure here.