1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/conversion-util.js
Dan J Miller 1e83835ba8 [New-UI] Confirm Screen restyle and connect to state (#2042)
* Adds utility for converting currencies (WIP)

* Implements confirm screen

* Style tweaks.

* Confirm screen total ammount now uses real data.

* Confirm screen total ammount now uses real data.

* Replace content divider with sibling css.

* Replace section divider with scss.
2017-09-11 22:19:05 -07:00

50 lines
996 B
JavaScript

const {
numericBalance,
parseBalance,
formatBalance,
normalizeToWei,
valueTable,
} = require('./util')
const hexToBn = require('../../app/scripts/lib/hex-to-bn')
const { BN } = require('ethereumjs-util')
const GWEI_MULTIPLIER = normalizeToWei(hexToBn(valueTable.gwei.toString(16)), 'gwei');
const conversionUtil = (value, {
fromCurrency,
toCurrency,
fromFormat,
toFormat,
precision = 2,
conversionRate,
}) => {
let result;
if (fromFormat === 'BN') {
if (fromCurrency !== 'GWEI') {
result = normalizeToWei(value, 'gwei')
}
else {
result = value
}
result = result.toString(16)
result = formatBalance(result, 9)
result = result.split(' ')
result = Number(result[0]) * 1000000000
}
if (fromCurrency === 'GWEI') {
result = result / 1000000000
}
if (toCurrency === 'USD') {
result = result * conversionRate
result = result.toFixed(precision)
}
return result
};
module.exports = {
conversionUtil,
}