/** * Copyright (c) TonTech. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import type { FC, ComponentProps } from 'react'; import { calcFiatValue, formatLargeValue } from '@ton/appkit'; import clsx from 'clsx'; import { useI18n } from '../../../settings/hooks/use-i18n'; import { Input } from '../../../../components/ui/input/input'; import { Skeleton } from '../../../../components/ui/skeleton'; import { TokenSelector } from '../token-selector/token-selector'; import type { AppkitUIToken } from '../../../../types/appkit-ui-token'; import { getDisplayAmount } from '../../utils/get-display-amount'; import styles from './swap-field.module.css'; export interface SwapFieldProps extends Omit, 'children'> { type: 'pay' | 'receive'; amount: string; token?: AppkitUIToken; onAmountChange?: (value: string) => void; balance?: string; isBalanceLoading?: boolean; loading?: boolean; onMaxClick?: () => void; onTokenSelectorClick?: () => void; isWalletConnected?: boolean; fiatSymbol?: string; } export const SwapField: FC = ({ type, token, amount, onAmountChange, balance, isBalanceLoading, loading, onMaxClick, onTokenSelectorClick, isWalletConnected, fiatSymbol = '$', className, ...props }) => { const { t } = useI18n(); const tokenSymbol = token?.symbol; const displayBalance = getDisplayAmount(balance, token?.decimals); return ( {type === 'pay' ? t('swap.pay') : t('swap.receive')} onAmountChange(e.target.value))} disabled={type === 'receive'} />
{token?.rate && `${fiatSymbol} ${formatLargeValue(calcFiatValue(amount || '0', token.rate), 2, 2)}`} {type === 'pay' && token && ( {isBalanceLoading ? ( ) : ( <> )} )} {type === 'receive' && token && ( {isBalanceLoading ? ( ) : ( `${displayBalance} ${tokenSymbol}` )} )}
); };