1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-11 20:27:12 +01:00
metamask-extension/ui/app/components/account-panel.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const Identicon = require('./identicon')
const formatBalance = require('../util').formatBalance
2016-06-17 03:37:39 +02:00
const addressSummary = require('../util').addressSummary
module.exports = AccountPanel
inherits(AccountPanel, Component)
2016-06-21 22:18:32 +02:00
function AccountPanel () {
Component.call(this)
}
2016-06-21 22:18:32 +02:00
AccountPanel.prototype.render = function () {
var state = this.props
var identity = state.identity || {}
var account = state.account || {}
var isFauceting = state.isFauceting
var panelState = {
key: `accountPanel${identity.address}`,
identiconKey: identity.address,
2016-07-07 02:58:46 +02:00
identiconLabel: identity.name || '',
attributes: [
{
key: 'ADDRESS',
2016-06-17 03:37:39 +02:00
value: addressSummary(identity.address),
},
balanceOrFaucetingIndication(account, isFauceting),
2016-06-21 22:18:32 +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-28 22:07:46 +02:00
h('span.font-small', panelState.identiconLabel.substring(0, 7) + '...'),
]),
// 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-06-21 22:18:32 +02:00
function balanceOrFaucetingIndication (account, isFauceting) {
// Temporarily deactivating isFauceting indication
// because it shows fauceting for empty restored accounts.
2016-06-21 22:18:32 +02:00
if (/* isFauceting*/ false) {
return {
key: 'Account is auto-funding.',
value: 'Please wait.',
}
} else {
return {
key: 'BALANCE',
2016-06-21 22:18:32 +02:00
value: formatBalance(account.balance),
}
}
}