From 3d3fef240140ebbf0d377368101f4d1f21fb4021 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:24:45 +0200 Subject: [PATCH] Make separate errors for src and dst validatorAddr --- components/forms/ReDelegationForm.tsx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/components/forms/ReDelegationForm.tsx b/components/forms/ReDelegationForm.tsx index 7e04491..7e00671 100644 --- a/components/forms/ReDelegationForm.tsx +++ b/components/forms/ReDelegationForm.tsx @@ -26,7 +26,7 @@ const ReDelegationForm = (props: Props) => { const [gas, setGas] = useState(300000); const [gasPrice, _setGasPrice] = useState(state.chain.gasPrice); const [_processing, setProcessing] = useState(false); - const [addressError, setAddressError] = useState(""); + const [addressErrors, setAddressErrors] = useState({ srcAddress: "", dstAddress: "" }); const createTransaction = ( txValidatorSrcAddress: string, @@ -71,16 +71,16 @@ const ReDelegationForm = (props: Props) => { assert(state.chain.addressPrefix, "addressPrefix missing"); const validatorSrcAddressError = checkAddress(validatorSrcAddress, state.chain.addressPrefix); const validatorDstAddressError = checkAddress(validatorDstAddress, state.chain.addressPrefix); - if (validatorSrcAddressError) { - setAddressError( - `Invalid address for network ${state.chain.chainId}: ${validatorSrcAddressError}`, - ); - return; - } - if (validatorDstAddressError) { - setAddressError( - `Invalid address for network ${state.chain.chainId}: ${validatorDstAddressError}`, - ); + + setAddressErrors({ + srcAddress: validatorSrcAddressError + ? `Invalid address for network ${state.chain.chainId}: ${validatorSrcAddressError}` + : "", + dstAddress: validatorDstAddressError + ? `Invalid address for network ${state.chain.chainId}: ${validatorDstAddressError}` + : "", + }); + if (validatorSrcAddressError || validatorDstAddressError) { return; } @@ -110,7 +110,7 @@ const ReDelegationForm = (props: Props) => { onChange={(e: React.ChangeEvent) => setValidatorSrcAddress(e.target.value) } - error={addressError} + error={addressErrors.srcAddress} placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)}`} /> @@ -122,7 +122,7 @@ const ReDelegationForm = (props: Props) => { onChange={(e: React.ChangeEvent) => setValidatorDstAddress(e.target.value) } - error={addressError} + error={addressErrors.dstAddress} placeholder={`E.g. ${exampleValidatorAddress(1, state.chain.addressPrefix)}`} />