diff --git a/CHANGELOG.md b/CHANGELOG.md index 4181f901f..5989c6fc1 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. 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;