From 347c6335dfd0b681e29ec5943490ac3659c52ddb Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:24:10 +0200 Subject: [PATCH] Build msgValue with fromPartial() --- .../forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx | 8 +++++--- .../CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx | 7 +++---- components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx | 7 +++---- .../forms/CreateTxForm/MsgForm/MsgRedelegateForm.tsx | 7 +++---- components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx | 7 +++---- .../CreateTxForm/MsgForm/MsgSetWithdrawAddressForm.tsx | 8 +++++--- components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx | 7 +++---- .../forms/CreateTxForm/MsgForm/MsgUndelegateForm.tsx | 7 +++---- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx index 9ada9e5..f68ffde 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgClaimRewardsForm.tsx @@ -1,11 +1,10 @@ import { MsgWithdrawDelegatorRewardEncodeObject } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; -import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -44,7 +43,10 @@ const MsgClaimRewardsForm = ({ return true; }; - const msgValue: MsgWithdrawDelegatorReward = { delegatorAddress, validatorAddress }; + const msgValue = MsgCodecs[MsgTypeUrls.WithdrawDelegatorReward].fromPartial({ + delegatorAddress, + validatorAddress, + }); const msg: MsgWithdrawDelegatorRewardEncodeObject = { typeUrl: MsgTypeUrls.WithdrawDelegatorReward, diff --git a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx index dc8b2d2..c2027b2 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx @@ -1,13 +1,12 @@ import { Decimal } from "@cosmjs/math"; import { EncodeObject } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; -import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { timestampFromDatetimeLocal } from "../../../../lib/dateHelpers"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -95,13 +94,13 @@ const MsgCreateVestingAccountForm = ({ ? Decimal.fromUserInput(amount, Number(state.chain.displayDenomExponent)).atomics : "0"; - const msgValue: MsgCreateVestingAccount = { + const msgValue = MsgCodecs[MsgTypeUrls.CreateVestingAccount].fromPartial({ fromAddress, toAddress, amount: [{ amount: amountInAtomics, denom: state.chain.denom }], endTime: timestampFromDatetimeLocal(endTime), delayed, - }; + }); const msg: EncodeObject = { typeUrl: MsgTypeUrls.CreateVestingAccount, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx index efc7389..88c2afd 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgDelegateForm.tsx @@ -1,12 +1,11 @@ import { Decimal } from "@cosmjs/math"; import { MsgDelegateEncodeObject } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; -import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -57,11 +56,11 @@ const MsgDelegateForm = ({ delegatorAddress, setMsgGetter, deleteMsg }: MsgDeleg Number(state.chain.displayDenomExponent), ).atomics; - const msgValue: MsgDelegate = { + const msgValue = MsgCodecs[MsgTypeUrls.Delegate].fromPartial({ delegatorAddress, validatorAddress, amount: { amount: amountInAtomics, denom: state.chain.denom }, - }; + }); const msg: MsgDelegateEncodeObject = { typeUrl: MsgTypeUrls.Delegate, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgRedelegateForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgRedelegateForm.tsx index 1f74a4b..64ff72d 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgRedelegateForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgRedelegateForm.tsx @@ -1,12 +1,11 @@ import { Decimal } from "@cosmjs/math"; import { EncodeObject } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; -import { MsgBeginRedelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -72,12 +71,12 @@ const MsgRedelegateForm = ({ Number(state.chain.displayDenomExponent), ).atomics; - const msgValue: MsgBeginRedelegate = { + const msgValue = MsgCodecs[MsgTypeUrls.BeginRedelegate].fromPartial({ delegatorAddress, validatorSrcAddress, validatorDstAddress, amount: { amount: amountInAtomics, denom: state.chain.denom }, - }; + }); const msg: EncodeObject = { typeUrl: MsgTypeUrls.BeginRedelegate, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx index 0ce64e3..dda14ff 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgSendForm.tsx @@ -1,12 +1,11 @@ import { Decimal } from "@cosmjs/math"; import { MsgSendEncodeObject } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; -import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -56,11 +55,11 @@ const MsgSendForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgSendFormProps) ? Decimal.fromUserInput(amount, Number(state.chain.displayDenomExponent)).atomics : "0"; - const msgValue: MsgSend = { + const msgValue = MsgCodecs[MsgTypeUrls.Send].fromPartial({ fromAddress, toAddress, amount: [{ amount: amountInAtomics, denom: state.chain.denom }], - }; + }); const msg: MsgSendEncodeObject = { typeUrl: MsgTypeUrls.Send, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgSetWithdrawAddressForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgSetWithdrawAddressForm.tsx index 6d78493..51074c4 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgSetWithdrawAddressForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgSetWithdrawAddressForm.tsx @@ -1,11 +1,10 @@ import { EncodeObject } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; -import { MsgSetWithdrawAddress } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -44,7 +43,10 @@ const MsgSetWithdrawAddressForm = ({ return true; }; - const msgValue: MsgSetWithdrawAddress = { delegatorAddress, withdrawAddress }; + const msgValue = MsgCodecs[MsgTypeUrls.SetWithdrawAddress].fromPartial({ + delegatorAddress, + withdrawAddress, + }); const msg: EncodeObject = { typeUrl: MsgTypeUrls.SetWithdrawAddress, value: msgValue }; setMsgGetter({ isMsgValid, msg }); diff --git a/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx index b0a5d1a..2be611f 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx @@ -1,12 +1,11 @@ import { MsgTransferEncodeObject } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; -import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx"; import Long from "long"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -106,7 +105,7 @@ const MsgTransferForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgTransferFo } })(); - const msgValue: MsgTransfer = { + const msgValue = MsgCodecs[MsgTypeUrls.Transfer].fromPartial({ sender: fromAddress, receiver: toAddress, token: { denom, amount }, @@ -114,7 +113,7 @@ const MsgTransferForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgTransferFo sourceChannel, timeoutTimestamp, memo, - }; + }); const msg: MsgTransferEncodeObject = { typeUrl: MsgTypeUrls.Transfer, value: msgValue }; diff --git a/components/forms/CreateTxForm/MsgForm/MsgUndelegateForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgUndelegateForm.tsx index 0b1f586..890ea4f 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgUndelegateForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgUndelegateForm.tsx @@ -1,12 +1,11 @@ import { Decimal } from "@cosmjs/math"; import { MsgUndelegateEncodeObject } from "@cosmjs/stargate"; import { assert } from "@cosmjs/utils"; -import { MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx"; import { useEffect, useState } from "react"; import { MsgGetter } from ".."; import { useAppContext } from "../../../../context/AppContext"; import { checkAddress, exampleAddress } from "../../../../lib/displayHelpers"; -import { MsgTypeUrls } from "../../../../types/txMsg"; +import { MsgCodecs, MsgTypeUrls } from "../../../../types/txMsg"; import Input from "../../../inputs/Input"; import StackableContainer from "../../../layout/StackableContainer"; @@ -61,11 +60,11 @@ const MsgUndelegateForm = ({ Number(state.chain.displayDenomExponent), ).atomics; - const msgValue: MsgUndelegate = { + const msgValue = MsgCodecs[MsgTypeUrls.Undelegate].fromPartial({ delegatorAddress, validatorAddress, amount: { amount: amountInAtomics, denom: state.chain.denom }, - }; + }); const msg: MsgUndelegateEncodeObject = { typeUrl: MsgTypeUrls.Undelegate, value: msgValue };