Skip to content

Commit

Permalink
Merge pull request #188 from cosmos/upgrade-cosmjs-0.32
Browse files Browse the repository at this point in the history
Upgrade CosmJS to 0.32
  • Loading branch information
webmaster128 authored Dec 19, 2023
2 parents 2e470df + e310978 commit 6a91080
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const MsgMigrateContractForm = ({
const msgValue = MsgCodecs[MsgTypeUrls.Migrate].fromPartial({
sender: fromAddress,
contract: contractAddress,
codeId: codeId || 1,
codeId: BigInt(codeId),
msg: msgContentUtf8Array,
});

Expand Down
2 changes: 1 addition & 1 deletion components/forms/CreateTxForm/MsgForm/MsgTransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions lib/dateHelpers.ts
Original file line number Diff line number Diff line change
@@ -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(":");
Expand All @@ -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");
}
};

Expand Down
Loading

1 comment on commit 6a91080

@vercel
Copy link

@vercel vercel bot commented on 6a91080 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.