diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-07-12 08:44:00 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-07-12 08:44:00 +0800 |
commit | d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9 (patch) | |
tree | ae0143375e16a1950582da2941d179b4c7977c44 /ui/app/util.js | |
parent | 6a61591dad48f20502a64ad22a8d54e18a0a1d21 (diff) | |
download | tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar.gz tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar.bz2 tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar.lz tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar.xz tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.tar.zst tangerine-wallet-browser-d7e6b752a38aaf4d1e46168683bc9539a8e9e0e9.zip |
Integrate changes back into eth-balance
Diffstat (limited to 'ui/app/util.js')
-rw-r--r-- | ui/app/util.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/ui/app/util.js b/ui/app/util.js index 0d57f1f96..c04612455 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -115,27 +115,31 @@ function formatBalance (balance, decimalsToKeep) { } -function generateBalanceObject (formattedBalance) { +function generateBalanceObject (formattedBalance, decimalsToKeep = 1) { var balance = formattedBalance.split(' ')[0] var label = formattedBalance.split(' ')[1] var beforeDecimal = balance.split('.')[0] var afterDecimal = balance.split('.')[1] - var shortBalance = shortenBalance(balance) + var shortBalance = shortenBalance(balance, decimalsToKeep) - if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') { balance = '< 0.00001' } + if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') { balance = '<1.0e-5' } return { balance, label, shortBalance } } -function shortenBalance (balance) { +function shortenBalance (balance, decimalsToKeep = 1) { var truncatedValue var convertedBalance = parseFloat(balance) if (convertedBalance > 1000000) { - truncatedValue = (balance / 1000000).toFixed(1) + truncatedValue = (balance / 1000000).toFixed(decimalsToKeep) return `>${truncatedValue}m` } else if (convertedBalance > 1000) { - truncatedValue = (balance / 1000).toFixed(1) + truncatedValue = (balance / 1000).toFixed(decimalsToKeep) return `>${truncatedValue}k` + } else if (convertedBalance < 1) { + var exponent = balance.match(/\.0*/)[0].length + truncatedValue = (convertedBalance * Math.pow(10, exponent)).toFixed(decimalsToKeep) + return `<${truncatedValue}e-${exponent}` } else { return balance } |