import type { BoxProps } from '@chakra-ui/react'; import { chakra } from '@chakra-ui/react'; import React from 'react'; import type { TokenInfo } from 'types/api/token'; import { route } from 'nextjs/routes'; import config from 'configs/app'; import { useMultichainContext } from 'lib/contexts/multichain'; import { Skeleton } from 'toolkit/chakra/skeleton'; import { Tooltip } from 'toolkit/chakra/tooltip'; import { TruncatedTextTooltip } from 'toolkit/components/truncation/TruncatedTextTooltip'; import * as EntityBase from 'ui/shared/entities/base/components'; import getChainTooltipText from 'ui/shared/externalChains/getChainTooltipText'; import IconSvg from 'ui/shared/IconSvg'; import TokenLogoPlaceholder from 'ui/shared/TokenLogoPlaceholder'; import { distributeEntityProps, getIconProps } from '../base/utils'; type LinkProps = EntityBase.LinkBaseProps & Pick; const Link = chakra((props: LinkProps) => { const defaultHref = route( { pathname: '/token/[hash]', query: { ...props.query, hash: props.token.address_hash } }, { chain: props.chain, external: props.external }, ); return ( { props.children } ); }); type IconProps = Pick & EntityBase.IconBaseProps; const Icon = (props: IconProps) => { if (props.noIcon) { return null; } const styles = { ...getIconProps(props, Boolean(props.shield ?? props.chain)), borderRadius: props.token.type === 'ERC-20' ? 'full' : 'base', }; const shield = (() => { if ('shield' in props) { return props.shield; } if (props.chain) { return props.chain.logo ? { src: props.chain.logo } : { name: 'networks/icon-placeholder' as const }; } })(); return ( } shield={ shield } hint={ props.chain && props.shield !== false ? getChainTooltipText(props.chain, 'Token on ') : undefined } { ...props } /> ); }; type ContentProps = Omit & Pick; const Content = chakra((props: ContentProps) => { const nameString = [ !props.onlySymbol && (props.token.name ?? 'Unnamed token'), props.onlySymbol && (props.token.symbol ?? props.token.name ?? 'Unnamed token'), props.token.symbol && props.jointSymbol && !props.onlySymbol && `(${ props.token.symbol })`, ].filter(Boolean).join(' '); return ( ); }); type SymbolProps = Pick; const Symbol = (props: SymbolProps) => { const symbol = props.token.symbol; if (!symbol || props.noSymbol || props.jointSymbol || props.onlySymbol) { return null; } return (
(
{ symbol }
)
); }; type CopyProps = Omit & Pick; const Copy = (props: CopyProps) => { return ( ); }; const Container = EntityBase.Container; interface ReputationProps extends BoxProps { value: TokenInfo['reputation']; } const Reputation = ({ value, ...rest }: ReputationProps) => { if (config.UI.views.token.hideScamTokensEnabled && value === 'scam') { return ( ); } return null; }; export interface EntityProps extends EntityBase.EntityBaseProps { token: Pick; noSymbol?: boolean; jointSymbol?: boolean; onlySymbol?: boolean; } const TokenEntity = (props: EntityProps) => { const multichainContext = useMultichainContext(); const partsProps = distributeEntityProps(props, multichainContext); const content = ; return ( { props.noLink ? content : { content } } ); }; export default React.memo(chakra(TokenEntity)); export { Container, Link, Icon, Content, Copy, Reputation, };