From 69c6cd3f320c1153cb663ccf76b448c7bf2e1af0 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 31 Jan 2023 17:12:18 -0800 Subject: [PATCH] feat: move manual entry logic --- libs/accounts/src/lib/transfer-form.tsx | 91 +++++++++++++++++-------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/libs/accounts/src/lib/transfer-form.tsx b/libs/accounts/src/lib/transfer-form.tsx index 2d91e4f1a..e6200288d 100644 --- a/libs/accounts/src/lib/transfer-form.tsx +++ b/libs/accounts/src/lib/transfer-form.tsx @@ -21,7 +21,9 @@ import { import type { Transfer } from '@vegaprotocol/wallet'; import { normalizeTransfer } from '@vegaprotocol/wallet'; import BigNumber from 'bignumber.js'; +import type { ReactNode } from 'react'; import { useCallback, useMemo, useState } from 'react'; +import type { UseFormSetFocus, UseFormSetValue } from 'react-hook-form'; import { Controller, useForm } from 'react-hook-form'; interface FormFields { @@ -51,13 +53,13 @@ export const TransferForm = ({ feeFactor, submitTransfer, }: TransferFormProps) => { - const [manualAddressEntry, setManualAddressEntry] = useState(false); const { control, register, watch, handleSubmit, setValue, + setFocus, formState: { errors }, } = useForm(); @@ -109,35 +111,33 @@ export const TransferForm = ({ /> - {!manualAddressEntry && pubKeys?.length ? ( - - ) : ( - - )} - + + + {pubKeys?.length && + pubKeys + .filter((pk) => pk !== pubKey) // remove currently selected pubkey + .map((pk) => )} + + } + input={ + + } + /> {errors.toAddress?.message && ( {errors.toAddress.message} @@ -252,3 +252,34 @@ const TransferFee = ({ ); }; + +interface AddressInputProps { + setFocus: UseFormSetFocus; + setValue: UseFormSetValue; + select: ReactNode; + input: ReactNode; +} + +const AddressField = ({ setValue, select, input }: AddressInputProps) => { + const [isInput, setIsInput] = useState(false); + + return ( + <> + {isInput ? input : select} + + + ); +};