aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/util.js
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-07-12 07:31:12 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-07-12 07:31:12 +0800
commit6a61591dad48f20502a64ad22a8d54e18a0a1d21 (patch)
treebb162c0070201350ac98af1f2d9d7d46d1f08634 /ui/app/util.js
parent37f21cf18f3495b255d25cfe57c2cbf495ba6b69 (diff)
downloadtangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar.gz
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar.bz2
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar.lz
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar.xz
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.tar.zst
tangerine-wallet-browser-6a61591dad48f20502a64ad22a8d54e18a0a1d21.zip
Move shorten balance to util. Add as property of generateBalance object output.
Diffstat (limited to 'ui/app/util.js')
-rw-r--r--ui/app/util.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/ui/app/util.js b/ui/app/util.js
index 216ded49f..0d57f1f96 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -85,7 +85,6 @@ function parseBalance (balance) {
const trailingZeros = /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]
@@ -115,15 +114,31 @@ function formatBalance (balance, decimalsToKeep) {
return formatted
}
+
function generateBalanceObject (formattedBalance) {
var balance = formattedBalance.split(' ')[0]
var label = formattedBalance.split(' ')[1]
var beforeDecimal = balance.split('.')[0]
var afterDecimal = balance.split('.')[1]
+ var shortBalance = shortenBalance(balance)
if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') { balance = '< 0.00001' }
- return { balance, label }
+ return { balance, label, shortBalance }
+}
+
+function shortenBalance (balance) {
+ var truncatedValue
+ var convertedBalance = parseFloat(balance)
+ if (convertedBalance > 1000000) {
+ truncatedValue = (balance / 1000000).toFixed(1)
+ return `>${truncatedValue}m`
+ } else if (convertedBalance > 1000) {
+ truncatedValue = (balance / 1000).toFixed(1)
+ return `>${truncatedValue}k`
+ } else {
+ return balance
+ }
}
function dataSize (data) {