From 81c5267ee7aab0efb657164f7c96eb50d25097bf Mon Sep 17 00:00:00 2001 From: genaroibc Date: Tue, 24 Oct 2023 14:39:09 -0300 Subject: [PATCH] fix: correctly filter chains --- src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 651b767..c1f0628 100644 --- a/src/index.ts +++ b/src/index.ts @@ -745,8 +745,8 @@ export class Squid { userAddress: string; chains: (string | number)[]; }): Promise { - // remove invalid and duplicate chains - const filteredChains = new Set(chains.filter(c => !Number.isNaN(c))); + // remove invalid and duplicate chains and convert to number + const filteredChains = new Set(chains.map(Number).filter(c => !isNaN(c))); return getAllEvmTokensBalance( this.tokens.filter(t => filteredChains.has(Number(t.chainId))), @@ -756,13 +756,18 @@ export class Squid { public async getAllCosmosBalances({ addresses, - chainIds + chainIds = [] }: { addresses: CosmosAddress[]; chainIds?: (string | number)[]; }) { - const cosmosChains = this.chains.filter( - c => c.chainType === ChainType.Cosmos && chainIds?.includes(c.chainId) + const cosmosChains = this.chains.filter(c => + c.chainType === ChainType.Cosmos && + // if chainIds is not provided, return all cosmos chains + chainIds.length === 0 + ? true + : // else return only chains that are in chainIds + chainIds?.includes(c.chainId) ) as CosmosChain[]; return getCosmosBalances({ @@ -787,7 +792,7 @@ export class Squid { // fetch balances for all chains compatible with provided addresses const evmBalances = evmAddress ? await this.getAllEvmBalances({ - chains: this.tokens.map(t => Number(t.chainId)), + chains: this.tokens.map(t => String(t.chainId)), userAddress: evmAddress }) : [];