From 2f53a34c058aa5d231a21e5eca7bc41891948fb5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 13 Jun 2023 18:22:45 +0200 Subject: [PATCH] Use cosmjs-types types consistently --- .../TransactionInfo/TxMsgDelegateDetails.tsx | 2 + .../TxMsgRedelegateDetails.tsx | 2 + .../TransactionInfo/TxMsgTransferDetails.tsx | 2 + .../TxMsgUndelegateDetails.tsx | 2 + types/txMsg.ts | 56 +++++-------------- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/components/dataViews/TransactionInfo/TxMsgDelegateDetails.tsx b/components/dataViews/TransactionInfo/TxMsgDelegateDetails.tsx index a2b6102..96199a4 100644 --- a/components/dataViews/TransactionInfo/TxMsgDelegateDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgDelegateDetails.tsx @@ -1,3 +1,4 @@ +import { assert } from "@cosmjs/utils"; import { useAppContext } from "../../../context/AppContext"; import { printableCoin } from "../../../lib/displayHelpers"; import { TxMsgDelegate } from "../../../types/txMsg"; @@ -9,6 +10,7 @@ interface TxMsgDelegateDetailsProps { const TxMsgDelegateDetails = ({ msg }: TxMsgDelegateDetailsProps) => { const { state } = useAppContext(); + assert(msg.value.amount, "Amount must be set, see https://github.com/osmosis-labs/telescope/issues/386"); return ( <> diff --git a/components/dataViews/TransactionInfo/TxMsgRedelegateDetails.tsx b/components/dataViews/TransactionInfo/TxMsgRedelegateDetails.tsx index 9f8c0c2..7b2bdf3 100644 --- a/components/dataViews/TransactionInfo/TxMsgRedelegateDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgRedelegateDetails.tsx @@ -1,3 +1,4 @@ +import { assert } from "@cosmjs/utils"; import { useAppContext } from "../../../context/AppContext"; import { printableCoin } from "../../../lib/displayHelpers"; import { TxMsgRedelegate } from "../../../types/txMsg"; @@ -9,6 +10,7 @@ interface TxMsgRedelegateDetailsProps { const TxMsgRedelegateDetails = ({ msg }: TxMsgRedelegateDetailsProps) => { const { state } = useAppContext(); + assert(msg.value.amount, "Amount must be set, same as https://github.com/osmosis-labs/telescope/issues/386"); return ( <> diff --git a/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx b/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx index e79577e..ef8c546 100644 --- a/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx @@ -1,3 +1,4 @@ +import { assert } from "@cosmjs/utils"; import { thinSpace } from "../../../lib/displayHelpers"; import { TxMsgTransfer } from "../../../types/txMsg"; import HashView from "../HashView"; @@ -7,6 +8,7 @@ interface TxMsgTransferDetailsProps { } const TxMsgTransferDetails = ({ msg }: TxMsgTransferDetailsProps) => { + assert(msg.value.token, "Token must be set, same as https://github.com/osmosis-labs/telescope/issues/386"); const timeoutDateObj = new Date(msg.value.timeoutTimestamp.divide(1_000_000).toNumber()); const timeoutDate = timeoutDateObj.toLocaleDateString(); const timeoutTime = timeoutDateObj.toLocaleTimeString(); diff --git a/components/dataViews/TransactionInfo/TxMsgUndelegateDetails.tsx b/components/dataViews/TransactionInfo/TxMsgUndelegateDetails.tsx index 18d233e..69ca7f0 100644 --- a/components/dataViews/TransactionInfo/TxMsgUndelegateDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgUndelegateDetails.tsx @@ -1,3 +1,4 @@ +import { assert } from "@cosmjs/utils"; import { useAppContext } from "../../../context/AppContext"; import { printableCoin } from "../../../lib/displayHelpers"; import { TxMsgUndelegate } from "../../../types/txMsg"; @@ -9,6 +10,7 @@ interface TxMsgUndelegateDetailsProps { const TxMsgUndelegateDetails = ({ msg }: TxMsgUndelegateDetailsProps) => { const { state } = useAppContext(); + assert(msg.value.amount, "Amount must be set, same as https://github.com/osmosis-labs/telescope/issues/386"); return ( <> diff --git a/types/txMsg.ts b/types/txMsg.ts index 11fe8b9..469d6f2 100644 --- a/types/txMsg.ts +++ b/types/txMsg.ts @@ -1,4 +1,7 @@ -import { Coin, MsgTransferEncodeObject } from "@cosmjs/stargate"; +import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; +import { MsgSetWithdrawAddress, MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; +import { MsgBeginRedelegate, MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx"; +import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx"; import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx"; export type MsgType = @@ -23,71 +26,40 @@ export type TxMsg = export interface TxMsgSend { readonly typeUrl: "/cosmos.bank.v1beta1.MsgSend"; - readonly value: { - readonly fromAddress: string; - readonly toAddress: string; - readonly amount: readonly Readonly[]; - }; + readonly value: MsgSend; } export interface TxMsgDelegate { readonly typeUrl: "/cosmos.staking.v1beta1.MsgDelegate"; - readonly value: { - readonly delegatorAddress: string; - readonly validatorAddress: string; - readonly amount: Readonly; - }; + readonly value: MsgDelegate; } export interface TxMsgUndelegate { readonly typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate"; - readonly value: { - readonly delegatorAddress: string; - readonly validatorAddress: string; - readonly amount: Readonly; - }; + readonly value: MsgUndelegate; } export interface TxMsgRedelegate { readonly typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate"; - readonly value: { - readonly delegatorAddress: string; - readonly validatorSrcAddress: string; - readonly validatorDstAddress: string; - readonly amount: Readonly; - }; + readonly value: MsgBeginRedelegate; } export interface TxMsgClaimRewards { readonly typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"; - readonly value: { - readonly delegatorAddress: string; - readonly validatorAddress: string; - }; + readonly value: MsgWithdrawDelegatorReward; } export interface TxMsgSetWithdrawAddress { readonly typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress"; - readonly value: { - readonly delegatorAddress: string; - readonly withdrawAddress: string; - }; + readonly value: MsgSetWithdrawAddress; } export interface TxMsgCreateVestingAccount { readonly typeUrl: "/cosmos.vesting.v1beta1.MsgCreateVestingAccount"; - readonly value: { - readonly fromAddress: string; - readonly toAddress: string; - readonly amount: readonly Readonly[]; - readonly endTime: Long; - readonly delayed: boolean; - }; + readonly value: MsgCreateVestingAccount; } -type OmmitedMsgTransfer = Omit; -type MsgTransferRequiredToken = OmmitedMsgTransfer & Required>; - -export interface TxMsgTransfer extends MsgTransferEncodeObject { - readonly value: Readonly; +export interface TxMsgTransfer { + readonly typeUrl: "/ibc.applications.transfer.v1.MsgTransfer"; + readonly value: MsgTransfer; }