diff --git a/src/services/wdk-service/index.ts b/src/services/wdk-service/index.ts index 5ae8528..9396219 100644 --- a/src/services/wdk-service/index.ts +++ b/src/services/wdk-service/index.ts @@ -117,6 +117,24 @@ class WDKService { return this.config.indexer.apiKey; } + // Maps network key to blockchain name expected by the indexer API + private getIndexerBlockchainName(networkType: string): string { + const chainsConfig = this.getChainsConfig(); + if (chainsConfig?.ethereum?.chainId === 11155111 && networkType === 'ethereum') { + return 'sepolia'; + } + return networkType; + } + + // Reverse-maps indexer blockchain name back to internal network key + private fromIndexerBlockchainName(blockchain: string): string { + const chainsConfig = this.getChainsConfig(); + if (chainsConfig?.ethereum?.chainId === 11155111 && blockchain === 'sepolia') { + return 'ethereum'; + } + return blockchain; + } + private getChainsConfig(): any { if (!this.config) { throw new Error('WDK Service config not set'); @@ -649,7 +667,7 @@ class WDKService { if (address) { payload.push({ - blockchain: networkType, + blockchain: this.getIndexerBlockchainName(networkType), token: asset, address, limit: 100, @@ -718,7 +736,7 @@ class WDKService { const address = networkAddresses[networkType as NetworkType]; if (address) { payload.push({ - blockchain: networkType, + blockchain: this.getIndexerBlockchainName(networkType), token: asset, address, }); @@ -751,7 +769,8 @@ class WDKService { ).reduce( (allBalances, [_, value]) => { const obj = (value as any).tokenBalance; - allBalances[`${obj.blockchain}_${obj.token}`] = { + const networkKey = this.fromIndexerBlockchainName(obj.blockchain); + allBalances[`${networkKey}_${obj.token}`] = { balance: parseFloat(obj.amount), asset: obj.token as AssetTicker, };