1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-13 20:08:56 +00:00

add utils for converting to/from fiat

This commit is contained in:
slowbackspace 2019-03-11 17:53:28 +01:00
parent f08e4683b1
commit 4616ebeadc

View File

@ -0,0 +1,18 @@
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);
return localAmount;
};
const fromFiatCurrency = (localAmount, fiatCurrency, rates, decimals) => {
const rate = rates[fiatCurrency];
let amount = parseFloat(localAmount) / rate;
amount = Number.isNaN(amount) ? '' : amount.toFixed(decimals);
return amount;
};
export { toFiatCurrency, fromFiatCurrency };