2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const extend = require('xtend')
|
2016-05-11 01:51:49 +02:00
|
|
|
const Identicon = require('identicon.js')
|
2016-04-14 00:28:44 +02:00
|
|
|
const actions = require('./actions')
|
|
|
|
const AccountPanel = require('./components/account-panel')
|
|
|
|
const valuesFor = require('./util').valuesFor
|
2016-05-11 01:51:49 +02:00
|
|
|
const addressSummary = require('./util').addressSummary
|
|
|
|
const formatBalance = require('./util').formatBalance
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(AccountsScreen)
|
|
|
|
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
accounts: state.metamask.accounts,
|
|
|
|
identities: state.metamask.identities,
|
|
|
|
unconfTxs: state.metamask.unconfTxs,
|
|
|
|
selectedAddress: state.metamask.selectedAddress,
|
|
|
|
currentDomain: state.appState.currentDomain,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(AccountsScreen, Component)
|
|
|
|
function AccountsScreen() {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AccountsScreen.prototype.render = function() {
|
|
|
|
var state = this.props
|
|
|
|
var identityList = valuesFor(state.identities)
|
|
|
|
var unconfTxList = valuesFor(state.unconfTxs)
|
|
|
|
var actions = {
|
|
|
|
onSelect: this.onSelect.bind(this),
|
|
|
|
onShowDetail: this.onShowDetail.bind(this),
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
|
|
|
|
h('.accounts-section.flex-column.flex-grow', [
|
|
|
|
|
|
|
|
// subtitle and nav
|
|
|
|
h('.section-title.flex-column.flex-center', [
|
2016-05-11 01:51:49 +02:00
|
|
|
h('h2.page-subtitle', 'Select Account'),
|
2016-04-14 00:28:44 +02:00
|
|
|
]),
|
|
|
|
|
2016-05-11 01:51:49 +02:00
|
|
|
h('hr.horizontal-line'),
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
// identity selection
|
|
|
|
h('section.identity-section.flex-column', {
|
|
|
|
style: {
|
|
|
|
overflowY: 'auto',
|
|
|
|
overflowX: 'hidden',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
identityList.map(renderAccountPanel)
|
|
|
|
),
|
|
|
|
|
|
|
|
unconfTxList.length ? (
|
|
|
|
|
|
|
|
h('.unconftx-link.flex-row.flex-center', {
|
|
|
|
onClick: this.navigateToConfTx.bind(this),
|
|
|
|
}, [
|
|
|
|
h('span', 'Unconfirmed Txs'),
|
|
|
|
h('i.fa.fa-arrow-right.fa-lg'),
|
|
|
|
])
|
|
|
|
|
|
|
|
) : (
|
|
|
|
null
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
function renderAccountPanel(identity){
|
|
|
|
var mayBeFauceting = identity.mayBeFauceting
|
|
|
|
var isSelected = state.selectedAddress === identity.address
|
|
|
|
var account = state.accounts[identity.address]
|
|
|
|
var isFauceting = mayBeFauceting && account.balance === '0x0'
|
|
|
|
var componentState = extend(actions, {
|
|
|
|
identity: identity,
|
|
|
|
account: account,
|
2016-04-30 00:53:29 +02:00
|
|
|
isSelected: false,
|
2016-04-14 00:28:44 +02:00
|
|
|
isFauceting: isFauceting,
|
|
|
|
})
|
2016-05-11 01:51:49 +02:00
|
|
|
// return h(AccountPanel, componentState)
|
|
|
|
|
|
|
|
// var identity = state.identity || {}
|
|
|
|
// var account = state.account || {}
|
|
|
|
// var isFauceting = state.isFauceting
|
|
|
|
|
|
|
|
var identicon = new Identicon(identity.address, 46).toString()
|
|
|
|
var identiconSrc = `data:image/png;base64,${identicon}`
|
|
|
|
|
|
|
|
return (
|
2016-05-11 02:22:09 +02:00
|
|
|
h('.accounts-list-option.flex-row.flex-space-between.cursor-pointer', {
|
2016-05-11 01:51:49 +02:00
|
|
|
style: {
|
|
|
|
flex: '1 0 auto',
|
|
|
|
background: isSelected ? 'white' : 'none',
|
|
|
|
},
|
2016-05-11 02:22:09 +02:00
|
|
|
onClick: (event) => actions.onShowDetail(identity.address, event),
|
2016-05-11 01:51:49 +02:00
|
|
|
}, [
|
|
|
|
|
|
|
|
// account identicon
|
|
|
|
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
|
|
|
h('img.identicon', {
|
|
|
|
src: identiconSrc,
|
|
|
|
style: {
|
|
|
|
border: 'none',
|
|
|
|
borderRadius: '20px',
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
// account address, balance
|
|
|
|
h('.identity-data.flex-column.flex-justify-center.flex-grow.select-none', [
|
|
|
|
|
|
|
|
h('span', identity.name),
|
|
|
|
h('span.font-small', addressSummary(identity.address)),
|
|
|
|
h('span.font-small', formatBalance(account.balance)),
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
])
|
|
|
|
)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountsScreen.prototype.navigateToConfTx = function(){
|
|
|
|
event.stopPropagation()
|
|
|
|
this.props.dispatch(actions.showConfTxPage())
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountsScreen.prototype.onSelect = function(address, event){
|
|
|
|
event.stopPropagation()
|
|
|
|
// if already selected, deselect
|
|
|
|
if (this.props.selectedAddress === address) address = null
|
|
|
|
this.props.dispatch(actions.setSelectedAddress(address))
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountsScreen.prototype.onShowDetail = function(address, event){
|
|
|
|
event.stopPropagation()
|
|
|
|
this.props.dispatch(actions.showAccountDetail(address))
|
|
|
|
}
|