2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
2016-06-24 01:28:57 +02:00
|
|
|
const Identicon = require('./identicon')
|
2016-04-14 00:28:44 +02:00
|
|
|
const formatBalance = require('../util').formatBalance
|
2016-06-17 03:37:39 +02:00
|
|
|
const addressSummary = require('../util').addressSummary
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
module.exports = AccountPanel
|
|
|
|
|
2016-06-24 01:28:57 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
inherits(AccountPanel, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function AccountPanel () {
|
2016-04-14 00:28:44 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
AccountPanel.prototype.render = function () {
|
2016-04-14 00:28:44 +02:00
|
|
|
var state = this.props
|
|
|
|
var identity = state.identity || {}
|
|
|
|
var account = state.account || {}
|
|
|
|
var isFauceting = state.isFauceting
|
|
|
|
|
2016-06-24 01:28:57 +02:00
|
|
|
var panelState = {
|
2016-05-06 23:24:01 +02:00
|
|
|
key: `accountPanel${identity.address}`,
|
|
|
|
identiconKey: identity.address,
|
2016-07-07 02:58:46 +02:00
|
|
|
identiconLabel: identity.name || '',
|
2016-05-06 23:24:01 +02:00
|
|
|
attributes: [
|
|
|
|
{
|
|
|
|
key: 'ADDRESS',
|
2016-06-17 03:37:39 +02:00
|
|
|
value: addressSummary(identity.address),
|
2016-04-14 00:28:44 +02:00
|
|
|
},
|
2016-05-06 23:24:01 +02:00
|
|
|
balanceOrFaucetingIndication(account, isFauceting),
|
2016-06-21 22:18:32 +02:00
|
|
|
],
|
2016-05-06 23:24:01 +02:00
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2016-06-24 01:28:57 +02:00
|
|
|
return (
|
|
|
|
|
|
|
|
h('.identity-panel.flex-row.flex-space-between', {
|
|
|
|
style: {
|
|
|
|
flex: '1 0 auto',
|
|
|
|
cursor: panelState.onClick ? 'pointer' : undefined,
|
|
|
|
},
|
|
|
|
onClick: panelState.onClick,
|
|
|
|
}, [
|
|
|
|
|
|
|
|
// account identicon
|
|
|
|
h('.identicon-wrapper.flex-column.select-none', [
|
|
|
|
h(Identicon, {
|
|
|
|
address: panelState.identiconKey,
|
2016-06-24 21:48:52 +02:00
|
|
|
imageify: state.imageifyIdenticons,
|
2016-06-24 01:28:57 +02:00
|
|
|
}),
|
2016-06-28 22:07:46 +02:00
|
|
|
h('span.font-small', panelState.identiconLabel.substring(0, 7) + '...'),
|
2016-06-24 01:28:57 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
// account address, balance
|
|
|
|
h('.identity-data.flex-column.flex-justify-center.flex-grow.select-none', [
|
|
|
|
|
|
|
|
panelState.attributes.map((attr) => {
|
|
|
|
return h('.flex-row.flex-space-between', {
|
|
|
|
key: '' + Math.round(Math.random() * 1000000),
|
|
|
|
}, [
|
|
|
|
h('label.font-small.no-select', attr.key),
|
|
|
|
h('span.font-small', attr.value),
|
|
|
|
])
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function balanceOrFaucetingIndication (account, isFauceting) {
|
2016-04-14 00:28:44 +02:00
|
|
|
// Temporarily deactivating isFauceting indication
|
|
|
|
// because it shows fauceting for empty restored accounts.
|
2016-06-21 22:18:32 +02:00
|
|
|
if (/* isFauceting*/ false) {
|
2016-05-06 23:24:01 +02:00
|
|
|
return {
|
|
|
|
key: 'Account is auto-funding.',
|
|
|
|
value: 'Please wait.',
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
} else {
|
2016-05-06 23:24:01 +02:00
|
|
|
return {
|
|
|
|
key: 'BALANCE',
|
2016-06-21 22:18:32 +02:00
|
|
|
value: formatBalance(account.balance),
|
2016-05-06 23:24:01 +02:00
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|