import TokenSelect from './TokenSelect' import NumberFormat, { NumberFormatValues, SourceInfo, } from 'react-number-format' import { formatCurrencyValue } from 'utils/numbers' import { useTranslation } from 'react-i18next' import { Dispatch, SetStateAction, useMemo } from 'react' import mangoStore from '@store/mangoStore' import useMangoGroup from 'hooks/useMangoGroup' import { INPUT_TOKEN_DEFAULT } from 'utils/constants' import { NUMBER_FORMAT_CLASSNAMES, withValueLimit } from './MarketSwapForm' import MaxSwapAmount from './MaxSwapAmount' import useUnownedAccount from 'hooks/useUnownedAccount' import InlineNotification from '@components/shared/InlineNotification' import useMangoAccount from 'hooks/useMangoAccount' import { toUiDecimalsForQuote } from '@blockworks-foundation/mango-v4' const SellTokenInput = ({ handleAmountInChange, setShowTokenSelect, handleMax, className, error, isTriggerOrder, }: { handleAmountInChange: (e: NumberFormatValues, info: SourceInfo) => void setShowTokenSelect: Dispatch> handleMax: (amountIn: string) => void className?: string error?: string isTriggerOrder?: boolean }) => { const { t } = useTranslation('common') const { mangoAccountAddress } = useMangoAccount() const { group } = useMangoGroup() const { isUnownedAccount } = useUnownedAccount() const { margin: useMargin, inputBank, amountIn: amountInFormValue, } = mangoStore((s) => s.swap) const freeCollateral = useMemo(() => { const group = mangoStore.getState().group const mangoAccount = mangoStore.getState().mangoAccount.current return group && mangoAccount ? toUiDecimalsForQuote(mangoAccount.getCollateralValue(group)) : 10 }, [mangoAccountAddress]) return (

{t('sell')}

{!isUnownedAccount ? ( handleMax(v)} /> ) : null}
{!isNaN(Number(amountInFormValue)) ? ( {inputBank ? formatCurrencyValue( inputBank.uiPrice * Number(amountInFormValue), ) : '–'} ) : null}
{mangoAccountAddress && freeCollateral <= 0 ? (
) : null} {error ? (
) : null}
) } export default SellTokenInput