From 7c6186ff47963b8114d30f865049b0160466af92 Mon Sep 17 00:00:00 2001 From: mtyszczak Date: Tue, 3 Sep 2024 11:32:04 +0200 Subject: [PATCH] Add hasWallet method to the TypeScript interface --- .../beekeeper/beekeeper_wasm/src/detailed/session.ts | 10 ++++++++++ programs/beekeeper/beekeeper_wasm/src/interfaces.ts | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/programs/beekeeper/beekeeper_wasm/src/detailed/session.ts b/programs/beekeeper/beekeeper_wasm/src/detailed/session.ts index 161dfb70a7..599380728d 100644 --- a/programs/beekeeper/beekeeper_wasm/src/detailed/session.ts +++ b/programs/beekeeper/beekeeper_wasm/src/detailed/session.ts @@ -7,6 +7,10 @@ interface IBeekeeperWalletPassword { password: string; } +interface IBeekeeperHasWallet { + exists: boolean; +} + interface IBeekeeperWallets { wallets: Array<{ name: string; @@ -45,6 +49,12 @@ export class BeekeeperSession implements IBeekeeperSession { return wallets; } + public hasWallet(name: string): boolean { + const result = this.api.extract(this.api.api.has_wallet(this.token, name) as string) as IBeekeeperHasWallet; + + return result.exists; + } + public async createWallet(name: string, password: string | undefined, isTemporary: boolean = false): Promise { if(typeof password === 'string') this.api.extract(this.api.api.create(this.token, name, password, isTemporary) as string); diff --git a/programs/beekeeper/beekeeper_wasm/src/interfaces.ts b/programs/beekeeper/beekeeper_wasm/src/interfaces.ts index e38a2fd332..bedfa96a36 100644 --- a/programs/beekeeper/beekeeper_wasm/src/interfaces.ts +++ b/programs/beekeeper/beekeeper_wasm/src/interfaces.ts @@ -204,6 +204,17 @@ export interface IBeekeeperSession { */ getInfo(): IBeekeeperInfo; + /** + * Checks if wallet with given name exists + * + * @param {string} name name of the wallet + * + * @returns {boolean} `true` if a wallet exists otherwise `false` + * + * @throws {BeekeeperError} on any beekeeper API-related error (error parsing response, invalid input, timeout error, fs sync error etc.) + */ + hasWallet(name: string): boolean; + /** * Lists all of the opened wallets *