Skip to content

Commit

Permalink
fix: select proper currency types
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 18, 2024
1 parent 0664f16 commit 9cb075c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions apps/swap/src/fx/fx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Currency,
CustomStore,
mapToSupportedCurrency,
SupportedCurrencyType,
} from '@bitsacco/common';

interface CurrencyApiResponse {
Expand Down Expand Up @@ -36,8 +37,8 @@ export class FxService {
}

async getExchangeRate(
baseCurrency: Currency,
targetCurrency: Currency,
baseCurrency: SupportedCurrencyType,
targetCurrency: SupportedCurrencyType,
): Promise<number> {
const cacheKey = `${baseCurrency}-${targetCurrency}`;

Expand Down Expand Up @@ -73,7 +74,7 @@ export class FxService {
const response = await firstValueFrom(
this.httpService
.get(
`https://api.currencyapi.com/v3/latest?apikey=${api_key}&base_currency=${mapToSupportedCurrency(baseCurrency)}&currencies=${mapToSupportedCurrency(targetCurrency)}`,
`https://api.currencyapi.com/v3/latest?apikey=${api_key}&base_currency=${baseCurrency}&currencies=${targetCurrency}`,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -100,7 +101,7 @@ export class FxService {
baseCurrency: Currency,
targetCurrency: Currency,
) {
const rate = await this.getExchangeRate(baseCurrency, targetCurrency);
const rate = await this.getExchangeRate(mapToSupportedCurrency(baseCurrency), mapToSupportedCurrency(targetCurrency));
return 1 / rate;
}
}

0 comments on commit 9cb075c

Please sign in to comment.