aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/util.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-04-15 04:20:19 +0800
committerDan Finlay <dan@danfinlay.com>2016-04-15 04:20:19 +0800
commit8527d051b0a02bbf9d5f26f10299daf10d647019 (patch)
treefbcd559a90e6e5e1fb580790ecf78d5bdacc98d6 /ui/app/util.js
parent5694a116725dad3d3bb9878c9c7059f1870d2e29 (diff)
downloadtangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar.gz
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar.bz2
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar.lz
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar.xz
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.tar.zst
tangerine-wallet-browser-8527d051b0a02bbf9d5f26f10299daf10d647019.zip
Fix eth resolution
utils.formatBalance was returning rounded ether, was not useful for displaying account balances. Now returns four decimal points, and is easily configurable for more, with passing tests. Spoiler alert: Don't you dare divide bignumber wei. Bignumber does not have decimals. Keep it as wei, format it as ether.
Diffstat (limited to 'ui/app/util.js')
-rw-r--r--ui/app/util.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/ui/app/util.js b/ui/app/util.js
index 4c31e54f4..74e2c19aa 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -64,11 +64,16 @@ function weiToEth(bn) {
return eth
}
+var decimalsToKeep = 4
function formatBalance(balance) {
if (!balance) return 'None'
var wei = numericBalance(balance)
- var eth = weiToEth(wei)
- return eth.toString(10) + ' ETH'
+ var padded = wei.toString(10)
+ var len = padded.length
+ var nonZeroIndex = padded.match(/[^0]/).index
+ var beforeDecimal = padded.substr(nonZeroIndex ? nonZeroIndex : 0, len - 18)
+ var afterDecimal = padded.substr(len - 18, decimalsToKeep)
+ return `${beforeDecimal}.${afterDecimal} ETH`
}
function dataSize(data) {