Skip to content

Commit b030768

Browse files
committed
fix(stores-eth): trigger batch rebuild on EVM RPC endpoint change
Previously the rebuild reaction tracked only the refcount set, so a runtime endpoint change (Keplr custom RPC configuration) left batchQueries bound to the stale URL until the contract set happened to change again. Include the current RPC URL in the reaction key and in waitFreshResponse's match predicate, and check refcount.size for the empty-contracts branch instead of relying on the key string.
1 parent fe82d22 commit b030768

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/stores-eth/src/queries/erc20-balance-batch.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export class ObservableQueryEthereumERC20BalancesBatchParent {
3636
makeObservable(this);
3737

3838
reaction(
39-
() => Array.from(this.refcount.keys()).sort().join(","),
39+
() => {
40+
const keys = Array.from(this.refcount.keys()).sort().join(",");
41+
// Include the RPC URL so a runtime endpoint change (user-configured
42+
// custom RPC) triggers a rebuild against the new endpoint.
43+
return `${this.getRpcUrl()}::${keys}`;
44+
},
4045
(key) => this.rebuildBatchQueries(key),
4146
{ fireImmediately: true, delay: REBUILD_DEBOUNCE_MS }
4247
);
@@ -98,19 +103,21 @@ export class ObservableQueryEthereumERC20BalancesBatchParent {
98103
return undefined;
99104
}
100105

106+
protected currentKey(): string {
107+
const keys = Array.from(this.refcount.keys()).sort().join(",");
108+
return `${this.getRpcUrl()}::${keys}`;
109+
}
110+
101111
async waitFreshResponse(): Promise<void> {
102112
// The reaction that rebuilds batchQueries is debounced, so refcount can
103113
// change without batchQueries catching up. Wait until the built key
104-
// matches the current refcount keys.
105-
await when(
106-
() =>
107-
Array.from(this.refcount.keys()).sort().join(",") === this.lastBuiltKey
108-
);
114+
// matches the current (refcount + rpc) snapshot.
115+
await when(() => this.currentKey() === this.lastBuiltKey);
109116
await Promise.all(this.batchQueries.map((q) => q.waitFreshResponse()));
110117
}
111118

112119
protected rebuildBatchQueries(key: string): void {
113-
if (key === "") {
120+
if (this.refcount.size === 0) {
114121
runInAction(() => {
115122
this.batchQueries = [];
116123
this.lastBuiltKey = key;

0 commit comments

Comments
 (0)