-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
fix: fallback conversion rate for token market data #4615
Conversation
@@ -745,16 +745,28 @@ export class TokenRatesController extends StaticIntervalPollingController< | |||
return {}; | |||
} | |||
|
|||
// Converts the price in the fallback currency to the native currency | |||
const convertFallbackToNative = (value: number | undefined) => |
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.
Can these calculations be done with a non-destructive decimal type like BigNumber, instead of lossy floats (JS Number)?
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.
Is there a case you're worried about that can produce a problem, like very small/big numbers? Is this different than other multiplications ?
And how would you do it in code? I think it should eventually serialize as a number, so does that look like converting to BigNumber
, multiplying, then back to number?
marketCapPercentChange1d: 100, | ||
price: 0.001, | ||
price: (2 / 1000) * fallbackRate, |
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.
<!-- 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** Patches MetaMask/core#4615 When the price API does not support the native currency (e.g. MATIC), prices are fetched in ETH and an additional conversion hop is performed to the native currency. But this hop was only being performed on the current price, and was missing on the extended market data like marketCap, allTimeHigh, etc. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26460?quickstart=1) ## **Related issues** ## **Manual testing steps** 1. Open the token details page for a polygon token 2. Verify market cap, all time low, all time high are correct ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <img width="357" alt="Screenshot 2024-08-15 at 6 08 43 PM" src="https://github.com/user-attachments/assets/073e2a74-8258-4206-af1d-664eb3d4c1bb"> <img width="353" alt="Screenshot 2024-08-15 at 6 22 15 PM" src="https://github.com/user-attachments/assets/d5603a56-9fea-401a-a7cf-a08654792c17"> ### **After** <img width="351" alt="Screenshot 2024-08-15 at 6 12 46 PM" src="https://github.com/user-attachments/assets/13498481-8fe7-4f6d-852d-8d45508769dd"> <img width="351" alt="Screenshot 2024-08-15 at 6 17 11 PM" src="https://github.com/user-attachments/assets/1f094ce8-0d05-4c7f-bb6d-73221eeb3fef"> <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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.
merging since this was already hotfixed to prod, and i want to keep things in sync. if we hit precision issues we can do something like lego's suggestion later |
Explanation
When the price API does not support the native currency (e.g. MATIC), prices are fetched in ETH and an additional conversion hop is performed to the native currency. But this hop was only being performed on the current price, and was missing on the extended market data like marketCap, allTimeHigh, etc.
References
Changelog
@metamask/assets-controllers
Checklist