-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 |
||
value !== undefined && value !== null | ||
? value * fallbackCurrencyToNativeCurrencyConversionRate | ||
: undefined; | ||
|
||
const updatedContractExchangeRates = Object.entries( | ||
contractExchangeInformations, | ||
).reduce((acc, [tokenAddress, token]) => { | ||
acc = { | ||
...acc, | ||
[tokenAddress]: { | ||
...token, | ||
price: token.price | ||
? token.price * fallbackCurrencyToNativeCurrencyConversionRate | ||
: undefined, | ||
currency: nativeCurrency, | ||
price: convertFallbackToNative(token.price), | ||
marketCap: convertFallbackToNative(token.marketCap), | ||
allTimeHigh: convertFallbackToNative(token.allTimeHigh), | ||
allTimeLow: convertFallbackToNative(token.allTimeLow), | ||
totalVolume: convertFallbackToNative(token.totalVolume), | ||
high1d: convertFallbackToNative(token.high1d), | ||
low1d: convertFallbackToNative(token.low1d), | ||
dilutedMarketCap: convertFallbackToNative(token.dilutedMarketCap), | ||
}, | ||
}; | ||
return acc; | ||
|
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.
https://github.com/MetaMask/core/pull/4615/files#r1719238989