import type { TokenAmount } from '@lifi/sdk' import SwapVertIcon from '@mui/icons-material/SwapVert' import { FormHelperText, Skeleton, Typography } from '@mui/material' import { memo } from 'react' import { useTranslation } from 'react-i18next' import { useTokenAddressBalance } from '../../hooks/useTokenAddressBalance.js' import type { FormTypeProps } from '../../stores/form/types.js' import { FormKeyHelper } from '../../stores/form/types.js' import { useFieldValues } from '../../stores/form/useFieldValues.js' import { useInputModeStore } from '../../stores/inputMode/useInputModeStore.js' import { formatTokenAmount, formatTokenPrice } from '../../utils/format.js' import { InputPriceButton } from './PriceFormHelperText.style.js' export const PriceFormHelperText = memo(({ formType }) => { const [chainId, tokenAddress] = useFieldValues( FormKeyHelper.getChainKey(formType), FormKeyHelper.getTokenKey(formType) ) const { token, isLoading } = useTokenAddressBalance(chainId, tokenAddress) return ( ) }) const PriceFormHelperTextBase: React.FC< FormTypeProps & { isLoading?: boolean tokenAddress?: string token?: TokenAmount } > = ({ formType, isLoading, tokenAddress, token }) => { const { t } = useTranslation() const [amount] = useFieldValues(FormKeyHelper.getAmountKey(formType)) const { inputMode, toggleInputMode } = useInputModeStore() const currentInputMode = inputMode[formType] const tokenAmount = token ? formatTokenAmount(token.amount, token.decimals) : '0' const getPriceAmountDisplayValue = () => { if (currentInputMode === 'amount') { const tokenPrice = formatTokenPrice( amount, token?.priceUSD, token?.decimals ) return t('format.currency', { value: tokenPrice }) } else { return t('format.tokenAmount', { value: amount || '0' }) } } const handleToggleMode = (e: React.MouseEvent) => { e.stopPropagation() toggleInputMode(formType) } return ( {getPriceAmountDisplayValue()} {currentInputMode === 'price' && token?.symbol ? ( {token.symbol} ) : null} {token?.priceUSD && } {isLoading && tokenAddress ? ( ) : token?.amount ? ( {`/ ${t('format.tokenAmount', { value: tokenAmount, })}`} ) : null} ) }