From c486f2a0e1731b93353a37bd75a1180316614eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Tue, 1 Oct 2024 10:01:23 +1300 Subject: [PATCH] feat: account store `has` method (#210) --- packages/core/src/wallets/local-wallet.ts | 4 +++- packages/wallet-ledger/src/ledger-wallet.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/core/src/wallets/local-wallet.ts b/packages/core/src/wallets/local-wallet.ts index dce0fc25..25f6546b 100644 --- a/packages/core/src/wallets/local-wallet.ts +++ b/packages/core/src/wallets/local-wallet.ts @@ -13,9 +13,11 @@ export abstract class LocalWallet< */ abstract accountStore: { add(account: TAccount): void | Promise; + clear(): void | Promise; delete(account: { id: TAccount["id"] }): void | Promise; delete(accountId: TAccount["id"]): void | Promise; - clear(): void | Promise; + has(account: { id: TAccount["id"] }): boolean | Promise; + has(accountId: TAccount["id"]): boolean | Promise; values(): Iterable; }; } diff --git a/packages/wallet-ledger/src/ledger-wallet.ts b/packages/wallet-ledger/src/ledger-wallet.ts index 633871c9..ac95e57b 100644 --- a/packages/wallet-ledger/src/ledger-wallet.ts +++ b/packages/wallet-ledger/src/ledger-wallet.ts @@ -120,6 +120,9 @@ export class LedgerWallet extends LocalWallet { .concat([account]), ); }, + clear: () => { + this.#ledgerAccounts$.next([]); + }, delete: (identifiable: string | { id: string }) => { const id = typeof identifiable === "string" ? identifiable : identifiable.id; @@ -130,8 +133,11 @@ export class LedgerWallet extends LocalWallet { ), ); }, - clear: () => { - this.#ledgerAccounts$.next([]); + has: (identifiable: string | { id: string }) => { + const id = + typeof identifiable === "string" ? identifiable : identifiable.id; + + return this.#ledgerAccounts$.value.some((account) => account.id === id); }, values: () => this.#ledgerAccounts$.value, };