From 20bfb60fd2ef84630a6f653b5f360c96d924b004 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 8 Jul 2016 17:27:13 -0700 Subject: Implement alternate shortening scheme. --- ui/app/components/eth-balance-tx-history.js | 29 +++++++++++++++++++++++------ ui/app/components/transaction-list-item.js | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/ui/app/components/eth-balance-tx-history.js b/ui/app/components/eth-balance-tx-history.js index 81166bb45..ca065416a 100644 --- a/ui/app/components/eth-balance-tx-history.js +++ b/ui/app/components/eth-balance-tx-history.js @@ -15,6 +15,7 @@ EthBalanceComponent.prototype.render = function () { var state = this.props var style = state.style var value = formatBalance(state.value) + var maxWidth = state.maxWidth return ( h('.ether-balance', { @@ -23,19 +24,23 @@ EthBalanceComponent.prototype.render = function () { h('.ether-balance-amount', { style: { display: 'inline', - width: '55px', - overflow: 'hidden', + maxWidth: maxWidth, }, - }, this.renderBalance(value)), + }, this.renderBalance(value,state)), ]) ) } -EthBalanceComponent.prototype.renderBalance = function (value) { +EthBalanceComponent.prototype.renderBalance = function (value,state) { if (value === 'None') return value var balanceObj = generateBalanceObject(value) var balance = balanceObj.balance + + if (state.shorten) { + balance = shortenBalance(balance) + } + var label = balanceObj.label return ( @@ -54,8 +59,6 @@ EthBalanceComponent.prototype.renderBalance = function (value) { h('div', { style: { width: '100%', - overflow: 'hidden', - textOverflow: 'ellipsis', }, }, balance), h('div', { @@ -68,3 +71,17 @@ EthBalanceComponent.prototype.renderBalance = function (value) { ]) ) } + +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 + } +} diff --git a/ui/app/components/transaction-list-item.js b/ui/app/components/transaction-list-item.js index a41226343..4fa7b897c 100644 --- a/ui/app/components/transaction-list-item.js +++ b/ui/app/components/transaction-list-item.js @@ -73,6 +73,8 @@ TransactionListItem.prototype.render = function () { isTx ? h(EtherBalance, { value: txParams.value, + maxWidth: '55px', + shorten: true, }) : h('.flex-column'), ]) ) -- cgit v1.2.3