2019-03-11 17:37:19 +00:00
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
|
2019-03-11 16:53:28 +00:00
|
|
|
const toFiatCurrency = (amount, fiatCurrency, rates) => {
|
|
|
|
// calculate amount in local currency
|
|
|
|
const rate = rates[fiatCurrency];
|
|
|
|
|
2019-03-11 17:37:19 +00:00
|
|
|
let localAmount = BigNumber(amount).times(rate);
|
|
|
|
localAmount = localAmount.isNaN() ? '' : localAmount.toFixed(2);
|
2019-03-11 16:53:28 +00:00
|
|
|
return localAmount;
|
|
|
|
};
|
|
|
|
|
|
|
|
const fromFiatCurrency = (localAmount, fiatCurrency, rates, decimals) => {
|
|
|
|
const rate = rates[fiatCurrency];
|
|
|
|
|
2019-03-11 17:37:19 +00:00
|
|
|
let amount = BigNumber(localAmount).div(rate);
|
|
|
|
amount = amount.isNaN() ? '' : amount.toFixed(decimals);
|
2019-03-11 16:53:28 +00:00
|
|
|
return amount;
|
|
|
|
};
|
|
|
|
|
|
|
|
export { toFiatCurrency, fromFiatCurrency };
|