-
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
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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { | |
| getNativeAssetForChainId, | ||
| isNativeAddress, | ||
| } from '@metamask/bridge-controller'; | ||
| import { TransactionMeta } from '@metamask/transaction-controller'; | ||
| import { CHAIN_IDS, TransactionMeta } from '@metamask/transaction-controller'; | ||
| import { useCallback } from 'react'; | ||
|
|
||
| import { TokenStandAndDetails } from '../../../../../store/actions'; | ||
|
|
@@ -15,6 +15,8 @@ import { fetchAllTokenDetails } from '../../../utils/token'; | |
| import { getTokenValueFromRecord } from '../../../utils/dapp-swap-comparison-utils'; | ||
| import { useConfirmContext } from '../../../context/confirm'; | ||
|
|
||
| const POLYGON_NATIVE_ASSET = '0x0000000000000000000000000000000000001010'; | ||
|
|
||
| export function useDappSwapUSDValues({ | ||
| tokenAddresses = [], | ||
| destTokenAddress, | ||
|
|
@@ -30,11 +32,22 @@ export function useDappSwapUSDValues({ | |
|
|
||
| const { value: fiatRates, pending: fiatRatesPending } = useAsyncResult< | ||
| Record<Hex, number | undefined> | ||
| >(() => { | ||
| >(async () => { | ||
| const addresses = tokenAddresses.filter( | ||
| (tokenAddress) => !isNativeAddress(tokenAddress), | ||
| ); | ||
| return fetchTokenExchangeRates('usd', addresses as Hex[], chainId); | ||
| const exchangeRates = await fetchTokenExchangeRates( | ||
| 'usd', | ||
| addresses as Hex[], | ||
| chainId, | ||
| ); | ||
|
|
||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing zero address mapping for Polygon native token ratesWhen on Polygon, the code maps the exchange rate from |
||
|
|
||
| return exchangeRates; | ||
| }, [chainId, tokenAddresses?.length]); | ||
|
|
||
| const { value: tokenDetails, pending: tokenDetailsPending } = useAsyncResult< | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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,isNativeAddressis imported from a different location:This is because the location of
isNativeAddresswas moved in this PR, which is part of13.11.0but is not included in13.10.1.