-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebf7194
commit 5d4b7e6
Showing
8 changed files
with
173 additions
and
1,613 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { useIbcChainSelection } from "./hooks/useIbcChainSelection"; | ||
import { sendIbcTransfer } from "./services/ibc"; | ||
import { padDecimal } from "./utils/utils"; | ||
|
||
export { padDecimal, sendIbcTransfer, useIbcChainSelection }; | ||
export { sendIbcTransfer, useIbcChainSelection }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,35 @@ | ||
import { padDecimal } from "./utils"; // adjust import path as needed | ||
import { nowPlusMinutesInNano } from "./utils"; | ||
|
||
describe("padDecimal", () => { | ||
test("adds leading zero to strings starting with decimal point", () => { | ||
expect(padDecimal(".5")).toBe("0.5"); | ||
expect(padDecimal(".123")).toBe("0.123"); | ||
expect(padDecimal(".0")).toBe("0.0"); | ||
describe("nowPlusMinutesInNano", () => { | ||
beforeEach(() => { | ||
jest.spyOn(Date, "now").mockImplementation(() => 1600000000000); // 2020-09-13T12:26:40.000Z | ||
}); | ||
|
||
test("does not modify strings that do not start with decimal point", () => { | ||
expect(padDecimal("1.5")).toBe("1.5"); | ||
expect(padDecimal("10.123")).toBe("10.123"); | ||
expect(padDecimal("0.5")).toBe("0.5"); | ||
expect(padDecimal("123")).toBe("123"); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
test("handles edge cases", () => { | ||
// Empty string | ||
expect(padDecimal("")).toBe(""); | ||
test("converts 5 minutes to expected nanoseconds from now", () => { | ||
const result = nowPlusMinutesInNano(5); | ||
|
||
// Just a decimal point | ||
expect(padDecimal(".")).toBe("0."); | ||
// assert the result is a BigInt | ||
expect(typeof result).toBe("bigint"); | ||
|
||
// Multiple decimal points | ||
expect(padDecimal(".1.2")).toBe("0.1.2"); | ||
|
||
// Leading zeros | ||
expect(padDecimal("00.5")).toBe("00.5"); | ||
|
||
// Negative numbers | ||
expect(padDecimal("-.5")).toBe("-.5"); | ||
expect(padDecimal("-0.5")).toBe("-0.5"); | ||
// convert result back to milliseconds and check the time difference | ||
const resultInMs = Number(result / BigInt(1_000_000)); | ||
const expectedMs = Date.now() + 5 * 60 * 1000; | ||
expect(resultInMs).toBe(expectedMs); | ||
}); | ||
|
||
test("preserves string format without modifying actual numbers", () => { | ||
// Scientific notation | ||
expect(padDecimal("1e-10")).toBe("1e-10"); | ||
|
||
// Very long decimals | ||
expect(padDecimal(".12345678901234567890")).toBe("0.12345678901234567890"); | ||
test("maintains millisecond precision when converting to nanoseconds", () => { | ||
const result = nowPlusMinutesInNano(1); | ||
// check that the last 6 digits (nanosecond portion) are zeros | ||
expect(result % BigInt(1_000_000)).toBe(BigInt(0)); | ||
}); | ||
|
||
// Trailing zeros | ||
expect(padDecimal(".500")).toBe("0.500"); | ||
test("handles zero minutes", () => { | ||
const result = nowPlusMinutesInNano(0); | ||
const expectedMs = Date.now(); | ||
expect(Number(result / BigInt(1_000_000))).toBe(expectedMs); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/** | ||
* Pad decimal with 0 if it starts with a dot | ||
* @param str | ||
* Returns now plus the given minutes, in nanoseconds | ||
*/ | ||
export function padDecimal(str: string) { | ||
return str.startsWith(".") ? `0${str}` : str; | ||
export function nowPlusMinutesInNano(minutes: number): bigint { | ||
return BigInt(Date.now() + minutes * 60 * 1000) * BigInt(1_000_000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
/// <reference types="react-scripts" /> | ||
import type { Keplr } from "@keplr-wallet/types"; | ||
|
||
declare global { | ||
interface Window { | ||
// window.keplr should be provided by the Keplr extension | ||
keplr?: Keplr; | ||
} | ||
} |