diff --git a/components/Sequence.tsx b/components/Sequence.tsx new file mode 100644 index 0000000..0d0b189 --- /dev/null +++ b/components/Sequence.tsx @@ -0,0 +1,71 @@ +import { FC, useCallback, useState } from 'react' +import state from '../state' +import { Flex, Input, Button } from '.' +import fetchAccountInfo from '../utils/accountInfo' +import { useSnapshot } from 'valtio' + +interface AccountSequenceProps { + address?: string +} +const AccountSequence: FC = ({ address }) => { + const { accounts } = useSnapshot(state) + const account = accounts.find(acc => acc.address === address) + const [isLoading, setIsLoading] = useState(false) + const setSequence = useCallback( + (sequence: number) => { + const acc = state.accounts.find(acc => acc.address == address) + if (!acc) return + acc.sequence = sequence + }, + [address] + ) + const handleUpdateSequence = useCallback( + async (silent?: boolean) => { + if (!account) return + setIsLoading(true) + + const info = await fetchAccountInfo(account.address, { silent }) + if (info) { + setSequence(info.Sequence) + } + + setIsLoading(false) + }, + [account, setSequence] + ) + const disabled = !account + return ( + + + + + ) +} + +export default AccountSequence diff --git a/components/SetHookDialog.tsx b/components/SetHookDialog.tsx index 28c85a0..b10d524 100644 --- a/components/SetHookDialog.tsx +++ b/components/SetHookDialog.tsx @@ -21,6 +21,7 @@ import { prepareDeployHookTx, sha256 } from '../state/actions/deployHook' import estimateFee from '../utils/estimateFee' import { getParameters, getInvokeOptions, transactionOptions, SetHookData } from '../utils/setHook' import { capitalize } from '../utils/helpers' +import AccountSequence from './Sequence' export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo( ({ accountAddress }) => { @@ -190,6 +191,10 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo( onChange={(acc: any) => setSelectedAccount(acc)} /> + + + + | undefined) => TransactionState | undefined @@ -161,6 +162,9 @@ export const TxUI: FC = ({ onChange={(acc: any) => handleSetAccount(acc)} // TODO make react-select have correct types for acc /> + + + {richFields.includes('Destination') && ( => { + try { + const res = await xrplSend({ + id: `hooks-builder-req-info-${address}`, + command: 'account_info', + account: address + }) + return res.account_data; + } catch (err) { + if (!opts.silent) { + console.error(err) + toast.error('Could not fetch account info!') + } + } +} + +export default fetchAccountInfo