import { useEffect, useState } from 'react'; import { ScrollView } from 'react-native'; import { useSnapshot } from 'valtio'; import { ConnectionsController, CoreHelperUtil, RouterController, SendController } from '@reown/appkit-core-react-native'; import { Button, FlexView, IconBox, useCustomDimensions } from '@reown/appkit-ui-react-native'; import { SendInputToken } from '../../partials/w3m-send-input-token'; import { useKeyboard } from '../../hooks/useKeyboard'; import { SendInputAddress } from '../../partials/w3m-send-input-address'; import styles from './styles'; export function WalletSendView() { const { padding, maxHeight } = useCustomDimensions(); const { keyboardShown, keyboardHeight } = useKeyboard(); const [isBalanceLoading, setBalanceLoading] = useState(false); const { token, sendTokenAmount, receiverAddress, receiverProfileName, loading } = useSnapshot( SendController.state ); const onSendPress = () => { RouterController.push('WalletSendPreview'); }; const getActionText = () => { if (!SendController.state.token) { return 'Select token'; } if ( SendController.state.sendTokenAmount && SendController.state.token?.quantity && SendController.state.sendTokenAmount > Number(SendController.state.token.quantity.numeric) ) { return 'Insufficient funds'; } if (!SendController.state.sendTokenAmount) { return 'Add amount'; } if (SendController.state.sendTokenAmount && SendController.state.token?.price) { const value = SendController.state.sendTokenAmount * SendController.state.token.price; if (!value) { return 'Incorrect value'; } } if ( SendController.state.receiverAddress && !CoreHelperUtil.isAddress( SendController.state.receiverAddress, ConnectionsController.state.activeNamespace ) ) { return 'Invalid address'; } if (!SendController.state.receiverAddress) { return 'Add address'; } return 'Preview send'; }; useEffect(() => { async function fetchBalance() { setBalanceLoading(true); await ConnectionsController.fetchBalance(); setBalanceLoading(false); } fetchBalance(); }, []); const actionText = getActionText(); return ( RouterController.push('WalletSendSelectToken')} loading={isBalanceLoading} testID="send-input-token" /> ); }