From 0a6560bd5dcadd9dbdb96546b9273be0bb063916 Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 7 Jul 2016 12:07:47 -0700 Subject: [PATCH 1/2] Add method to deal with small decimals and create the object for eth-balance component --- ui/app/components/eth-balance.js | 39 ++++++++++++++++++-------------- ui/app/util.js | 12 ++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/ui/app/components/eth-balance.js b/ui/app/components/eth-balance.js index c7240ea21..e68c7b4db 100644 --- a/ui/app/components/eth-balance.js +++ b/ui/app/components/eth-balance.js @@ -2,7 +2,8 @@ const Component = require('react').Component const h = require('react-hyperscript') const inherits = require('util').inherits const formatBalance = require('../util').formatBalance - +const mainBalanceObject = require('../util').mainBalanceObject +const Tooltip = require('./tooltip.js') module.exports = EthBalanceComponent inherits(EthBalanceComponent, Component) @@ -14,7 +15,6 @@ EthBalanceComponent.prototype.render = function () { var state = this.props var style = state.style var value = formatBalance(state.value) - return ( h('.ether-balance', { @@ -30,28 +30,33 @@ EthBalanceComponent.prototype.render = function () { ) } EthBalanceComponent.prototype.renderBalance = function (value) { - if (value === 'None') return value + var balanceObj = mainBalanceObject(value) - var balance = value.split(' ')[0] - var label = value.split(' ')[1] + var balance = balanceObj.balance + var label = balanceObj.label return ( - h('.flex-column', { - style: { - alignItems: 'flex-end', - lineHeight: '13px', - fontFamily: 'Montserrat Thin', - textRendering: 'geometricPrecision', - }, + h(Tooltip, { + position: 'bottom', + title: value.split(' ')[0], }, [ - h('div', balance), - h('div', { + h('.flex-column', { style: { - color: ' #AEAEAE', - fontSize: '12px', + alignItems: 'flex-end', + lineHeight: '13px', + fontFamily: 'Montserrat Light', + textRendering: 'geometricPrecision', }, - }, label), + }, [ + h('div', balance), + h('div', { + style: { + color: ' #AEAEAE', + fontSize: '12px', + }, + }, label), + ]), ]) ) } diff --git a/ui/app/util.js b/ui/app/util.js index db12a1282..d686cf2c3 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -26,6 +26,7 @@ module.exports = { numericBalance: numericBalance, parseBalance: parseBalance, formatBalance: formatBalance, + mainBalanceObject: mainBalanceObject, dataSize: dataSize, readableDate: readableDate, ethToWei: ethToWei, @@ -117,6 +118,17 @@ function formatBalance (balance, decimalsToKeep) { return formatted } +function mainBalanceObject (formattedBalance) { + var balance = formattedBalance.split(' ')[0] + var label = formattedBalance.split(' ')[1] + var beforeDecimal = balance.split('.')[0] + var afterDecimal = balance.split('.')[1] + + if (beforeDecimal === '0' && afterDecimal.substr(0, 5) === '00000') { balance = '< 0.00001' } + + return { balance, label } +} + function dataSize (data) { var size = data ? ethUtil.stripHexPrefix(data).length : 0 return size + ' bytes' From cd8ae4b5ff5405e4129df897559cc35066492ea7 Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 7 Jul 2016 12:39:07 -0700 Subject: [PATCH 2/2] Change function name to generateBalanceObject --- ui/app/components/eth-balance.js | 4 ++-- ui/app/util.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/app/components/eth-balance.js b/ui/app/components/eth-balance.js index e68c7b4db..e31b3ed97 100644 --- a/ui/app/components/eth-balance.js +++ b/ui/app/components/eth-balance.js @@ -2,7 +2,7 @@ const Component = require('react').Component const h = require('react-hyperscript') const inherits = require('util').inherits const formatBalance = require('../util').formatBalance -const mainBalanceObject = require('../util').mainBalanceObject +const generateBalanceObject = require('../util').generateBalanceObject const Tooltip = require('./tooltip.js') module.exports = EthBalanceComponent @@ -31,7 +31,7 @@ EthBalanceComponent.prototype.render = function () { } EthBalanceComponent.prototype.renderBalance = function (value) { if (value === 'None') return value - var balanceObj = mainBalanceObject(value) + var balanceObj = generateBalanceObject(value) var balance = balanceObj.balance var label = balanceObj.label diff --git a/ui/app/util.js b/ui/app/util.js index d686cf2c3..befb2aad8 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -26,7 +26,7 @@ module.exports = { numericBalance: numericBalance, parseBalance: parseBalance, formatBalance: formatBalance, - mainBalanceObject: mainBalanceObject, + generateBalanceObject: generateBalanceObject, dataSize: dataSize, readableDate: readableDate, ethToWei: ethToWei, @@ -118,7 +118,7 @@ function formatBalance (balance, decimalsToKeep) { return formatted } -function mainBalanceObject (formattedBalance) { +function generateBalanceObject (formattedBalance) { var balance = formattedBalance.split(' ')[0] var label = formattedBalance.split(' ')[1] var beforeDecimal = balance.split('.')[0]