aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-06-22 00:19:37 +0800
committerGitHub <noreply@github.com>2016-06-22 00:19:37 +0800
commitcfc056e34ba6dda983a1ca6b4bc090661b799d38 (patch)
tree35373fb089eb7546a42afdd4f8dc0e810d4b1bf0 /ui
parent6fdece459d1d2674acc5349b70e68c1d5033dd38 (diff)
parentbd6ee81d097f3da2fcfbfb7b7d29d5daf706eb1d (diff)
downloadtangerine-wallet-browser-cfc056e34ba6dda983a1ca6b4bc090661b799d38.tar.gz
tangerine-wallet-browser-cfc056e34ba6dda983a1ca6b4bc090661b799d38.tar.zst
tangerine-wallet-browser-cfc056e34ba6dda983a1ca6b4bc090661b799d38.zip
Merge pull request #299 from MetaMask/balances-bug-fix
added a failing case and fixed it by refactoring everything to strings
Diffstat (limited to 'ui')
-rw-r--r--ui/app/util.js17
1 files changed, 7 insertions, 10 deletions
diff --git a/ui/app/util.js b/ui/app/util.js
index 6ece28a9e..9e08e0bb2 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -85,16 +85,13 @@ 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]
}