Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add default implementation for Wallet.getAccounts #304

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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