2016-08-16 19:34:29 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const formatBalance = require('../util').formatBalance
|
|
|
|
const generateBalanceObject = require('../util').generateBalanceObject
|
|
|
|
const Tooltip = require('./tooltip.js')
|
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(EthBalanceComponent)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
conversionRate: state.metamask.conversionRate,
|
|
|
|
conversionDate: state.metamask.conversionDate,
|
|
|
|
currentFiat: state.metamask.currentFiat,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(EthBalanceComponent, Component)
|
|
|
|
function EthBalanceComponent () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
EthBalanceComponent.prototype.render = function () {
|
|
|
|
var state = this.props
|
|
|
|
var style = state.style
|
|
|
|
|
|
|
|
const value = formatBalance(state.value, 6)
|
|
|
|
var width = state.width
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
h('.ether-balance', {
|
|
|
|
style: style,
|
|
|
|
}, [
|
|
|
|
h('.ether-balance-amount', {
|
|
|
|
style: {
|
|
|
|
display: 'inline',
|
|
|
|
width: width,
|
|
|
|
},
|
|
|
|
}, this.renderBalance(value, state)),
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
EthBalanceComponent.prototype.renderBalance = function (value, state) {
|
|
|
|
if (value === 'None') return value
|
|
|
|
var balanceObj = generateBalanceObject(value, state.shorten ? 1 : 3)
|
2016-08-19 00:59:37 +02:00
|
|
|
var balance, fiatDisplayNumber, fiatTooltipNumber
|
2016-08-16 19:34:29 +02:00
|
|
|
var splitBalance = value.split(' ')
|
|
|
|
var ethNumber = splitBalance[0]
|
|
|
|
var ethSuffix = splitBalance[1]
|
2016-08-16 23:49:21 +02:00
|
|
|
|
2016-08-16 23:51:55 +02:00
|
|
|
|
2016-08-17 00:11:40 +02:00
|
|
|
if (state.conversionRate !== 0) {
|
2016-08-19 00:59:37 +02:00
|
|
|
fiatTooltipNumber = Number(splitBalance[0]) * state.conversionRate
|
|
|
|
fiatDisplayNumber = fiatTooltipNumber.toFixed(2)
|
2016-08-16 23:49:21 +02:00
|
|
|
} else {
|
2016-08-19 00:59:37 +02:00
|
|
|
fiatDisplayNumber = 'N/A'
|
2016-08-16 23:49:21 +02:00
|
|
|
}
|
|
|
|
|
2016-08-16 19:34:29 +02:00
|
|
|
var fiatSuffix = state.currentFiat
|
|
|
|
|
|
|
|
if (state.shorten) {
|
|
|
|
balance = balanceObj.shortBalance
|
|
|
|
} else {
|
|
|
|
balance = balanceObj.balance
|
|
|
|
}
|
|
|
|
|
|
|
|
var label = balanceObj.label
|
|
|
|
|
|
|
|
return (
|
|
|
|
h('.flex-column', [
|
|
|
|
h(Tooltip, {
|
|
|
|
position: 'bottom',
|
2016-08-16 19:48:31 +02:00
|
|
|
title: `${ethNumber} ${ethSuffix}`,
|
2016-08-16 19:34:29 +02:00
|
|
|
}, [
|
|
|
|
h('.flex-row', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
lineHeight: '13px',
|
|
|
|
fontFamily: 'Montserrat Light',
|
|
|
|
textRendering: 'geometricPrecision',
|
|
|
|
marginBottom: '5px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
width: '100%',
|
|
|
|
textAlign: 'right',
|
|
|
|
},
|
|
|
|
}, balance),
|
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
color: '#AEAEAE',
|
|
|
|
marginLeft: '5px',
|
|
|
|
},
|
|
|
|
}, label),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
h(Tooltip, {
|
|
|
|
position: 'bottom',
|
2016-08-19 00:59:37 +02:00
|
|
|
title: `${fiatTooltipNumber} ${fiatSuffix}`,
|
2016-08-16 19:34:29 +02:00
|
|
|
}, [
|
2016-08-19 00:59:37 +02:00
|
|
|
fiatDisplay(fiatDisplayNumber, fiatSuffix),
|
2016-08-16 19:34:29 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
2016-08-16 23:49:21 +02:00
|
|
|
|
2016-08-19 00:59:37 +02:00
|
|
|
function fiatDisplay (fiatDisplayNumber, fiatSuffix) {
|
|
|
|
if (fiatDisplayNumber !== 'N/A') {
|
2016-08-16 23:49:21 +02:00
|
|
|
return h('.flex-row', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
lineHeight: '13px',
|
|
|
|
fontFamily: 'Montserrat Light',
|
|
|
|
textRendering: 'geometricPrecision',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
width: '100%',
|
|
|
|
textAlign: 'right',
|
|
|
|
fontSize: '12px',
|
|
|
|
color: '#333333',
|
|
|
|
},
|
2016-08-19 00:59:37 +02:00
|
|
|
}, fiatDisplayNumber),
|
2016-08-16 23:49:21 +02:00
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
color: '#AEAEAE',
|
|
|
|
marginLeft: '5px',
|
|
|
|
fontSize: '12px',
|
|
|
|
},
|
|
|
|
}, fiatSuffix),
|
|
|
|
])
|
|
|
|
} else {
|
|
|
|
return h('div')
|
|
|
|
}
|
|
|
|
}
|