-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
…-balances' into 28534-asset-page-native-fix
- Loading branch information
Showing
13 changed files
with
197 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './native-token'; |
52 changes: 52 additions & 0 deletions
52
ui/components/app/assets/asset-list/native-token/native-token.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
getMultichainCurrentNetwork, | ||
getMultichainNativeCurrency, | ||
getMultichainIsEvm, | ||
getMultichainCurrencyImage, | ||
getMultichainIsMainnet, | ||
getMultichainSelectedAccountCachedBalance, | ||
} from '../../../../../selectors/multichain'; | ||
import { getPreferences } from '../../../../../selectors'; | ||
import { TokenListItem } from '../../../../multichain'; | ||
import { AssetListProps } from '../asset-list'; | ||
import { useNativeTokenBalance } from './use-native-token-balance'; | ||
|
||
const NativeToken = ({ onClickAsset }: AssetListProps) => { | ||
const nativeCurrency = useSelector(getMultichainNativeCurrency); | ||
const isMainnet = useSelector(getMultichainIsMainnet); | ||
const { chainId } = useSelector(getMultichainCurrentNetwork); | ||
const { privacyMode } = useSelector(getPreferences); | ||
const balance = useSelector(getMultichainSelectedAccountCachedBalance); | ||
const balanceIsLoading = !balance; | ||
|
||
const { string, symbol, secondary } = useNativeTokenBalance(); | ||
|
||
const primaryTokenImage = useSelector(getMultichainCurrencyImage); | ||
|
||
const isEvm = useSelector(getMultichainIsEvm); | ||
|
||
let isStakeable = isMainnet && isEvm; | ||
///: BEGIN:ONLY_INCLUDE_IF(build-mmi) | ||
isStakeable = false; | ||
///: END:ONLY_INCLUDE_IF | ||
|
||
return ( | ||
<TokenListItem | ||
chainId={chainId} | ||
onClick={() => onClickAsset(chainId, nativeCurrency)} | ||
title={nativeCurrency} | ||
primary={string} | ||
tokenSymbol={symbol} | ||
secondary={secondary} | ||
tokenImage={balanceIsLoading ? null : primaryTokenImage} | ||
isNativeCurrency | ||
isStakeable={isStakeable} | ||
showPercentage | ||
privacyMode={privacyMode} | ||
/> | ||
); | ||
}; | ||
|
||
export default NativeToken; |
94 changes: 94 additions & 0 deletions
94
ui/components/app/assets/asset-list/native-token/use-native-token-balance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import currencyFormatter from 'currency-formatter'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { | ||
getMultichainCurrencyImage, | ||
getMultichainCurrentNetwork, | ||
getMultichainSelectedAccountCachedBalance, | ||
getMultichainShouldShowFiat, | ||
} from '../../../../../selectors/multichain'; | ||
import { getCurrentCurrency, getPreferences } from '../../../../../selectors'; | ||
import { useIsOriginalNativeTokenSymbol } from '../../../../../hooks/useIsOriginalNativeTokenSymbol'; | ||
import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common'; | ||
import { useUserPreferencedCurrency } from '../../../../../hooks/useUserPreferencedCurrency'; | ||
import { useCurrencyDisplay } from '../../../../../hooks/useCurrencyDisplay'; | ||
import { TokenWithBalance } from '../asset-list'; | ||
|
||
export const useNativeTokenBalance = () => { | ||
const showFiat = useSelector(getMultichainShouldShowFiat); | ||
const primaryTokenImage = useSelector(getMultichainCurrencyImage); | ||
const { showNativeTokenAsMainBalance } = useSelector(getPreferences); | ||
const { chainId, ticker, type, rpcUrl } = useSelector( | ||
getMultichainCurrentNetwork, | ||
); | ||
const isOriginalNativeSymbol = useIsOriginalNativeTokenSymbol( | ||
chainId, | ||
ticker, | ||
type, | ||
rpcUrl, | ||
); | ||
const balance = useSelector(getMultichainSelectedAccountCachedBalance); | ||
const currentCurrency = useSelector(getCurrentCurrency); | ||
const { | ||
currency: primaryCurrency, | ||
numberOfDecimals: primaryNumberOfDecimals, | ||
} = useUserPreferencedCurrency(PRIMARY, { | ||
ethNumberOfDecimals: 4, | ||
shouldCheckShowNativeToken: true, | ||
}); | ||
const { | ||
currency: secondaryCurrency, | ||
numberOfDecimals: secondaryNumberOfDecimals, | ||
} = useUserPreferencedCurrency(SECONDARY, { | ||
ethNumberOfDecimals: 4, | ||
shouldCheckShowNativeToken: true, | ||
}); | ||
|
||
const [primaryCurrencyDisplay, primaryCurrencyProperties] = | ||
useCurrencyDisplay(balance, { | ||
numberOfDecimals: primaryNumberOfDecimals, | ||
currency: primaryCurrency, | ||
}); | ||
|
||
const [secondaryCurrencyDisplay, secondaryCurrencyProperties] = | ||
useCurrencyDisplay(balance, { | ||
numberOfDecimals: secondaryNumberOfDecimals, | ||
currency: secondaryCurrency, | ||
}); | ||
|
||
const primaryBalance = isOriginalNativeSymbol | ||
? secondaryCurrencyDisplay | ||
: undefined; | ||
|
||
const secondaryBalance = | ||
showFiat && isOriginalNativeSymbol ? primaryCurrencyDisplay : undefined; | ||
|
||
const tokenSymbol = showNativeTokenAsMainBalance | ||
? primaryCurrencyProperties.suffix | ||
: secondaryCurrencyProperties.suffix; | ||
|
||
const unformattedTokenFiatAmount = showNativeTokenAsMainBalance | ||
? secondaryCurrencyDisplay.toString() | ||
: primaryCurrencyDisplay.toString(); | ||
|
||
// useCurrencyDisplay passes along the symbol and formatting into the value here | ||
// for sorting we need the raw value, without the currency and it should be decimal | ||
// this is the easiest way to do this without extensive refactoring of useCurrencyDisplay | ||
const tokenFiatAmount = currencyFormatter | ||
.unformat(unformattedTokenFiatAmount, { | ||
code: currentCurrency.toUpperCase(), | ||
}) | ||
.toString(); | ||
|
||
const nativeTokenWithBalance: TokenWithBalance = { | ||
address: '', | ||
symbol: tokenSymbol ?? '', | ||
string: primaryBalance, | ||
image: primaryTokenImage, | ||
secondary: secondaryBalance, | ||
tokenFiatAmount, | ||
isNative: true, | ||
}; | ||
|
||
return nativeTokenWithBalance; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.