2016-05-23 23:56:34 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2016-05-24 00:31:11 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
|
2016-09-07 01:45:06 +02:00
|
|
|
const EthBalance = require('../components/eth-balance')
|
2016-06-29 23:11:31 +02:00
|
|
|
const CopyButton = require('../components/copyButton')
|
2016-05-24 00:31:11 +02:00
|
|
|
const Identicon = require('../components/identicon')
|
2016-05-23 23:56:34 +02:00
|
|
|
|
2016-09-12 23:22:06 +02:00
|
|
|
module.exports = AccountListItem
|
2016-05-23 23:56:34 +02:00
|
|
|
|
2016-09-12 23:22:06 +02:00
|
|
|
inherits(AccountListItem, Component)
|
|
|
|
function AccountListItem () {
|
2016-05-23 23:56:34 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-09-12 23:22:06 +02:00
|
|
|
AccountListItem.prototype.render = function () {
|
2016-12-23 02:17:20 +01:00
|
|
|
const { identity, selectedAccount, accounts, onShowDetail } = this.props
|
|
|
|
|
|
|
|
const isSelected = selectedAccount === identity.address
|
|
|
|
const account = accounts[identity.address]
|
2016-05-24 00:31:11 +02:00
|
|
|
const selectedClass = isSelected ? '.selected' : ''
|
2016-05-23 23:56:34 +02:00
|
|
|
|
|
|
|
return (
|
2016-05-24 00:31:11 +02:00
|
|
|
h(`.accounts-list-option.flex-row.flex-space-between.pointer.hover-white${selectedClass}`, {
|
|
|
|
key: `account-panel-${identity.address}`,
|
2016-12-23 02:17:20 +01:00
|
|
|
onClick: (event) => onShowDetail(identity.address, event),
|
2016-05-24 00:31:11 +02:00
|
|
|
}, [
|
|
|
|
|
|
|
|
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
2016-05-26 01:54:43 +02:00
|
|
|
this.pendingOrNot(),
|
2016-12-23 02:17:20 +01:00
|
|
|
this.indicateIfLoose(),
|
2016-05-24 00:31:11 +02:00
|
|
|
h(Identicon, {
|
2016-06-21 22:18:32 +02:00
|
|
|
address: identity.address,
|
2016-06-24 01:18:47 +02:00
|
|
|
imageify: true,
|
2016-05-24 00:31:11 +02:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
// account address, balance
|
2016-06-15 00:24:47 +02:00
|
|
|
h('.identity-data.flex-column.flex-justify-center.flex-grow.select-none', {
|
|
|
|
style: {
|
|
|
|
width: '200px',
|
|
|
|
},
|
|
|
|
}, [
|
2016-05-24 00:31:11 +02:00
|
|
|
h('span', identity.name),
|
2016-06-15 00:24:47 +02:00
|
|
|
h('span.font-small', {
|
|
|
|
style: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
},
|
|
|
|
}, ethUtil.toChecksumAddress(identity.address)),
|
2016-09-07 01:45:06 +02:00
|
|
|
h(EthBalance, {
|
2016-12-24 02:22:46 +01:00
|
|
|
value: account && account.balance,
|
2016-08-16 23:13:03 +02:00
|
|
|
style: {
|
|
|
|
lineHeight: '7px',
|
|
|
|
marginTop: '10px',
|
|
|
|
},
|
2016-05-24 00:31:11 +02:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
2016-06-15 00:24:47 +02:00
|
|
|
// copy button
|
|
|
|
h('.identity-copy.flex-column', {
|
|
|
|
style: {
|
|
|
|
margin: '0 20px',
|
|
|
|
},
|
|
|
|
}, [
|
2016-06-29 23:11:31 +02:00
|
|
|
h(CopyButton, {
|
|
|
|
value: ethUtil.toChecksumAddress(identity.address),
|
2016-05-24 00:31:11 +02:00
|
|
|
}),
|
2016-06-15 00:24:47 +02:00
|
|
|
]),
|
2016-05-24 00:31:11 +02:00
|
|
|
])
|
2016-05-23 23:56:34 +02:00
|
|
|
)
|
|
|
|
}
|
2016-05-26 01:54:43 +02:00
|
|
|
|
2016-12-23 02:17:20 +01:00
|
|
|
AccountListItem.prototype.indicateIfLoose = function () {
|
|
|
|
try { // Sometimes keyrings aren't loaded yet:
|
|
|
|
const type = this.props.keyring.type
|
|
|
|
const isLoose = type !== 'HD Key Tree'
|
2016-12-24 02:22:46 +01:00
|
|
|
return isLoose ? h('.keyring-label', 'LOOSE') : null
|
2016-12-23 02:17:20 +01:00
|
|
|
} catch (e) { return }
|
|
|
|
}
|
|
|
|
|
2016-09-12 23:22:06 +02:00
|
|
|
AccountListItem.prototype.pendingOrNot = function () {
|
2016-05-26 01:54:43 +02:00
|
|
|
const pending = this.props.pending
|
|
|
|
if (pending.length === 0) return null
|
|
|
|
return h('.pending-dot', pending.length)
|
|
|
|
}
|