Skip to content

Commit

Permalink
fix: Add MANTLE support when fetching conversion rates for unsupporte…
Browse files Browse the repository at this point in the history
…d native currency
  • Loading branch information
Prithpal-Sooriya committed Feb 27, 2025
1 parent 1b35e86 commit 85eb612
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ describe('CryptoCompare', () => {
expect(conversionRate).toBe(123);
});

it('should override currency symbol when the CryptoCompare identifier is different', async () => {
nock(cryptoCompareHost)
.get('/data/price?fsym=USD&tsyms=MANTLE')
.reply(200, { MANTLE: 1234 });

const { conversionRate } = await fetchExchangeRate('MNT', 'USD');
expect(conversionRate).toBe(1234);
});

describe('fetchMultiExchangeRate', () => {
it('should return CAD and USD conversion rate for BTC, ETH, and SOL', async () => {
nock(cryptoCompareHost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ function get#URL(
nativeCurrency: string,
includeUSDRate?: boolean,
) {
nativeCurrency = nativeCurrency.toUpperCase();
const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
return (
`${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +
`${fsym}&tsyms=${currentCurrency.toUpperCase()}` +
`${nativeCurrency}&tsyms=${currentCurrency}` +
`${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`
);
}
Expand Down Expand Up @@ -100,6 +98,11 @@ export async function fetchExchangeRate(
conversionRate: number;
usdConversionRate: number;
}> {
currency = currency.toUpperCase();
nativeCurrency = nativeCurrency.toUpperCase();
currency = nativeSymbolOverrides.get(currency) ?? currency;
nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;

const json = await handleFetch(
get#URL(currency, nativeCurrency, includeUSDRate),
);
Expand Down

0 comments on commit 85eb612

Please # to comment.