mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add method to deal with small decimals and create the object for eth-balance component
This commit is contained in:
parent
bbc7d222d8
commit
0a6560bd5d
@ -2,7 +2,8 @@ const Component = require('react').Component
|
|||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const formatBalance = require('../util').formatBalance
|
const formatBalance = require('../util').formatBalance
|
||||||
|
const mainBalanceObject = require('../util').mainBalanceObject
|
||||||
|
const Tooltip = require('./tooltip.js')
|
||||||
module.exports = EthBalanceComponent
|
module.exports = EthBalanceComponent
|
||||||
|
|
||||||
inherits(EthBalanceComponent, Component)
|
inherits(EthBalanceComponent, Component)
|
||||||
@ -14,7 +15,6 @@ 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)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
h('.ether-balance', {
|
h('.ether-balance', {
|
||||||
@ -30,28 +30,33 @@ EthBalanceComponent.prototype.render = function () {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
EthBalanceComponent.prototype.renderBalance = function (value) {
|
EthBalanceComponent.prototype.renderBalance = function (value) {
|
||||||
|
|
||||||
if (value === 'None') return value
|
if (value === 'None') return value
|
||||||
|
var balanceObj = mainBalanceObject(value)
|
||||||
|
|
||||||
var balance = value.split(' ')[0]
|
var balance = balanceObj.balance
|
||||||
var label = value.split(' ')[1]
|
var label = balanceObj.label
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('.flex-column', {
|
h(Tooltip, {
|
||||||
style: {
|
position: 'bottom',
|
||||||
alignItems: 'flex-end',
|
title: value.split(' ')[0],
|
||||||
lineHeight: '13px',
|
|
||||||
fontFamily: 'Montserrat Thin',
|
|
||||||
textRendering: 'geometricPrecision',
|
|
||||||
},
|
|
||||||
}, [
|
}, [
|
||||||
h('div', balance),
|
h('.flex-column', {
|
||||||
h('div', {
|
|
||||||
style: {
|
style: {
|
||||||
color: ' #AEAEAE',
|
alignItems: 'flex-end',
|
||||||
fontSize: '12px',
|
lineHeight: '13px',
|
||||||
|
fontFamily: 'Montserrat Light',
|
||||||
|
textRendering: 'geometricPrecision',
|
||||||
},
|
},
|
||||||
}, label),
|
}, [
|
||||||
|
h('div', balance),
|
||||||
|
h('div', {
|
||||||
|
style: {
|
||||||
|
color: ' #AEAEAE',
|
||||||
|
fontSize: '12px',
|
||||||
|
},
|
||||||
|
}, label),
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ module.exports = {
|
|||||||
numericBalance: numericBalance,
|
numericBalance: numericBalance,
|
||||||
parseBalance: parseBalance,
|
parseBalance: parseBalance,
|
||||||
formatBalance: formatBalance,
|
formatBalance: formatBalance,
|
||||||
|
mainBalanceObject: mainBalanceObject,
|
||||||
dataSize: dataSize,
|
dataSize: dataSize,
|
||||||
readableDate: readableDate,
|
readableDate: readableDate,
|
||||||
ethToWei: ethToWei,
|
ethToWei: ethToWei,
|
||||||
@ -117,6 +118,17 @@ function formatBalance (balance, decimalsToKeep) {
|
|||||||
return formatted
|
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) {
|
function dataSize (data) {
|
||||||
var size = data ? ethUtil.stripHexPrefix(data).length : 0
|
var size = data ? ethUtil.stripHexPrefix(data).length : 0
|
||||||
return size + ' bytes'
|
return size + ' bytes'
|
||||||
|
Loading…
Reference in New Issue
Block a user