Skip to content

Commit

Permalink
fix requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 13, 2024
1 parent f1e9bcf commit 7665e5e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/dex/cables/cables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,22 @@ export class Cables extends SimpleExchange implements IDex<any> {
return [];
}

const pairData = await this.getPairData(srcToken, destToken);
const normalizedSrcToken = this.normalizeToken(srcToken);
const normalizedDestToken = this.normalizeToken(destToken);

const pairData = await this.getPairData(
normalizedSrcToken,
normalizedDestToken,
);

if (!pairData) {
return [];
}

await this.setTokensMap();
const tokensAddr = (await this.getCachedTokensAddr()) || {};

return [
this.getPoolIdentifier(
tokensAddr[pairData.base.toLowerCase()],
tokensAddr[pairData.quote.toLowerCase()],
normalizedSrcToken.address,
normalizedDestToken.address,
),
];
}
Expand Down Expand Up @@ -695,37 +698,28 @@ export class Cables extends SimpleExchange implements IDex<any> {
};

async getPairData(srcToken: Token, destToken: Token): Promise<any> {
const normalizedSrcToken = this.normalizeToken(srcToken);
const normalizedDestToken = this.normalizeToken(destToken);

if (normalizedSrcToken.address === normalizedDestToken.address) {
if (srcToken.address === destToken.address) {
return null;
}

const cachedTokens = await this.getCachedTokens();

normalizedSrcToken.symbol = this.findKeyByAddress(
cachedTokens,
normalizedSrcToken.address,
);
normalizedDestToken.symbol = this.findKeyByAddress(
cachedTokens,
normalizedDestToken.address,
);
srcToken.symbol = this.findKeyByAddress(cachedTokens, srcToken.address);
destToken.symbol = this.findKeyByAddress(cachedTokens, destToken.address);

const cachedPairs = await this.getCachedPairs();

const potentialPairs = [
{
base: normalizedSrcToken.symbol,
quote: normalizedDestToken.symbol,
identifier: this.getPairString(normalizedSrcToken, normalizedDestToken),
base: srcToken.symbol,
quote: destToken.symbol,
identifier: this.getPairString(srcToken, destToken),
isSrcBase: true,
},
{
base: normalizedDestToken.symbol,
quote: normalizedSrcToken.symbol,
identifier: this.getPairString(normalizedDestToken, normalizedSrcToken),
base: destToken.symbol,
quote: srcToken.symbol,
identifier: this.getPairString(destToken, srcToken),
isSrcBase: false,
},
];
Expand Down

0 comments on commit 7665e5e

Please sign in to comment.