mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 18:58:08 +00:00
use BigNumber
This commit is contained in:
parent
e54c1befb2
commit
f6dc375dd0
@ -1,17 +1,19 @@
|
|||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
|
||||||
const toFiatCurrency = (amount, fiatCurrency, rates) => {
|
const toFiatCurrency = (amount, fiatCurrency, rates) => {
|
||||||
// calculate amount in local currency
|
// calculate amount in local currency
|
||||||
const rate = rates[fiatCurrency];
|
const rate = rates[fiatCurrency];
|
||||||
|
|
||||||
let localAmount = parseFloat(amount) * rate;
|
let localAmount = BigNumber(amount).times(rate);
|
||||||
localAmount = Number.isNaN(localAmount) ? '' : localAmount.toFixed(2);
|
localAmount = localAmount.isNaN() ? '' : localAmount.toFixed(2);
|
||||||
return localAmount;
|
return localAmount;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fromFiatCurrency = (localAmount, fiatCurrency, rates, decimals) => {
|
const fromFiatCurrency = (localAmount, fiatCurrency, rates, decimals) => {
|
||||||
const rate = rates[fiatCurrency];
|
const rate = rates[fiatCurrency];
|
||||||
|
|
||||||
let amount = parseFloat(localAmount) / rate;
|
let amount = BigNumber(localAmount).div(rate);
|
||||||
amount = Number.isNaN(amount) ? '' : amount.toFixed(decimals);
|
amount = amount.isNaN() ? '' : amount.toFixed(decimals);
|
||||||
return amount;
|
return amount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user