Skip to content

Commit 48007b2

Browse files
committed
feat(stores-eth): add currency registration check in ERC20 balance queries
Implemented a new method to verify if a currency is registered before proceeding with balance fetching in both ObservableQueryEthereumERC20BalanceImpl and ObservableQueryThirdpartyERC20BalancesImpl. This prevents unnecessary calls when the currency has been removed, enhancing efficiency.
1 parent 62a2ac5 commit 48007b2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export class ObservableQueryEthereumERC20BalanceImpl
111111
}
112112

113113
protected async ensureFetched(): Promise<void> {
114+
// balanceImplMap doesn't evict on currency removal.
115+
if (!this.isCurrencyRegistered()) return;
114116
// Force temporary registration so imperative callers (outside a reactive
115117
// observer) still trigger an actual eth_call.
116118
this.parent.addContract(this.contractAddress);
@@ -121,6 +123,15 @@ export class ObservableQueryEthereumERC20BalanceImpl
121123
}
122124
}
123125

126+
protected isCurrencyRegistered(): boolean {
127+
const target = DenomHelper.normalizeDenom(this.denomHelper.denom);
128+
return this.chainGetter
129+
.getModularChain(this.chainId)
130+
.currencies.some(
131+
(c) => DenomHelper.normalizeDenom(c.coinMinimalDenom) === target
132+
);
133+
}
134+
124135
fetch(): Promise<void> {
125136
return this.ensureFetched();
126137
}

packages/stores-eth/src/queries/erc20-balances.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ export class ObservableQueryThirdpartyERC20BalancesImpl
322322
// observation-driven reaction) so imperative callers also exercise the
323323
// batch fallback for tokens missing from Alchemy.
324324
protected async awaitFallbackIfMissing(): Promise<void> {
325+
// balanceImplMap doesn't evict on currency removal.
326+
if (!this.isCurrencyRegistered()) return;
325327
const contract = this.denomHelper.contractAddress;
326328
// Mirror the reaction: an Alchemy error forces fallback even when a
327329
// stale response still advertises the contract as covered.
@@ -338,6 +340,15 @@ export class ObservableQueryThirdpartyERC20BalancesImpl
338340
}
339341
}
340342

343+
protected isCurrencyRegistered(): boolean {
344+
const target = DenomHelper.normalizeDenom(this.denomHelper.denom);
345+
return this.chainGetter
346+
.getModularChain(this.chainId)
347+
.currencies.some(
348+
(c) => DenomHelper.normalizeDenom(c.coinMinimalDenom) === target
349+
);
350+
}
351+
341352
async waitFreshResponse(): Promise<
342353
Readonly<QueryResponse<unknown>> | undefined
343354
> {

0 commit comments

Comments
 (0)