From f8067bf7d220b58f25d09b6d2c01320737cc650c Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 3 Jul 2023 08:20:17 +0200 Subject: [PATCH] Use new hook in forms --- .../MsgForm/MsgClaimRewardsForm.tsx | 22 ++++-------- .../MsgForm/MsgCreateVestingAccountForm.tsx | 32 +++++++---------- .../CreateTxForm/MsgForm/MsgDelegateForm.tsx | 30 +++++++--------- .../MsgForm/MsgRedelegateForm.tsx | 36 ++++++++----------- .../CreateTxForm/MsgForm/MsgSendForm.tsx | 31 +++++++--------- .../MsgForm/MsgSetWithdrawAddressForm.tsx | 22 ++++-------- .../CreateTxForm/MsgForm/MsgTransferForm.tsx | 12 +++---- .../MsgForm/MsgUndelegateForm.tsx | 30 +++++++--------- components/forms/CreateTxForm/index.tsx | 16 ++++----- components/forms/FindMultisigForm.tsx | 19 ++++------ components/forms/MultisigForm.tsx | 19 ++++------ components/forms/TransactionSigning.tsx | 35 ++++++++---------- 12 files changed, 115 insertions(+), 189 deletions(-) diff --git a/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx index f68ffde..88b8580 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx @@ -1,8 +1,7 @@ import { MsgWithdrawDelegatorRewardEncodeObject } from "@cosmjs/stargate"; -import { assert } from "@cosmjs/utils"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; -import { useAppContext } from "../../../../context/AppContext"; +import { useChains } from "../../../../context/ChainsContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; @@ -19,8 +18,7 @@ const MsgClaimRewardsForm = ({ setMsgGetter, deleteMsg, }: MsgClaimRewardsFormProps) => { - const { state } = useAppContext(); - assert(state.chain.addressPrefix, "addressPrefix missing"); + const { chain } = useChains(); const [validatorAddress, setValidatorAddress] = useState(""); const [validatorAddressError, setValidatorAddressError] = useState(""); @@ -30,12 +28,10 @@ const MsgClaimRewardsForm = ({ setValidatorAddressError(""); const isMsgValid = (): boolean => { - assert(state.chain.addressPrefix, "addressPrefix missing"); - - const addressErrorMsg = checkAddress(validatorAddress, state.chain.addressPrefix); + const addressErrorMsg = checkAddress(validatorAddress, chain.addressPrefix); if (addressErrorMsg) { setValidatorAddressError( - `Invalid address for network ${state.chain.chainId}: ${addressErrorMsg}`, + `Invalid address for network ${chain.chainId}: ${addressErrorMsg}`, ); return false; } @@ -55,13 +51,7 @@ const MsgClaimRewardsForm = ({ setMsgGetter({ isMsgValid, msg }); } catch {} - }, [ - delegatorAddress, - setMsgGetter, - state.chain.addressPrefix, - state.chain.chainId, - validatorAddress, - ]); + }, [chain.addressPrefix, chain.chainId, delegatorAddress, setMsgGetter, validatorAddress]); return ( @@ -76,7 +66,7 @@ const MsgClaimRewardsForm = ({ value={validatorAddress} onChange={({ target }) => setValidatorAddress(target.value)} error={validatorAddressError} - placeholder={`E.g. ${exampleAddress(0, state.chain.addressPrefix)}`} + placeholder={`E.g. ${exampleAddress(0, chain.addressPrefix)}`} />