import React from 'react' // import FeatherIcon from 'feather-icons-react' import classNames from 'classnames' import { FieldValues, UseFormRegister, UseFormReturn, UseFormSetValue } from 'react-hook-form' import { Amount, i18nTranslate, Token } from 'src/types' interface TokenAmountInputFlatProps { inputKey: string form: UseFormReturn chainId: number token: Token balance: Amount validate?: { [key: string]: (value: string) => boolean | string } isWalletConnected: boolean t?: i18nTranslate className?: string widthClassName?: string heightClassName?: string inputClassName?: string bgClassName?: string autoComplete?: string } /** * For use in conjunction with react-hook-form. * @param props * @returns */ export const TokenAmountInputFlat: React.FC = (props) => { const { className, widthClassName, heightClassName, inputClassName, form, inputKey, token, chainId, balance, t, validate, autoComplete } = props const { register, setValue, watch } = form const inputVal = watch(inputKey) return (
= 3 && inputVal?.length < 4, 'w-3/5': inputVal?.length >= 4 && inputVal?.length < 5, 'w-4/5': inputVal?.length >= 5 && inputVal?.length < 6, 'w-full': inputVal?.length >= 6 // 'text-xl sm:text-8xl': inputVal?.length >= 12, // 'text-3xl sm:text-10xl': inputVal?.length >= 7 && inputVal?.length < 12, // 'text-10xl': !inputVal || inputVal?.length < 7 })} autoComplete={autoComplete} register={register} inputKey={inputKey} validate={validate} t={t} />
) } TokenAmountInputFlat.defaultProps = { inputClassName: '', bgClassName: 'bg-tertiary' } const InputToken = (props: { className?: string; chainId: number; token: Token }) => { const { token, className } = props if (!token) { return null } return (
{token.symbol}
) } interface InputProps { autoComplete?: string inputKey: string register: UseFormRegister validate: { [key: string]: (value: string) => boolean | string } t?: i18nTranslate className?: string fontSizeClassName?: string } const Input = (props: InputProps) => { const { autoComplete, fontSizeClassName, className, register, inputKey, validate, t } = props const pattern = { value: /^\d*\.?\d*$/, message: t?.('pleaseEnterAPositiveNumber') || 'Please enter a positive number' } return ( ) } Input.defaultProps = { fontSizeClassName: 'text-xl xs:text-2xl' } const MaxButton: React.FC<{ t?: i18nTranslate setValue: UseFormSetValue balance: Amount inputKey: string token: Token }> = (props) => { const { t, inputKey, setValue, balance } = props const disabled = !balance || balance.amountUnformatted.isZero() return (
Balance: {balance?.amountPretty || 0}
) }