refactor xmr rate module to exchange rate module for multi crypto support
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import Decimal from 'decimal.js';
|
||||
import type { ShopFiatCurrency } from '../../../types/ShopFiatCurrency';
|
||||
|
||||
export const extractCoinPaprikaTickerPrice = (
|
||||
response: { quotes: Record<string, { price: number }> },
|
||||
shopFiatCurrency: ShopFiatCurrency
|
||||
): number | null => {
|
||||
const quote = response.quotes[shopFiatCurrency];
|
||||
|
||||
if (!quote) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rate = quote.price;
|
||||
|
||||
if (typeof rate !== 'number' || !Number.isFinite(rate) || rate <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new Decimal(rate).toDecimalPlaces(2).toNumber();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user