|
|
@ -30,8 +30,6 @@ module.exports = { |
|
|
|
generateBalanceObject: generateBalanceObject, |
|
|
|
generateBalanceObject: generateBalanceObject, |
|
|
|
dataSize: dataSize, |
|
|
|
dataSize: dataSize, |
|
|
|
readableDate: readableDate, |
|
|
|
readableDate: readableDate, |
|
|
|
ethToWei: ethToWei, |
|
|
|
|
|
|
|
weiToEth: weiToEth, |
|
|
|
|
|
|
|
normalizeToWei: normalizeToWei, |
|
|
|
normalizeToWei: normalizeToWei, |
|
|
|
normalizeEthStringToWei: normalizeEthStringToWei, |
|
|
|
normalizeEthStringToWei: normalizeEthStringToWei, |
|
|
|
normalizeNumberToWei: normalizeNumberToWei, |
|
|
|
normalizeNumberToWei: normalizeNumberToWei, |
|
|
@ -79,27 +77,15 @@ function numericBalance (balance) { |
|
|
|
return new ethUtil.BN(stripped, 16) |
|
|
|
return new ethUtil.BN(stripped, 16) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Takes eth BN, returns BN wei
|
|
|
|
|
|
|
|
function ethToWei (bn) { |
|
|
|
|
|
|
|
var eth = new ethUtil.BN('1000000000000000000') |
|
|
|
|
|
|
|
var wei = bn.mul(eth) |
|
|
|
|
|
|
|
return wei |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Takes BN in Wei, returns BN in eth
|
|
|
|
|
|
|
|
function weiToEth (bn) { |
|
|
|
|
|
|
|
var diff = new ethUtil.BN('1000000000000000000') |
|
|
|
|
|
|
|
var eth = bn.div(diff) |
|
|
|
|
|
|
|
return eth |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Takes hex, returns [beforeDecimal, afterDecimal]
|
|
|
|
// Takes hex, returns [beforeDecimal, afterDecimal]
|
|
|
|
function parseBalance (balance) { |
|
|
|
function parseBalance (balance) { |
|
|
|
var beforeDecimal, afterDecimal |
|
|
|
var beforeDecimal, afterDecimal |
|
|
|
const wei = numericBalance(balance).toString() |
|
|
|
const wei = numericBalance(balance) |
|
|
|
|
|
|
|
var weiString = wei.toString() |
|
|
|
const trailingZeros = /0+$/ |
|
|
|
const trailingZeros = /0+$/ |
|
|
|
|
|
|
|
|
|
|
|
beforeDecimal = wei.length > 18 ? wei.slice(0, wei.length - 18) : '0' |
|
|
|
beforeDecimal = weiString.length > 18 ? weiString.slice(0, weiString.length - 18) : '0' |
|
|
|
|
|
|
|
// We don't use weiToEth here because we need to maintain decimal precision.
|
|
|
|
afterDecimal = ('000000000000000000' + wei).slice(-18).replace(trailingZeros, '') |
|
|
|
afterDecimal = ('000000000000000000' + wei).slice(-18).replace(trailingZeros, '') |
|
|
|
if (afterDecimal === '') { afterDecimal = '0' } |
|
|
|
if (afterDecimal === '') { afterDecimal = '0' } |
|
|
|
return [beforeDecimal, afterDecimal] |
|
|
|
return [beforeDecimal, afterDecimal] |
|
|
|