1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/accounts/index.js

156 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-05-23 23:48:01 +02:00
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('../actions')
const valuesFor = require('../util').valuesFor
const findDOMNode = require('react-dom').findDOMNode
const AccountListItem = require('./account-list-item')
2016-05-23 23:48:01 +02:00
module.exports = connect(mapStateToProps)(AccountsScreen)
2016-06-21 22:18:32 +02:00
function mapStateToProps (state) {
const pendingTxs = valuesFor(state.metamask.unconfTxs)
const pendingMsgs = valuesFor(state.metamask.unconfMsgs)
const pending = pendingTxs.concat(pendingMsgs)
2016-05-23 23:48:01 +02:00
return {
accounts: state.metamask.accounts,
identities: state.metamask.identities,
unconfTxs: state.metamask.unconfTxs,
selectedAddress: state.metamask.selectedAddress,
currentDomain: state.appState.currentDomain,
scrollToBottom: state.appState.scrollToBottom,
pending,
2016-05-23 23:48:01 +02:00
}
}
inherits(AccountsScreen, Component)
2016-06-21 22:18:32 +02:00
function AccountsScreen () {
2016-05-23 23:48:01 +02:00
Component.call(this)
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.render = function () {
2016-05-23 23:48:01 +02:00
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),
goHome: this.goHome.bind(this),
}
return (
h('.accounts-section.flex-grow', [
// subtitle and nav
h('.section-title.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: actions.goHome,
}),
h('h2.page-subtitle', 'Select Account'),
]),
h('hr.horizontal-line'),
// identity selection
h('section.identity-section.flex-column', {
style: {
height: '418px',
overflowY: 'auto',
overflowX: 'hidden',
2016-06-21 22:18:32 +02:00
},
2016-05-23 23:48:01 +02:00
},
2016-06-21 22:18:32 +02:00
[
identityList.map((identity) => {
const pending = this.props.pending.filter((txOrMsg) => {
if ('txParams' in txOrMsg) {
return txOrMsg.txParams.from === identity.address
} else if ('msgParams' in txOrMsg) {
return txOrMsg.msgParams.from === identity.address
} else {
return false
}
})
return h(AccountListItem, {
2016-06-21 22:18:32 +02:00
key: `acct-panel-${identity.address}`,
identity,
selectedAddress: this.props.selectedAddress,
accounts: this.props.accounts,
onShowDetail: this.onShowDetail.bind(this),
pending,
})
}),
h('hr.horizontal-line', {key: 'horizontal-line1'}),
h('div.footer.hover-white.pointer', {
key: 'reveal-account-bar',
onClick: () => {
2016-07-22 03:08:35 +02:00
this.onRevealAccount()
2016-06-21 22:18:32 +02:00
},
style: {
display: 'flex',
flex: '1 0 auto',
height: '40px',
paddint: '10px',
justifyContent: 'center',
alignItems: 'center',
},
}, [
h('i.fa.fa-plus.fa-lg', {key: ''}),
]),
2016-05-23 23:48:01 +02:00
]),
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
),
])
)
}
// If a new account was revealed, scroll to the bottom
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.componentDidUpdate = function () {
2016-05-23 23:48:01 +02:00
const scrollToBottom = this.props.scrollToBottom
if (scrollToBottom) {
var container = findDOMNode(this)
var scrollable = container.querySelector('.identity-section')
scrollable.scrollTop = scrollable.scrollHeight
}
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.navigateToConfTx = function () {
2016-05-23 23:48:01 +02:00
event.stopPropagation()
this.props.dispatch(actions.showConfTxPage())
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.onSelect = function (address, event) {
2016-05-23 23:48:01 +02:00
event.stopPropagation()
// if already selected, deselect
if (this.props.selectedAddress === address) address = null
this.props.dispatch(actions.setSelectedAddress(address))
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.onShowDetail = function (address, event) {
2016-05-23 23:48:01 +02:00
event.stopPropagation()
this.props.dispatch(actions.showAccountDetail(address))
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.onRevealAccount = function () {
2016-05-23 23:48:01 +02:00
this.props.dispatch(actions.revealAccount())
}
2016-06-21 22:18:32 +02:00
AccountsScreen.prototype.goHome = function () {
2016-05-23 23:48:01 +02:00
this.props.dispatch(actions.goHome())
}