nifty-wallet/old-ui/app/components/account-panel.js

106 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-11-14 08:04:23 -08:00
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const Identicon = require('./identicon')
const formatBalance = require('../util').formatBalance
const addressSummary = require('../util').addressSummary
module.exports = AccountPanel
inherits(AccountPanel, Component)
function AccountPanel () {
Component.call(this)
}
AccountPanel.prototype.render = function () {
2020-04-14 02:18:53 -07:00
const state = this.props
const identity = state.identity || {}
const account = state.account || {}
const isFauceting = state.isFauceting
2017-11-14 08:04:23 -08:00
2020-04-14 02:18:53 -07:00
const panelState = {
2017-11-14 08:04:23 -08:00
key: `accountPanel${identity.address}`,
identiconKey: identity.address,
identiconLabel: identity.name || '',
attributes: [
{
2018-08-07 14:28:23 -07:00
key: 'Address',
2019-06-12 13:58:58 -07:00
value: addressSummary(state.network, identity.address),
2017-11-14 08:04:23 -08:00
},
2018-07-19 04:12:21 -07:00
balanceOrFaucetingIndication(account, isFauceting, state.network),
2017-11-14 08:04:23 -08:00
],
}
return (
h('.identity-panel.flex-row.flex-space-between', {
style: {
2018-10-30 03:44:52 -07:00
background: ((state.style && state.style.background) || 'linear-gradient(rgb(84, 36, 147), rgb(104, 45, 182))'),
2018-08-07 14:28:23 -07:00
padding: '30px',
2017-11-14 08:04:23 -08:00
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,
imageify: state.imageifyIdenticons,
2018-08-07 14:28:23 -07:00
diameter: 60,
2017-11-14 08:04:23 -08:00
}),
]),
// account address, balance
h('.identity-data.flex-column.flex-justify-center.flex-grow.select-none', [
2018-08-07 14:28:23 -07:00
h('h2.font-medium', {
style: {
color: '#ffffff',
marginBottom: '20px',
lineHeight: '16px',
},
}, panelState.identiconLabel),
panelState.attributes.map((attr, i) => {
2017-11-14 08:04:23 -08:00
return h('.flex-row.flex-space-between', {
key: '' + Math.round(Math.random() * 1000000),
}, [
2018-08-07 14:28:23 -07:00
h('label.font-pre-medium.no-select', {
2018-07-26 11:15:51 -07:00
style: {
color: '#ffffff',
2018-08-07 14:28:23 -07:00
marginBottom: i === 0 ? '10px' : '0px',
lineHeight: '14px',
2018-07-27 09:54:23 -07:00
},
2018-07-26 11:15:51 -07:00
}, attr.key),
2018-08-07 14:28:23 -07:00
h('span.font-pre-medium', {
2018-07-26 11:15:51 -07:00
style: {
color: '#ffffff',
2018-08-07 14:28:23 -07:00
lineHeight: '14px',
2018-07-27 09:54:23 -07:00
},
2018-07-26 11:15:51 -07:00
}, attr.value),
2017-11-14 08:04:23 -08:00
])
}),
]),
])
)
}
2018-07-19 04:12:21 -07:00
function balanceOrFaucetingIndication (account, isFauceting, network) {
2017-11-14 08:04:23 -08:00
// Temporarily deactivating isFauceting indication
// because it shows fauceting for empty restored accounts.
if (/* isFauceting*/ false) {
return {
key: 'Account is auto-funding.',
value: 'Please wait.',
}
} else {
return {
2018-08-07 14:28:23 -07:00
key: 'Balance',
2018-07-19 04:12:21 -07:00
value: formatBalance(account.balance, undefined, undefined, network),
2017-11-14 08:04:23 -08:00
}
}
}