Skip to content

Commit

Permalink
refactor(core): wallets aggregation (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
tien authored Nov 5, 2024
1 parent 610dc67 commit ed4e82d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/heavy-ads-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactive-dot/core": patch
---

Ensure stable reference of wallets coming from wallet provider.
2 changes: 1 addition & 1 deletion packages/core/src/actions/aggregate-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function aggregateWallets(
providersOrWallets.map((walletOrProvider) =>
walletOrProvider instanceof Wallet
? [walletOrProvider]
: walletOrProvider.getWallets(),
: walletOrProvider.getOrFetchWallets(),
),
).then((wallets) => wallets.flat());
}
9 changes: 9 additions & 0 deletions packages/core/src/wallets/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type { Wallet } from "./wallet.js";

export abstract class WalletProvider {
#wallets: Wallet[] | undefined;

abstract getWallets(): Wallet[] | Promise<Wallet[]>;

/**
* @internal
*/
async getOrFetchWallets() {
return (this.#wallets ??= await this.getWallets());
}
}

0 comments on commit ed4e82d

Please sign in to comment.