mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
1e83835ba8
* 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.
50 lines
996 B
JavaScript
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,
|
|
} |