Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/services/wdk-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -649,7 +667,7 @@ class WDKService {

if (address) {
payload.push({
blockchain: networkType,
blockchain: this.getIndexerBlockchainName(networkType),
token: asset,
address,
limit: 100,
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
};
Expand Down