1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Implement alternate shortening scheme.

This commit is contained in:
Kevin Serrano 2016-07-08 17:27:13 -07:00
parent 58ee3e1227
commit 20bfb60fd2
3 changed files with 26 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,7 @@ EthBalanceComponent.prototype.render = function () {
var state = this.props var state = this.props
var style = state.style var style = state.style
var value = formatBalance(state.value) var value = formatBalance(state.value)
var maxWidth = state.maxWidth
return ( return (
h('.ether-balance', { h('.ether-balance', {
@ -23,19 +24,23 @@ EthBalanceComponent.prototype.render = function () {
h('.ether-balance-amount', { h('.ether-balance-amount', {
style: { style: {
display: 'inline', display: 'inline',
width: '55px', maxWidth: maxWidth,
overflow: 'hidden',
}, },
}, this.renderBalance(value)), }, this.renderBalance(value,state)),
]) ])
) )
} }
EthBalanceComponent.prototype.renderBalance = function (value) { EthBalanceComponent.prototype.renderBalance = function (value,state) {
if (value === 'None') return value if (value === 'None') return value
var balanceObj = generateBalanceObject(value) var balanceObj = generateBalanceObject(value)
var balance = balanceObj.balance var balance = balanceObj.balance
if (state.shorten) {
balance = shortenBalance(balance)
}
var label = balanceObj.label var label = balanceObj.label
return ( return (
@ -54,8 +59,6 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
h('div', { h('div', {
style: { style: {
width: '100%', width: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
}, },
}, balance), }, balance),
h('div', { 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
}
}

View File

@ -73,6 +73,8 @@ TransactionListItem.prototype.render = function () {
isTx ? h(EtherBalance, { isTx ? h(EtherBalance, {
value: txParams.value, value: txParams.value,
maxWidth: '55px',
shorten: true,
}) : h('.flex-column'), }) : h('.flex-column'),
]) ])
) )