import { useRef, useState } from 'react'; import { TextInput, type StyleProp, type ViewStyle } from 'react-native'; import { FlexView, Link, Text, useTheme, TokenButton, Shimmer } from '@reown/appkit-ui-react-native'; import { NumberUtil, type Balance } from '@reown/appkit-common-react-native'; import { SendController } from '@reown/appkit-core-react-native'; import { getMaxAmount, getSendValue } from './utils'; import styles from './styles'; export interface SendInputTokenProps { token?: Balance; sendTokenAmount?: number; style?: StyleProp; onTokenPress?: () => void; loading?: boolean; testID?: string; } export function SendInputToken({ token, sendTokenAmount, style, onTokenPress, loading, testID }: SendInputTokenProps) { const Theme = useTheme(); const valueInputRef = useRef(null); const [inputValue, setInputValue] = useState(sendTokenAmount?.toString()); const sendValue = getSendValue(token, sendTokenAmount); const maxAmount = getMaxAmount(token); const maxError = token && sendTokenAmount && sendTokenAmount > Number(token?.quantity?.numeric); const onInputChange = (value: string) => { const formattedValue = value.replace(/,/g, '.'); if (Number(formattedValue) >= 0 || formattedValue === '') { setInputValue(formattedValue); SendController.setTokenAmount(Number(formattedValue)); } }; const onMaxPress = () => { if (token?.quantity?.numeric) { const maxValue = NumberUtil.bigNumber(token.quantity.numeric); SendController.setTokenAmount(Number(maxValue.toFixed(20))); setInputValue(maxValue.toFixed(20)); valueInputRef.current?.blur(); } }; return loading ? ( ) : ( {token ? ( {sendValue ?? ''} {maxAmount ?? ''} Max ) : null} ); }