diff --git a/packages/ledger-icp/src/icp.spec.ts b/packages/ledger-icp/src/icp.spec.ts deleted file mode 100644 index 0f6078a2..00000000 --- a/packages/ledger-icp/src/icp.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { FromStringToTokenError } from "@dfinity/utils"; -import { describe, expect, it } from "@jest/globals"; -import { ICP } from "./icp"; - -describe("ICP", () => { - it("can be initialized from a whole number string", () => { - expect(ICP.fromString("1")).toEqual(ICP.fromE8s(BigInt(100000000))); - expect(ICP.fromString("1234")).toEqual(ICP.fromE8s(BigInt(123400000000))); - expect(ICP.fromString("000001234")).toEqual( - ICP.fromE8s(BigInt(123400000000)), - ); - expect(ICP.fromString(" 1")).toEqual(ICP.fromE8s(BigInt(100000000))); - expect(ICP.fromString("1,000")).toEqual(ICP.fromE8s(BigInt(100000000000))); - expect(ICP.fromString("1'000")).toEqual(ICP.fromE8s(BigInt(100000000000))); - expect(ICP.fromString("1'000'000")).toEqual( - ICP.fromE8s(BigInt(100000000000000)), - ); - }); - - it("can be initialized from a fractional number string", () => { - expect(ICP.fromString("0.1")).toEqual(ICP.fromE8s(BigInt(10000000))); - expect(ICP.fromString("0.0001")).toEqual(ICP.fromE8s(BigInt(10000))); - expect(ICP.fromString("0.00000001")).toEqual(ICP.fromE8s(BigInt(1))); - expect(ICP.fromString("0.0000000001")).toEqual( - FromStringToTokenError.FractionalMoreThan8Decimals, - ); - expect(ICP.fromString(".01")).toEqual(ICP.fromE8s(BigInt(1000000))); - }); - - it("can be initialized from a mixed string", () => { - expect(ICP.fromString("1.1")).toEqual(ICP.fromE8s(BigInt(110000000))); - expect(ICP.fromString("1.1")).toEqual(ICP.fromE8s(BigInt(110000000))); - expect(ICP.fromString("12,345.00000001")).toEqual( - ICP.fromE8s(BigInt(1234500000001)), - ); - expect(ICP.fromString("12'345.00000001")).toEqual( - ICP.fromE8s(BigInt(1234500000001)), - ); - expect(ICP.fromString("12345.00000001")).toEqual( - ICP.fromE8s(BigInt(1234500000001)), - ); - }); - - it("returns an error on invalid formats", () => { - expect(ICP.fromString("1.1.1")).toBe(FromStringToTokenError.InvalidFormat); - expect(ICP.fromString("a")).toBe(FromStringToTokenError.InvalidFormat); - expect(ICP.fromString("3.a")).toBe(FromStringToTokenError.InvalidFormat); - expect(ICP.fromString("123asdf$#@~!")).toBe( - FromStringToTokenError.InvalidFormat, - ); - }); - - it("rejects negative numbers", () => { - expect(ICP.fromString("-1")).toBe(FromStringToTokenError.InvalidFormat); - }); -}); diff --git a/packages/ledger-icp/src/icp.ts b/packages/ledger-icp/src/icp.ts deleted file mode 100644 index bdf4680d..00000000 --- a/packages/ledger-icp/src/icp.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { ICPTs } from "@dfinity/nns-proto"; -import { - ICPToken, - convertStringToE8s, - type FromStringToTokenError, - type Token, -} from "@dfinity/utils"; -import { importNnsProto } from "./utils/proto.utils"; - -/** - * We don't extend to keep `fromE8s` and `fromString` as backwards compatible. - * @deprecated - */ -export class ICP { - private constructor( - private e8s: bigint, - public token: Token, - ) {} - - public static fromE8s(amount: bigint): ICP { - return new ICP(amount, ICPToken); - } - - /** - * Initialize from a string. Accepted formats: - * - * 1234567.8901 - * 1'234'567.8901 - * 1,234,567.8901 - */ - public static fromString(amount: string): ICP | FromStringToTokenError { - const e8s = convertStringToE8s(amount); - if (typeof e8s === "bigint") { - return new ICP(e8s, ICPToken); - } - return e8s; - } - - public toE8s(): bigint { - return this.e8s; - } - - public async toProto(): Promise { - const { ICPTs: ICPTsConstructor } = await importNnsProto(); - - const proto = new ICPTsConstructor(); - proto.setE8s(this.e8s.toString()); - return proto; - } -} diff --git a/packages/ledger-icp/src/index.ts b/packages/ledger-icp/src/index.ts index 9df81341..4ccf938a 100644 --- a/packages/ledger-icp/src/index.ts +++ b/packages/ledger-icp/src/index.ts @@ -1,6 +1,5 @@ export { AccountIdentifier, SubAccount } from "./account_identifier"; export * from "./errors/ledger.errors"; -export { ICP } from "./icp"; export { LedgerCanister } from "./ledger.canister"; export * from "./types/ledger.options"; export * from "./utils/account_identifier.utils";