From ed98110ae613274dc0211ac8f9dd20d9fe68ef64 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 19 Dec 2023 14:53:04 +0100 Subject: [PATCH] Adapt codebase to CosmJS/cosmjs-types changes --- .../TxMsgCreateVestingAccountDetails.tsx | 2 +- .../TransactionInfo/TxMsgTransferDetails.tsx | 3 ++- .../MsgForm/MsgCreateVestingAccountForm.tsx | 2 +- .../MsgForm/MsgInstantiateContract2Form.tsx | 2 +- .../MsgForm/MsgInstantiateContractForm.tsx | 2 +- .../MsgForm/MsgMigrateContractForm.tsx | 2 +- .../CreateTxForm/MsgForm/MsgTransferForm.tsx | 2 +- lib/dateHelpers.ts | 16 ++++++++-------- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/components/dataViews/TransactionInfo/TxMsgCreateVestingAccountDetails.tsx b/components/dataViews/TransactionInfo/TxMsgCreateVestingAccountDetails.tsx index 6e702fd..18efc7a 100644 --- a/components/dataViews/TransactionInfo/TxMsgCreateVestingAccountDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgCreateVestingAccountDetails.tsx @@ -9,7 +9,7 @@ interface TxMsgCreateVestingAccountDetailsProps { const TxMsgCreateVestingAccountDetails = ({ msgValue }: TxMsgCreateVestingAccountDetailsProps) => { const { chain } = useChains(); - const endTimeDateObj = new Date(msgValue.endTime.multiply(1000).toNumber()); + const endTimeDateObj = new Date(Number(msgValue.endTime * 1000n)); const endTimeDate = endTimeDateObj.toLocaleDateString(); const endTimeHours = endTimeDateObj.toLocaleTimeString().slice(0, -3); diff --git a/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx b/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx index ae2e4fd..0c1df1e 100644 --- a/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx +++ b/components/dataViews/TransactionInfo/TxMsgTransferDetails.tsx @@ -12,7 +12,8 @@ const TxMsgTransferDetails = ({ msgValue }: TxMsgTransferDetailsProps) => { msgValue.token, "Token must be set, same as https://github.com/osmosis-labs/telescope/issues/386", ); - const timeoutDateObj = new Date(msgValue.timeoutTimestamp.divide(1_000_000).toNumber()); + const timeoutMilis = Number(msgValue.timeoutTimestamp / 1_000_000n); + const timeoutDateObj = new Date(timeoutMilis); const timeoutDate = timeoutDateObj.toLocaleDateString(); const timeoutTime = timeoutDateObj.toLocaleTimeString(); diff --git a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx index 3db83b0..f067e54 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgCreateVestingAccountForm.tsx @@ -58,7 +58,7 @@ const MsgCreateVestingAccountForm = ({ return false; } - const timeoutDate = new Date(timestampFromDatetimeLocal(endTime).toNumber()); + const timeoutDate = new Date(Number(timestampFromDatetimeLocal(endTime, "ms"))); if (timeoutDate <= new Date()) { setEndTimeError("End time must be a date in the future"); return false; diff --git a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx index 8e0fbb5..a4d73cc 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContract2Form.tsx @@ -149,7 +149,7 @@ const MsgInstantiateContract2Form = ({ const msgValue = MsgCodecs[MsgTypeUrls.Instantiate2].fromPartial({ sender: fromAddress, - codeId: codeId || 0, + codeId: BigInt(codeId), label, admin: adminAddress, fixMsg: false, diff --git a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx index cb6de40..25d03ec 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgInstantiateContractForm.tsx @@ -127,7 +127,7 @@ const MsgInstantiateContractForm = ({ const msgValue = MsgCodecs[MsgTypeUrls.Instantiate].fromPartial({ sender: fromAddress, - codeId: codeId || 1, + codeId: BigInt(codeId), label, admin: adminAddress, msg: msgContentUtf8Array, diff --git a/components/forms/CreateTxForm/MsgForm/MsgMigrateContractForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgMigrateContractForm.tsx index cf88534..b0e7755 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgMigrateContractForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgMigrateContractForm.tsx @@ -72,7 +72,7 @@ const MsgMigrateContractForm = ({ const msgValue = MsgCodecs[MsgTypeUrls.Migrate].fromPartial({ sender: fromAddress, contract: contractAddress, - codeId: codeId || 1, + codeId: BigInt(codeId), msg: msgContentUtf8Array, }); diff --git a/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx b/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx index 6142803..6c89d34 100644 --- a/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx +++ b/components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx @@ -97,7 +97,7 @@ const MsgTransferForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgTransferFo return false; } - const timeoutDate = new Date(timestampFromDatetimeLocal(timeout).toNumber()); + const timeoutDate = new Date(Number(timestampFromDatetimeLocal(timeout, "ms"))); if (timeoutDate <= new Date()) { setTimeoutError("Timeout must be a date in the future"); return false; diff --git a/lib/dateHelpers.ts b/lib/dateHelpers.ts index 311a9f9..855f707 100644 --- a/lib/dateHelpers.ts +++ b/lib/dateHelpers.ts @@ -1,9 +1,7 @@ -import Long from "long"; - export const timestampFromDatetimeLocal = ( datetimeLocal: string, - units?: "s" | "ms" | "ns", -): Long => { + units: "s" | "ms" | "ns", +): bigint => { const [date, time] = datetimeLocal.split("T"); const [year, month, day] = date.split("-"); const [hours, minutes] = time.split(":"); @@ -16,15 +14,17 @@ export const timestampFromDatetimeLocal = ( Number(minutes), ); - const timestampMillis = Long.fromNumber(dateObj.getTime()); + const timestampMillis = BigInt(dateObj.getTime()); switch (units) { case "s": - return timestampMillis.divide(1000); // seconds + return timestampMillis / 1000n; // seconds case "ns": - return timestampMillis.multiply(1000_000); // nanoseconds - default: + return timestampMillis * 1000_000n; // nanoseconds + case "ms": return timestampMillis; // milliseconds + default: + throw new Error("Unexpected unit value"); } };