diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx index 8ec11e674803..cf0fa4e9049f 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx @@ -20,7 +20,13 @@ import { TrendingViewDeck } from './TrendingViewDeck' import { currentDataProviderSettings } from '../../settings' import { useAvailableCoins } from '../../trending/useAvailableCoins' import { usePreferredCoinId } from '../../trending/useCurrentCoinId' -import { EthereumTokenType, useFungibleTokenDetailed, useChainIdValid, useNetworkType } from '@masknet/web3-shared-evm' +import { + EthereumTokenType, + useFungibleTokenDetailed, + useChainIdValid, + useNetworkType, + isNativeTokenSymbol, +} from '@masknet/web3-shared-evm' const useStyles = makeStyles<{ isPopper: boolean }>()((theme, props) => { return { @@ -192,8 +198,7 @@ export function TraderView(props: TraderViewProps) { // #endregion // #region if the coin is a native token or contract address exists - const isNativeToken = ['eth', 'matic', 'bnb', 'avax'].includes(coinSymbol) - const isSwappable = (!!trending?.coin.contract_address || isNativeToken) && chainIdValid + const isSwappable = (!!trending?.coin.contract_address || isNativeTokenSymbol(coinSymbol)) && chainIdValid // #endregion // #region display loading skeleton diff --git a/packages/mask/src/plugins/Wallet/services/assets.ts b/packages/mask/src/plugins/Wallet/services/assets.ts index 4d809e618815..8cb0df11296f 100644 --- a/packages/mask/src/plugins/Wallet/services/assets.ts +++ b/packages/mask/src/plugins/Wallet/services/assets.ts @@ -18,6 +18,7 @@ import { getChainShortName, getChainIdFromNetworkType, ERC721TokenCollectionInfo, + isNativeTokenSymbol as isNativeToken, } from '@masknet/web3-shared-evm' import BigNumber from 'bignumber.js' import { values } from 'lodash-unified' @@ -180,7 +181,6 @@ function formatAssetsFromZerion( return data.map(({ asset, quantity }) => { const balance = leftShift(quantity, asset.decimals).toNumber() const value = (asset as ZerionAsset).price?.value ?? (asset as ZerionCovalentAsset).value ?? 0 - const isNativeToken = (symbol: string) => ['ETH', 'BNB', 'MATIC', 'ARETH', 'AETH'].includes(symbol) return { token: { diff --git a/packages/web3-shared/evm/constants/index.ts b/packages/web3-shared/evm/constants/index.ts index 5d56210fae0a..37a858d8a389 100644 --- a/packages/web3-shared/evm/constants/index.ts +++ b/packages/web3-shared/evm/constants/index.ts @@ -33,7 +33,7 @@ function getEnvConstants(key: string) { } } -export { ZERO_ADDRESS, FAKE_SIGN_PASSWORD, EthereumNameType } from './specific' +export * from './specific' export const getAirdropConstants = transform(Airdrop) export const useAirdropConstants = hookTransform(getAirdropConstants) diff --git a/packages/web3-shared/evm/utils/token.ts b/packages/web3-shared/evm/utils/token.ts index 900a73da3506..863bce1ad8fc 100644 --- a/packages/web3-shared/evm/utils/token.ts +++ b/packages/web3-shared/evm/utils/token.ts @@ -20,6 +20,7 @@ import { import { getChainDetailed, getChainIdFromName } from './chainDetailed' import { formatBalance } from './formatter' import { isSameAddress } from './address' +import CHAINS from '../assets/chains.json' export function createNativeToken(chainId: ChainId): NativeTokenDetailed { const chainDetailed = getChainDetailed(chainId) @@ -34,6 +35,13 @@ export function createNativeToken(chainId: ChainId): NativeTokenDetailed { } } +const NATIVE_TOKEN_SYMBOLS = CHAINS.filter((x) => x.network === 'mainnet' && x.nativeCurrency).map((x) => + x.nativeCurrency.symbol.toLowerCase(), +) +export function isNativeTokenSymbol(symbol: string) { + return NATIVE_TOKEN_SYMBOLS.includes(symbol.toLowerCase()) +} + export function createERC20Token( chainId: ChainId, address: string,