diff --git a/src/app/components/Tokens/TokenList.tsx b/src/app/components/Tokens/TokenList.tsx index acbd8f03db..149861f488 100644 --- a/src/app/components/Tokens/TokenList.tsx +++ b/src/app/components/Tokens/TokenList.tsx @@ -7,12 +7,8 @@ import { TokenLink } from './TokenLink' import { CopyToClipboard } from '../CopyToClipboard' import { VerificationIcon, verificationIconBoxHeight } from '../ContractVerificationIcon' import Box from '@mui/material/Box' -import { - getTokenTypeDescription, - getTokenTypeStrictName, - tokenBackgroundColor, - tokenBorderColor, -} from '../../../types/tokens' +import { tokenBackgroundColor, tokenBorderColor } from '../../../types/tokens' +import { getTokenTypeDescription, getTokenTypeStrictName } from '../../utils/tokens' import { SearchScope } from '../../../types/searchScope' import { FC } from 'react' import Typography from '@mui/material/Typography' diff --git a/src/app/pages/RuntimeAccountDetailsPage/AccountTokensCard.tsx b/src/app/pages/RuntimeAccountDetailsPage/AccountTokensCard.tsx index c590525884..6acdaea6b2 100644 --- a/src/app/pages/RuntimeAccountDetailsPage/AccountTokensCard.tsx +++ b/src/app/pages/RuntimeAccountDetailsPage/AccountTokensCard.tsx @@ -17,7 +17,7 @@ import { getTokenTypePluralDescription, getTokenTypePluralName, getTokenTypeStrictName, -} from '../../../types/tokens' +} from '../../utils/tokens' import { SearchScope } from '../../../types/searchScope' import { RuntimeAccountDetailsContext } from './index' import { getPreciseNumberFormat } from '../../../locales/getPreciseNumberFormat' diff --git a/src/app/pages/RuntimeAccountDetailsPage/index.tsx b/src/app/pages/RuntimeAccountDetailsPage/index.tsx index 5be7ef5025..831d2ba297 100644 --- a/src/app/pages/RuntimeAccountDetailsPage/index.tsx +++ b/src/app/pages/RuntimeAccountDetailsPage/index.tsx @@ -11,7 +11,7 @@ import { useRequiredScopeParam } from '../../hooks/useScopeParam' import { contractCodeContainerId } from './ContractCodeCard' import { useTokenInfo } from '../TokenDashboardPage/hook' import { accountTokenTransfersContainerId } from './AccountTokenTransfersCard' -import { getTokenTypePluralName } from '../../../types/tokens' +import { getTokenTypePluralName } from '../../utils/tokens' import { SearchScope } from '../../../types/searchScope' import { RuntimeAccountDetailsCard } from './RuntimeAccountDetailsCard' import { eventsContainerId } from './AccountEventsCard' diff --git a/src/app/pages/TokenDashboardPage/TokenTypeCard.tsx b/src/app/pages/TokenDashboardPage/TokenTypeCard.tsx index e0fce99775..ca654a93e5 100644 --- a/src/app/pages/TokenDashboardPage/TokenTypeCard.tsx +++ b/src/app/pages/TokenDashboardPage/TokenTypeCard.tsx @@ -6,7 +6,7 @@ import { SnapshotCard } from '../../components/Snapshots/SnapshotCard' import { COLORS } from '../../../styles/theme/colors' import { useTokenInfo } from './hook' import Skeleton from '@mui/material/Skeleton' -import { getTokenTypeDescription, getTokenTypeStrictName } from '../../../types/tokens' +import { getTokenTypeDescription, getTokenTypeStrictName } from '../../utils/tokens' import { SearchScope } from '../../../types/searchScope' export const TokenTypeCard: FC<{ scope: SearchScope; address: string }> = ({ scope, address }) => { diff --git a/src/app/utils/tokens.ts b/src/app/utils/tokens.ts index 5d75f285d8..28632a40f5 100644 --- a/src/app/utils/tokens.ts +++ b/src/app/utils/tokens.ts @@ -1,3 +1,7 @@ +import { TFunction } from 'i18next' +import { exhaustedTypeWarning } from '../../types/errors' +import { EvmTokenType } from 'oasis-nexus/api' + export const getTokenMarketCap = ( relativeTotalValue: number | undefined, rosePriceInUsd: number | undefined, @@ -10,3 +14,49 @@ export const getTokenMarketCap = ( const totalValueInUsd = totalValueInWRose * rosePriceInUsd return totalValueInUsd } + +export const getTokenTypeDescription = (t: TFunction, tokenType: EvmTokenType | undefined): string => { + switch (tokenType ?? 'missing') { + case 'missing': + return t('common.missing') + case 'ERC20': + return t('common.token') + case 'ERC721': + return t('common.nft') + default: + exhaustedTypeWarning('Unknown token type', tokenType as any) + return '???' + } +} + +export const getTokenTypePluralDescription = (t: TFunction, tokenType: EvmTokenType): string => { + switch (tokenType) { + case 'ERC20': + return t('common.tokens') + case 'ERC721': + return t('common.nfts') + default: + exhaustedTypeWarning('Unknown token type', tokenType) + return '???' + } +} + +export const getTokenTypeStrictName = (t: TFunction, tokenType: EvmTokenType | 'missing'): string => { + switch (tokenType) { + case 'missing': + return t('common.missing') + case 'ERC20': + return t('account.ERC20') + case 'ERC721': + return t('account.ERC721') + default: + exhaustedTypeWarning('Unknown token type', tokenType) + return tokenType + } +} + +export const getTokenTypePluralName = (t: TFunction, tokenType: EvmTokenType): string => + t('tokens.typeDescription', { + spec: getTokenTypeStrictName(t, tokenType), + description: getTokenTypePluralDescription(t, tokenType), + }) diff --git a/src/types/tokens.ts b/src/types/tokens.ts index 40b463967e..f9f14e00c6 100644 --- a/src/types/tokens.ts +++ b/src/types/tokens.ts @@ -1,22 +1,6 @@ import { EvmTokenType } from '../oasis-nexus/api' -import { TFunction } from 'i18next' -import { exhaustedTypeWarning } from './errors' import { COLORS } from '../styles/theme/colors' -export const getTokenTypeDescription = (t: TFunction, tokenType: EvmTokenType | undefined): string => { - switch (tokenType ?? 'missing') { - case 'missing': - return t('common.missing') - case 'ERC20': - return t('common.token') - case 'ERC721': - return t('common.nft') - default: - exhaustedTypeWarning('Unknown token type', tokenType as any) - return '???' - } -} - export const tokenBackgroundColor: Record = { missing: COLORS.errorIndicatorBackground, ERC20: COLORS.brandMedium15, @@ -28,35 +12,3 @@ export const tokenBorderColor: Record = { ERC20: COLORS.brandMedium, ERC721: COLORS.pink, } - -export const getTokenTypePluralDescription = (t: TFunction, tokenType: EvmTokenType): string => { - switch (tokenType) { - case 'ERC20': - return t('common.tokens') - case 'ERC721': - return t('common.nfts') - default: - exhaustedTypeWarning('Unknown token type', tokenType) - return '???' - } -} - -export const getTokenTypeStrictName = (t: TFunction, tokenType: EvmTokenType | 'missing'): string => { - switch (tokenType) { - case 'missing': - return t('common.missing') - case 'ERC20': - return t('account.ERC20') - case 'ERC721': - return t('account.ERC721') - default: - exhaustedTypeWarning('Unknown token type', tokenType) - return tokenType - } -} - -export const getTokenTypePluralName = (t: TFunction, tokenType: EvmTokenType): string => - t('tokens.typeDescription', { - spec: getTokenTypeStrictName(t, tokenType), - description: getTokenTypePluralDescription(t, tokenType), - })