From e5e42849a62aaf45f35cca516b43b4a0e24abe4a Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 12 Dec 2023 07:11:52 +0100 Subject: [PATCH 1/3] feat: convert param only if needed --- packages/ledger-icp/src/index.canister.ts | 6 +++--- packages/ledger-icp/src/utils/params.utils.ts | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/ledger-icp/src/index.canister.ts b/packages/ledger-icp/src/index.canister.ts index b5de9740b..eff8fe999 100644 --- a/packages/ledger-icp/src/index.canister.ts +++ b/packages/ledger-icp/src/index.canister.ts @@ -14,7 +14,7 @@ import { MAINNET_INDEX_CANISTER_ID } from "./constants/canister_ids"; import { IndexError } from "./errors/index.errors"; import type { GetTransactionsParams } from "./types/index.params"; import type { AccountBalanceParams } from "./types/ledger.params"; -import { paramToAccountIdentifier } from "./utils/params.utils"; +import { paramToAccountIdentifierHex } from "./utils/params.utils"; export class IndexCanister extends Canister { static create({ @@ -47,7 +47,7 @@ export class IndexCanister extends Canister { accountIdentifier, }: AccountBalanceParams): Promise => this.caller({ certified }).get_account_identifier_balance( - paramToAccountIdentifier(accountIdentifier).toHex(), + paramToAccountIdentifierHex(accountIdentifier), ); /** @@ -70,7 +70,7 @@ export class IndexCanister extends Canister { const response = await this.caller({ certified, }).get_account_identifier_transactions({ - account_identifier: paramToAccountIdentifier(accountIdentifier).toHex(), + account_identifier: paramToAccountIdentifierHex(accountIdentifier), start: toNullable(start), max_results, }); diff --git a/packages/ledger-icp/src/utils/params.utils.ts b/packages/ledger-icp/src/utils/params.utils.ts index c8e85652d..bac8e345e 100644 --- a/packages/ledger-icp/src/utils/params.utils.ts +++ b/packages/ledger-icp/src/utils/params.utils.ts @@ -1,7 +1,13 @@ import { AccountIdentifier } from "../account_identifier"; +import type { AccountIdentifierHex } from "../types/common"; import type { AccountIdentifierParam } from "../types/ledger.params"; export const paramToAccountIdentifier = ( param: AccountIdentifierParam, ): AccountIdentifier => param instanceof AccountIdentifier ? param : AccountIdentifier.fromHex(param); + +export const paramToAccountIdentifierHex = ( + param: AccountIdentifierParam, +): AccountIdentifierHex => + param instanceof AccountIdentifier ? param.toHex() : param; From ff4936790c5154293430ad24be0a04f8f97d4848 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 12 Dec 2023 07:15:21 +0100 Subject: [PATCH 2/3] docs: fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4181f901f..0d4287f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ - Add a new type TokenAmountV2 which supports `decimals !== 8`. - Fix issue when converting token amount from small numbers with `TokenAmountV2`. +## Fix + +- Utilize ICP Index `accountBalance` and `getTransactions` with account identifier hex directly, eliminating the need for conversion with Buffer and resolving usage in non-polyfilled environments. + ## Operations - Add a cron job to periodically update IC candid files and typescript bindings. From 67976bfb3666d8f77b4d450977072660119215a0 Mon Sep 17 00:00:00 2001 From: Formatting Committer Date: Tue, 12 Dec 2023 06:18:07 +0000 Subject: [PATCH 3/3] Updating formatting --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d4287f95..5989c6fc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ ## Fix -- Utilize ICP Index `accountBalance` and `getTransactions` with account identifier hex directly, eliminating the need for conversion with Buffer and resolving usage in non-polyfilled environments. +- Utilize ICP Index `accountBalance` and `getTransactions` with account identifier hex directly, eliminating the need for conversion with Buffer and resolving usage in non-polyfilled environments. ## Operations