|
|
|
@ -1,17 +1,19 @@
|
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
|
|
|
|
|
|
const toFiatCurrency = (amount, fiatCurrency, rates) => {
|
|
|
|
|
// calculate amount in local currency
|
|
|
|
|
const rate = rates[fiatCurrency];
|
|
|
|
|
|
|
|
|
|
let localAmount = parseFloat(amount) * rate;
|
|
|
|
|
localAmount = Number.isNaN(localAmount) ? '' : localAmount.toFixed(2);
|
|
|
|
|
let localAmount = BigNumber(amount).times(rate);
|
|
|
|
|
localAmount = localAmount.isNaN() ? '' : localAmount.toFixed(2);
|
|
|
|
|
return localAmount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fromFiatCurrency = (localAmount, fiatCurrency, rates, decimals) => {
|
|
|
|
|
const rate = rates[fiatCurrency];
|
|
|
|
|
|
|
|
|
|
let amount = parseFloat(localAmount) / rate;
|
|
|
|
|
amount = Number.isNaN(amount) ? '' : amount.toFixed(decimals);
|
|
|
|
|
let amount = BigNumber(localAmount).div(rate);
|
|
|
|
|
amount = amount.isNaN() ? '' : amount.toFixed(decimals);
|
|
|
|
|
return amount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|