Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima-net committed Aug 23, 2022
1 parent 4568073 commit 15fdd93
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/atomex/atomex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ export class Atomex implements AtomexService {
return swaps.length === 1 ? swaps[0]! : (swaps as readonly Swap[]);
}

async convertCurrency(from: Currency['id'], to: Currency['id'], inAmount: BigNumber.Value): Promise<BigNumber | undefined> {
const price = await this.atomexContext.providers.ratesProvider.getAveragePrice(from, to);
async convertCurrency(fromAmount: BigNumber.Value, fromCurrency: Currency['id'], toCurrency: Currency['id']): Promise<BigNumber | undefined> {
const price = await this.atomexContext.providers.ratesProvider.getAveragePrice(fromCurrency, toCurrency);
if (!price)
return undefined;

const inAmountBigNumber = BigNumber.isBigNumber(inAmount) ? inAmount : new BigNumber(inAmount);
const inAmountBigNumber = BigNumber.isBigNumber(fromAmount) ? fromAmount : new BigNumber(fromAmount);
const outAmount = inAmountBigNumber.multipliedBy(price);
const toCurrency = this.getCurrency(to);
const toCurrencyInfo = this.getCurrency(toCurrency);

return toCurrency ? toFixedBigNumber(outAmount, toCurrency.decimals) : outAmount;
return toCurrencyInfo ? toFixedBigNumber(outAmount, toCurrencyInfo.decimals) : outAmount;
}
}

0 comments on commit 15fdd93

Please sign in to comment.