1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/accounts/account-list-item.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-05-23 23:56:34 +02:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const ethUtil = require('ethereumjs-util')
const EthBalance = require('../components/eth-balance')
const CopyButton = require('../components/copyButton')
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 () {
const { identity, selectedAddress, accounts, onShowDetail,
conversionRate, currentCurrency } = this.props
const checksumAddress = identity && identity.address && ethUtil.toChecksumAddress(identity.address)
const isSelected = selectedAddress === identity.address
const account = accounts[identity.address]
const selectedClass = isSelected ? '.selected' : ''
2016-05-23 23:56:34 +02:00
return (
h(`.accounts-list-option.flex-row.flex-space-between.pointer.hover-white${selectedClass}`, {
key: `account-panel-${identity.address}`,
onClick: (event) => onShowDetail(identity.address, event),
}, [
h('.identicon-wrapper.flex-column.flex-center.select-none', [
this.pendingOrNot(),
this.indicateIfLoose(),
h(Identicon, {
2016-06-21 22:18:32 +02:00
address: identity.address,
imageify: true,
}),
]),
// account address, balance
h('.identity-data.flex-column.flex-justify-center.flex-grow.select-none', {
style: {
width: '200px',
},
}, [
h('span', identity.name),
h('span.font-small', {
style: {
overflow: 'hidden',
textOverflow: 'ellipsis',
},
}, checksumAddress),
h(EthBalance, {
2016-12-24 02:22:46 +01:00
value: account && account.balance,
currentCurrency,
conversionRate,
2016-08-16 23:13:03 +02:00
style: {
lineHeight: '7px',
marginTop: '10px',
},
}),
]),
// copy button
h('.identity-copy.flex-column', {
style: {
margin: '0 20px',
},
}, [
h(CopyButton, {
value: checksumAddress,
}),
]),
])
2016-05-23 23:56:34 +02: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
} catch (e) { return }
}
2016-09-12 23:22:06 +02:00
AccountListItem.prototype.pendingOrNot = function () {
const pending = this.props.pending
if (pending.length === 0) return null
return h('.pending-dot', pending.length)
}