aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/util.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-05-19 04:41:08 +0800
committerkumavis <aaron@kumavis.me>2016-05-19 04:41:08 +0800
commit6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5 (patch)
tree59c931ca7b791f9ee2d55133a9fd4db629327afe /ui/app/util.js
parent877648623e0b483d05291379b17d5a6646375b34 (diff)
downloadtangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar.gz
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar.bz2
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar.lz
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar.xz
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.tar.zst
tangerine-wallet-browser-6ae0a90d7b9ee3bfca359c1291efe86c5142c7b5.zip
ui - redesign - ether amount component
Diffstat (limited to 'ui/app/util.js')
-rw-r--r--ui/app/util.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/ui/app/util.js b/ui/app/util.js
index 5dbcffa7e..0f3f191aa 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -22,6 +22,7 @@ module.exports = {
valuesFor: valuesFor,
addressSummary: addressSummary,
numericBalance: numericBalance,
+ parseBalance: parseBalance,
formatBalance: formatBalance,
dataSize: dataSize,
readableDate: readableDate,
@@ -65,16 +66,30 @@ function weiToEth(bn) {
return eth
}
-var decimalsToKeep = 4
-function formatBalance(balance) {
- if (!balance || balance === '0x0') return 'None'
+// Takes hex, returns [beforeDecimal, afterDecimal]
+function parseBalance(balance, decimalsToKeep) {
+ if (decimalsToKeep === undefined) decimalsToKeep = 4
+ if (!balance || balance === '0x0') return ['0', '']
var wei = numericBalance(balance)
var padded = wei.toString(10)
var len = padded.length
- var nonZeroIndex = padded.match(/[^0]/) && padded.match(/[^0]/).index
+ var match = padded.match(/[^0]/)
+ var nonZeroIndex = match && match.index
var beforeDecimal = padded.substr(nonZeroIndex ? nonZeroIndex : 0, len - 18) || '0'
var afterDecimal = padded.substr(len - 18, decimalsToKeep)
- return `${beforeDecimal}.${afterDecimal} ETH`
+ return [beforeDecimal, afterDecimal]
+}
+
+// Takes wei hex, returns "None" or "${formattedAmount} ETH"
+function formatBalance(balance) {
+ var parsed = parseBalance(balance)
+ var beforeDecimal = parsed[0]
+ var afterDecimal = parsed[1]
+ if (beforeDecimal === '0' && afterDecimal === '') return 'None'
+ var result = beforeDecimal
+ if (afterDecimal) result += '.'+afterDecimal
+ result += ' ETH'
+ return result
}
function dataSize(data) {