Skip to content

Commit d71e9ef

Browse files
authored
fix(core): missing chain spec option (#1180)
1 parent ae3891b commit d71e9ef

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

.changeset/tasty-rats-show.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@reactive-dot/core": patch
3+
---
4+
5+
Added missing `chainSpec` option to `whenAccountsChanged`, bringing parity with `useAccounts` hook/composable.

packages/core/src/apis/when-accounts-changed.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { PolkadotSignerAccount } from "../wallets/account.js";
55
import { Wallet } from "../wallets/wallet.js";
66
import { getClient } from "./get-client.js";
77
import { whenAccountsChanged } from "./when-accounts-changed.js";
8+
import type { ChainSpecData } from "@polkadot-api/substrate-client";
89
import type { PolkadotClient } from "polkadot-api";
910
import { lastValueFrom, Observable } from "rxjs";
1011
import { afterEach, expect, it, vi } from "vitest";
@@ -65,6 +66,26 @@ it("fetches wallets with chain-spec", () => {
6566
});
6667
});
6768

69+
it("uses the provided chainSpec when supplied", async () => {
70+
const wallet = new MockWallet();
71+
const chainSpec = {
72+
name: "Custom",
73+
genesisHash: "0x123",
74+
properties: { ss58Format: 42 },
75+
} as ChainSpecData;
76+
77+
whenAccountsChanged(defineConfig({ chains: {}, wallets: [wallet] }), {
78+
chainSpec,
79+
});
80+
81+
expect(getAccounts).toHaveBeenCalledWith(
82+
expect.any(Observable),
83+
chainSpec,
84+
undefined,
85+
undefined,
86+
);
87+
});
88+
6889
it("fetches wallets with EVM accounts", () => {
6990
const wallet = new MockWallet();
7091

packages/core/src/apis/when-accounts-changed.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { getAccounts } from "../actions/get-accounts.js";
22
import type { InferChainId } from "../chains.js";
33
import type { Config } from "../config.js";
4+
import type { MaybeAsync } from "../types.js";
45
import { getClient } from "./get-client.js";
56
import { whenWalletsChanged } from "./when-wallets-changed.js";
7+
import type { ChainSpecData } from "@polkadot-api/substrate-client";
68
import { defer } from "rxjs";
79

810
/**
@@ -14,19 +16,23 @@ import { defer } from "rxjs";
1416
*/
1517
export function whenAccountsChanged<TConfig extends Config>(
1618
config: TConfig,
17-
options?: { chainId?: InferChainId<TConfig> },
19+
options?: {
20+
chainId?: InferChainId<TConfig>;
21+
chainSpec?: MaybeAsync<ChainSpecData>;
22+
},
1823
) {
1924
const chainId = options?.chainId;
2025

2126
return getAccounts(
2227
whenWalletsChanged(config),
23-
chainId === undefined
24-
? undefined
25-
: defer(() =>
26-
getClient(config, { chainId }).then((client) =>
27-
client.getChainSpecData(),
28-
),
29-
),
28+
options?.chainSpec ??
29+
(chainId === undefined
30+
? undefined
31+
: defer(() =>
32+
getClient(config, { chainId }).then((client) =>
33+
client.getChainSpecData(),
34+
),
35+
)),
3036
undefined,
3137
config.includeEvmAccounts === undefined
3238
? undefined

0 commit comments

Comments
 (0)