Skip to content

Commit

Permalink
Use MsgTransferEncodeObject with Long
Browse files Browse the repository at this point in the history
  • Loading branch information
abefernan committed Jun 5, 2023
1 parent 958b7e8 commit 57ccc9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface TxMsgTransferDetailsProps {
const TxMsgTransferDetails = ({ msg }: TxMsgTransferDetailsProps) => {
const { state } = useAppContext();

const timeoutDateObj = new Date(msg.value.timeoutTimestamp / 1000000);
const timeoutDateObj = new Date(msg.value.timeoutTimestamp.divide(1_000_000).toNumber());
const timeoutDate = timeoutDateObj.toLocaleDateString();
const timeoutTime = timeoutDateObj.toLocaleTimeString();

Expand Down
5 changes: 3 additions & 2 deletions components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assert } from "@cosmjs/utils";
import Long from "long";
import { useEffect, useState } from "react";
import { MsgGetter } from "..";
import { useAppContext } from "../../../../context/AppContext";
Expand Down Expand Up @@ -106,8 +107,8 @@ const MsgTransferForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgTransferFo

const timeoutTimestamp =
selectedTimestamp.label === "custom"
? Number(customTimestamp)
: (Date.now() + selectedTimestamp.value) * 1000000; // In nanoseconds
? Long.fromString(customTimestamp)
: Long.fromNumber(Date.now() + selectedTimestamp.value, true).multiply(1_000_000); // In nanoseconds

const msg: TxMsgTransfer = {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
Expand Down
22 changes: 10 additions & 12 deletions types/txMsg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Coin } from "@cosmjs/amino";
import { MsgTransferEncodeObject } from "@cosmjs/stargate";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";

export type MsgType =
| "send"
Expand Down Expand Up @@ -71,15 +72,12 @@ export interface TxMsgSetWithdrawAddress {
};
}

export interface TxMsgTransfer {
readonly typeUrl: "/ibc.applications.transfer.v1.MsgTransfer";
readonly value: {
readonly sourcePort: string;
readonly sourceChannel: string;
readonly token: Coin;
readonly sender: string;
readonly receiver: string;
readonly timeoutTimestamp: number;
readonly memo: string;
};
type OmmitedMsgTransfer = Omit<MsgTransfer, "timeoutHeight" | "memo">;
type MsgTransferRequiredToken = OmmitedMsgTransfer & Required<Pick<OmmitedMsgTransfer, "token">>;
interface MsgTransferOptionalMemo extends MsgTransferRequiredToken {
readonly memo?: string;
}

export interface TxMsgTransfer extends MsgTransferEncodeObject {
readonly value: Readonly<MsgTransferOptionalMemo>;
}

0 comments on commit 57ccc9b

Please sign in to comment.