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:
parent
58ee3e1227
commit
20bfb60fd2
File diff suppressed because one or more lines are too long
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ TransactionListItem.prototype.render = function () {
|
||||
|
||||
isTx ? h(EtherBalance, {
|
||||
value: txParams.value,
|
||||
maxWidth: '55px',
|
||||
shorten: true,
|
||||
}) : h('.flex-column'),
|
||||
])
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user