2016-05-18 22:41:08 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2016-05-26 03:29:03 +02:00
|
|
|
const formatBalance = require('../util').formatBalance
|
2016-07-07 21:39:07 +02:00
|
|
|
const generateBalanceObject = require('../util').generateBalanceObject
|
2016-07-07 21:07:47 +02:00
|
|
|
const Tooltip = require('./tooltip.js')
|
2016-08-05 21:18:44 +02:00
|
|
|
|
2016-08-16 19:34:29 +02:00
|
|
|
module.exports = EthBalanceComponent
|
2016-08-05 21:18:44 +02:00
|
|
|
|
2016-05-18 22:41:08 +02:00
|
|
|
inherits(EthBalanceComponent, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function EthBalanceComponent () {
|
2016-05-18 22:41:08 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
EthBalanceComponent.prototype.render = function () {
|
2016-07-12 02:44:00 +02:00
|
|
|
var state = this.props
|
|
|
|
var style = state.style
|
2016-08-20 02:18:11 +02:00
|
|
|
var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
|
|
|
|
const value = formatBalance(state.value, 6, needsParse)
|
2016-07-12 02:44:00 +02:00
|
|
|
var width = state.width
|
2016-05-18 22:41:08 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
|
2016-08-19 01:30:13 +02:00
|
|
|
h('.ether-balance.ether-balance-amount', {
|
2016-05-18 22:41:08 +02:00
|
|
|
style: style,
|
|
|
|
}, [
|
2016-08-19 01:30:13 +02:00
|
|
|
h('div', {
|
2016-05-18 22:41:08 +02:00
|
|
|
style: {
|
|
|
|
display: 'inline',
|
2016-07-12 02:44:00 +02:00
|
|
|
width: width,
|
2016-05-18 22:41:08 +02:00
|
|
|
},
|
2016-08-20 02:18:11 +02:00
|
|
|
}, this.renderBalance(value)),
|
2016-05-18 22:41:08 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
2016-08-20 02:18:11 +02:00
|
|
|
EthBalanceComponent.prototype.renderBalance = function (value) {
|
|
|
|
var state = this.props
|
2016-06-30 20:15:32 +02:00
|
|
|
if (value === 'None') return value
|
2016-07-14 00:46:36 +02:00
|
|
|
var balanceObj = generateBalanceObject(value, state.shorten ? 1 : 3)
|
2016-07-12 02:44:00 +02:00
|
|
|
var balance
|
2016-08-05 21:18:44 +02:00
|
|
|
var splitBalance = value.split(' ')
|
|
|
|
var ethNumber = splitBalance[0]
|
|
|
|
var ethSuffix = splitBalance[1]
|
2016-07-12 02:44:00 +02:00
|
|
|
|
|
|
|
if (state.shorten) {
|
|
|
|
balance = balanceObj.shortBalance
|
|
|
|
} else {
|
|
|
|
balance = balanceObj.balance
|
|
|
|
}
|
|
|
|
|
2016-07-07 21:07:47 +02:00
|
|
|
var label = balanceObj.label
|
2016-06-30 20:15:32 +02:00
|
|
|
|
|
|
|
return (
|
2016-07-07 21:07:47 +02:00
|
|
|
h(Tooltip, {
|
|
|
|
position: 'bottom',
|
2016-08-16 19:34:29 +02:00
|
|
|
title: `${ethNumber} ${ethSuffix}`,
|
2016-06-30 21:43:28 +02:00
|
|
|
}, [
|
2016-07-12 02:44:00 +02:00
|
|
|
h('.flex-column', {
|
2016-06-30 21:43:28 +02:00
|
|
|
style: {
|
2016-07-07 21:07:47 +02:00
|
|
|
alignItems: 'flex-end',
|
2016-07-12 02:44:00 +02:00
|
|
|
lineHeight: '13px',
|
|
|
|
fontFamily: 'Montserrat Light',
|
2016-07-07 21:07:47 +02:00
|
|
|
textRendering: 'geometricPrecision',
|
2016-07-07 21:41:07 +02:00
|
|
|
},
|
2016-07-07 21:07:47 +02:00
|
|
|
}, [
|
2016-07-12 02:44:00 +02:00
|
|
|
h('div', {
|
2016-07-07 22:41:32 +02:00
|
|
|
style: {
|
2016-07-12 02:44:00 +02:00
|
|
|
width: '100%',
|
|
|
|
textAlign: 'right',
|
2016-07-07 22:41:32 +02:00
|
|
|
},
|
2016-08-20 02:18:11 +02:00
|
|
|
}, this.props.incoming ? `+${balance}` : balance),
|
2016-07-12 02:44:00 +02:00
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
color: ' #AEAEAE',
|
|
|
|
fontSize: '12px',
|
|
|
|
},
|
|
|
|
}, label),
|
2016-07-07 22:45:06 +02:00
|
|
|
]),
|
2016-06-30 20:15:32 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|