Skip to content

Commit

Permalink
refactor: add default implementation for Wallet.getAccounts (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Nov 3, 2024
1 parent ec73daf commit 0958ce1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/ninety-plants-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@reactive-dot/wallet-walletconnect": patch
"@reactive-dot/wallet-ledger": patch
"@reactive-dot/core": patch
---

Added default implementation for `Wallet.getAccounts`.
2 changes: 1 addition & 1 deletion packages/core/src/wallets/injected/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class InjectedWallet extends Wallet<InjectedWalletOptions, "connected"> {
),
);

getAccounts() {
override getAccounts() {
const extension = this.#extension$.getValue();

if (extension === undefined) {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/wallets/wallet.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,7 +34,7 @@ export abstract class Wallet<

abstract readonly accounts$: Observable<PolkadotSignerAccount[]>;

abstract getAccounts():
| PolkadotSignerAccount[]
| Promise<PolkadotSignerAccount[]>;
getAccounts(): PolkadotSignerAccount[] | Promise<PolkadotSignerAccount[]> {
return firstValueFrom(this.accounts$, { defaultValue: [] });
}
}
6 changes: 1 addition & 5 deletions packages/wallet-ledger/src/ledger-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -114,10 +114,6 @@ export class LedgerWallet extends LocalWallet<
this.accountStore.clear();
}

getAccounts() {
return firstValueFrom(this.accounts$);
}

accountStore = {
add: (account: LedgerAccount) => {
this.#ledgerAccounts$.next(
Expand Down
6 changes: 1 addition & 5 deletions packages/wallet-walletconnect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -216,10 +216,6 @@ export class WalletConnect extends DeepLinkWallet {
}),
);

getAccounts() {
return firstValueFrom(this.accounts$);
}

async #getModal() {
if (this.#modal !== undefined) {
return this.#modal;
Expand Down

0 comments on commit 0958ce1

Please sign in to comment.