diff options
author | Zac Mitton <zacmitton22@gmail.com> | 2016-06-21 06:46:29 +0800 |
---|---|---|
committer | Zac Mitton <zacmitton22@gmail.com> | 2016-06-21 06:46:29 +0800 |
commit | 9132f085070a99499a75d6353983bd1683f7a3f0 (patch) | |
tree | 906453bc38a443bf7c7a576bcd5bedcd46787859 /ui/app | |
parent | d19c286ee8dbd748ef0e1770545299879dada1da (diff) | |
download | tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar.gz tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar.bz2 tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar.lz tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar.xz tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.tar.zst tangerine-wallet-browser-9132f085070a99499a75d6353983bd1683f7a3f0.zip |
added a failing case and fixed it by refactoring everything to strings
Diffstat (limited to 'ui/app')
-rw-r--r-- | ui/app/util.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index 6ece28a9e..56a16a4cd 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -85,22 +85,20 @@ function weiToEth(bn) { // Takes hex, returns [beforeDecimal, afterDecimal] function parseBalance(balance) { - if (!balance || balance === '0x0') return ['0', '0'] - var wei = numericBalance(balance).toString(10) - var eth = String(wei/valueTable['wei']) - var beforeDecimal = String(Math.floor(eth)) - var afterDecimal - if(eth.indexOf('.') > -1){ - afterDecimal = eth.slice(eth.indexOf('.') + 1) - }else{ - afterDecimal = '0' - } + let beforeDecimal, afterDecimal + let wei = numericBalance(balance).toString() + let trailingZeros = /0+$/ + + beforeDecimal = wei.length > 18 ? wei.slice(0, wei.length - 18) : '0' + afterDecimal = ("000000000000000000" + wei).slice(-18).replace(trailingZeros, "") + if(afterDecimal == ""){afterDecimal = "0" } return [beforeDecimal, afterDecimal] } // Takes wei hex, returns "None" or "${formattedAmount} ETH" function formatBalance(balance, decimalsToKeep) { var parsed = parseBalance(balance) + console.log(parsed) var beforeDecimal = parsed[0] var afterDecimal = parsed[1] var formatted = "None" |