-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get balance for Index canister as well
- Loading branch information
1 parent
3515fc2
commit 73ec769
Showing
4 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Canister } from "@dfinity/utils"; | ||
import { toNullable } from "@dfinity/utils/src"; | ||
import type { _SERVICE as IcrcIndexService } from "../candid/icrc1_index"; | ||
import type { | ||
Tokens, | ||
_SERVICE as IcrcLedgerService, | ||
} from "../candid/icrc1_ledger"; | ||
import type { BalanceParams } from "./types/ledger.params"; | ||
|
||
export abstract class IcrcCanister< | ||
T extends IcrcLedgerService | IcrcIndexService | ||
> extends Canister<T> { | ||
|
||
/** | ||
* Returns the balance for a given account provided as owner and with optional subaccount. | ||
* | ||
* @param {BalanceParams} params The parameters to get the balance of an account. | ||
* @returns {Promise<Tokens>} The balance of the given account. | ||
*/ | ||
balance = (params: BalanceParams): Promise<Tokens> => | ||
this.caller({ certified: params.certified }).icrc1_balance_of({ | ||
owner: params.owner, | ||
subaccount: toNullable(params.subaccount), | ||
}); | ||
} |
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