diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 91c7c83e9..9a3963ac1 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -122,25 +122,6 @@ describe('util', function() { }) - describe('#ethToWei', function() { - - it('should take an eth BN, returns wei BN', function() { - var input = new ethUtil.BN(1, 10) - var result = util.ethToWei(input) - assert.equal(result, ethInWei, '18 zeroes') - }) - - }) - - describe('#weiToEth', function() { - - it('should take a wei BN and return an eth BN', function() { - var result = util.weiToEth(new ethUtil.BN(ethInWei)) - assert.equal(result, '1', 'equals 1 eth') - }) - - }) - describe('#formatBalance', function() { it('when given nothing', function() { diff --git a/ui/app/util.js b/ui/app/util.js index b86bc6035..216ded49f 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -30,8 +30,6 @@ module.exports = { generateBalanceObject: generateBalanceObject, dataSize: dataSize, readableDate: readableDate, - ethToWei: ethToWei, - weiToEth: weiToEth, normalizeToWei: normalizeToWei, normalizeEthStringToWei: normalizeEthStringToWei, normalizeNumberToWei: normalizeNumberToWei, @@ -79,27 +77,15 @@ function numericBalance (balance) { 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] function parseBalance (balance) { var beforeDecimal, afterDecimal - const wei = numericBalance(balance).toString() + const wei = numericBalance(balance) + var weiString = wei.toString() 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, '') if (afterDecimal === '') { afterDecimal = '0' } return [beforeDecimal, afterDecimal]