/* eslint-disable react/no-array-index-key */ import type { LiFiStep, TokenAmount } from '@lifi/sdk'; import type { BoxProps } from '@mui/material'; import { Box, Grow, Skeleton, Tooltip } from '@mui/material'; import type { FC, PropsWithChildren, ReactElement } from 'react'; import { useTranslation } from 'react-i18next'; import { useChain } from '../../hooks/useChain.js'; import { useToken } from '../../hooks/useToken.js'; import { formatTokenAmount, formatTokenPrice } from '../../utils/format.js'; import { AvatarBadgedSkeleton } from '../Avatar/Avatar.js'; import { TokenAvatar } from '../Avatar/TokenAvatar.js'; import { SmallAvatar } from '../SmallAvatar.js'; import { TextFitter } from '../TextFitter/TextFitter.js'; import { TextSecondary, TextSecondaryContainer } from './Token.style.js'; interface TokenProps { token: TokenAmount; impactToken?: TokenAmount; enableImpactTokenTooltip?: boolean; step?: LiFiStep; stepVisible?: boolean; disableDescription?: boolean; isLoading?: boolean; isFromRoute?: boolean; routePriceImpact?: number; } export const Token: FC = ({ token, ...other }) => { if (!token.priceUSD || !token.logoURI) { return ; } return ; }; export const TokenFallback: FC = ({ token, isLoading, ...other }) => { const { token: chainToken, isLoading: isLoadingToken } = useToken( token.chainId, token.address, ); return ( ); }; export const TokenBase: FC = ({ token, impactToken, enableImpactTokenTooltip, step, stepVisible, disableDescription, isLoading, isFromRoute, routePriceImpact, ...other }) => { const { t, i18n } = useTranslation(); const { chain } = useChain(token?.chainId); if (isLoading) { return ( ); } const tokenAmount = formatTokenAmount(token.amount, token.decimals); const tokenPrice = formatTokenPrice(tokenAmount, token.priceUSD); let priceImpact; let priceImpactPercent; if ( impactToken && !['MVM', 'TVM', 'ECLIPSE'].includes((chain as any)?.chainType) ) { const impactTokenAmount = formatTokenAmount( impactToken.amount, impactToken.decimals, ); const impactTokenPrice = formatTokenPrice(impactTokenAmount, impactToken.priceUSD) || 0.01; priceImpact = tokenPrice / impactTokenPrice - 1; priceImpactPercent = priceImpact * 100; } else { priceImpact = routePriceImpact; priceImpactPercent = priceImpact * 100; } const tokenOnChain = !disableDescription ? ( {t(`main.tokenOnChain`, { tokenSymbol: token.symbol, chainName: chain?.name, })} ) : null; return ( {t('format.number', { value: tokenAmount, })} {t(`format.currency`, { value: tokenPrice, })} {impactToken ? ( ) : null} {impactToken ? ( enableImpactTokenTooltip ? ( {t('format.percent', { value: priceImpact })} ) : ( {t('format.percent', { value: priceImpact })} ) ) : null} {!disableDescription ? ( ) : null} {step ? ( {tokenOnChain} ) : ( tokenOnChain )} ); }; const TokenStep: FC>> = ({ step, stepVisible, disableDescription, children, }) => { return ( {children as ReactElement} {step?.toolDetails.name[0]} {step?.toolDetails.name} ); }; export const TokenSkeleton: FC & BoxProps> = ({ step, disableDescription, ...other }) => { return ( {!step && !disableDescription ? ( ) : null} ); };