diff --git a/.changeset/heavy-ads-pay.md b/.changeset/heavy-ads-pay.md new file mode 100644 index 00000000..bef7a3d9 --- /dev/null +++ b/.changeset/heavy-ads-pay.md @@ -0,0 +1,5 @@ +--- +"@reactive-dot/core": patch +--- + +Ensure stable reference of wallets coming from wallet provider. diff --git a/packages/core/src/actions/aggregate-wallets.ts b/packages/core/src/actions/aggregate-wallets.ts index 7f504816..46d6a823 100644 --- a/packages/core/src/actions/aggregate-wallets.ts +++ b/packages/core/src/actions/aggregate-wallets.ts @@ -7,7 +7,7 @@ export function aggregateWallets( providersOrWallets.map((walletOrProvider) => walletOrProvider instanceof Wallet ? [walletOrProvider] - : walletOrProvider.getWallets(), + : walletOrProvider.getOrFetchWallets(), ), ).then((wallets) => wallets.flat()); } diff --git a/packages/core/src/wallets/provider.ts b/packages/core/src/wallets/provider.ts index d39d7d30..5ed3ec4b 100644 --- a/packages/core/src/wallets/provider.ts +++ b/packages/core/src/wallets/provider.ts @@ -1,5 +1,14 @@ import type { Wallet } from "./wallet.js"; export abstract class WalletProvider { + #wallets: Wallet[] | undefined; + abstract getWallets(): Wallet[] | Promise; + + /** + * @internal + */ + async getOrFetchWallets() { + return (this.#wallets ??= await this.getWallets()); + } }