diff --git a/.changeset/ninety-plants-give.md b/.changeset/ninety-plants-give.md new file mode 100644 index 00000000..5f2fa6bf --- /dev/null +++ b/.changeset/ninety-plants-give.md @@ -0,0 +1,7 @@ +--- +"@reactive-dot/wallet-walletconnect": patch +"@reactive-dot/wallet-ledger": patch +"@reactive-dot/core": patch +--- + +Added default implementation for `Wallet.getAccounts`. diff --git a/packages/core/src/wallets/injected/wallet.ts b/packages/core/src/wallets/injected/wallet.ts index ba3263d3..19106805 100644 --- a/packages/core/src/wallets/injected/wallet.ts +++ b/packages/core/src/wallets/injected/wallet.ts @@ -70,7 +70,7 @@ export class InjectedWallet extends Wallet { ), ); - getAccounts() { + override getAccounts() { const extension = this.#extension$.getValue(); if (extension === undefined) { diff --git a/packages/core/src/wallets/wallet.ts b/packages/core/src/wallets/wallet.ts index b73c61df..0663c726 100644 --- a/packages/core/src/wallets/wallet.ts +++ b/packages/core/src/wallets/wallet.ts @@ -1,6 +1,6 @@ import { type PrefixedStorage, defaultStorage } from "../storage.js"; import type { PolkadotSignerAccount } from "./account.js"; -import type { Observable } from "rxjs"; +import { firstValueFrom, type Observable } from "rxjs"; export type WalletOptions = { storage?: PrefixedStorage | undefined; @@ -34,7 +34,7 @@ export abstract class Wallet< abstract readonly accounts$: Observable; - abstract getAccounts(): - | PolkadotSignerAccount[] - | Promise; + getAccounts(): PolkadotSignerAccount[] | Promise { + return firstValueFrom(this.accounts$, { defaultValue: [] }); + } } diff --git a/packages/wallet-ledger/src/ledger-wallet.ts b/packages/wallet-ledger/src/ledger-wallet.ts index ae013db2..e2fcc52f 100644 --- a/packages/wallet-ledger/src/ledger-wallet.ts +++ b/packages/wallet-ledger/src/ledger-wallet.ts @@ -6,7 +6,7 @@ import { LocalWallet, type PolkadotSignerAccount, } from "@reactive-dot/core/wallets.js"; -import { BehaviorSubject, firstValueFrom } from "rxjs"; +import { BehaviorSubject } from "rxjs"; import { map, skip } from "rxjs/operators"; type LedgerAccount = { @@ -114,10 +114,6 @@ export class LedgerWallet extends LocalWallet< this.accountStore.clear(); } - getAccounts() { - return firstValueFrom(this.accounts$); - } - accountStore = { add: (account: LedgerAccount) => { this.#ledgerAccounts$.next( diff --git a/packages/wallet-walletconnect/src/index.ts b/packages/wallet-walletconnect/src/index.ts index c47c1b11..03106b08 100644 --- a/packages/wallet-walletconnect/src/index.ts +++ b/packages/wallet-walletconnect/src/index.ts @@ -13,7 +13,7 @@ import type { IUniversalProvider, UniversalProviderOpts, } from "@walletconnect/universal-provider"; -import { BehaviorSubject, firstValueFrom } from "rxjs"; +import { BehaviorSubject } from "rxjs"; import { map } from "rxjs/operators"; export class WalletConnect extends DeepLinkWallet { @@ -216,10 +216,6 @@ export class WalletConnect extends DeepLinkWallet { }), ); - getAccounts() { - return firstValueFrom(this.accounts$); - } - async #getModal() { if (this.#modal !== undefined) { return this.#modal;