Skip to content

Commit

Permalink
feat: account store has method (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Sep 30, 2024
1 parent 21658b6 commit c486f2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/wallets/local-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export abstract class LocalWallet<
*/
abstract accountStore: {
add(account: TAccount): void | Promise<void>;
clear(): void | Promise<void>;
delete(account: { id: TAccount["id"] }): void | Promise<void>;
delete(accountId: TAccount["id"]): void | Promise<void>;
clear(): void | Promise<void>;
has(account: { id: TAccount["id"] }): boolean | Promise<boolean>;
has(accountId: TAccount["id"]): boolean | Promise<boolean>;
values(): Iterable<TAccount>;
};
}
10 changes: 8 additions & 2 deletions packages/wallet-ledger/src/ledger-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class LedgerWallet extends LocalWallet<LedgerAccount, "accounts"> {
.concat([account]),
);
},
clear: () => {
this.#ledgerAccounts$.next([]);
},
delete: (identifiable: string | { id: string }) => {
const id =
typeof identifiable === "string" ? identifiable : identifiable.id;
Expand All @@ -130,8 +133,11 @@ export class LedgerWallet extends LocalWallet<LedgerAccount, "accounts"> {
),
);
},
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,
};
Expand Down

0 comments on commit c486f2a

Please sign in to comment.