1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/accounts/index.js

165 lines
4.8 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.unapprovedTxs)
.filter(txMeta => txMeta.metamaskNetworkId === state.metamask.network)
const pendingMsgs = valuesFor(state.metamask.unapprovedMsgs)
const pending = pendingTxs.concat(pendingMsgs)
2016-05-23 23:48:01 +02:00
return {
accounts: state.metamask.accounts,
identities: state.metamask.identities,
unapprovedTxs: state.metamask.unapprovedTxs,
selectedAddress: state.metamask.selectedAddress,
2016-05-23 23:48:01 +02:00
scrollToBottom: state.appState.scrollToBottom,
pending,
keyrings: state.metamask.keyrings,
conversionRate: state.metamask.conversionRate,
currentCurrency: state.metamask.currentCurrency,
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 () {
const props = this.props
const { keyrings, conversionRate, currentCurrency } = props
const identityList = valuesFor(props.identities)
const unapprovedTxList = valuesFor(props.unapprovedTxs)
2016-11-04 18:48:24 +01:00
2016-05-23 23:48:01 +02:00
return (
h('.accounts-section.flex-grow', [
// subtitle and nav
h('.section-title.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
2016-11-04 18:48:24 +01:00
onClick: this.goHome.bind(this),
2016-05-23 23:48:01 +02:00
}),
h('h2.page-subtitle', 'Select Account'),
]),
h('hr.horizontal-line'),
// identity selection
h('section.identity-section', {
2016-05-23 23:48:01 +02:00
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
}
})
const simpleAddress = identity.address.substring(2).toLowerCase()
const keyring = keyrings.find((kr) => {
return kr.accounts.includes(simpleAddress) ||
kr.accounts.includes(identity.address)
})
return h(AccountListItem, {
2016-06-21 22:18:32 +02:00
key: `acct-panel-${identity.address}`,
identity,
selectedAddress: this.props.selectedAddress,
conversionRate,
currentCurrency,
2016-06-21 22:18:32 +02:00
accounts: this.props.accounts,
onShowDetail: this.onShowDetail.bind(this),
pending,
keyring,
2016-06-21 22:18:32 +02:00
})
}),
2016-09-12 23:27:26 +02:00
h('hr.horizontal-line'),
2016-06-21 22:18:32 +02:00
h('div.footer.hover-white.pointer', {
key: 'reveal-account-bar',
onClick: () => {
this.addNewAccount()
2016-06-21 22:18:32 +02:00
},
style: {
display: 'flex',
height: '40px',
2017-04-05 22:38:33 +02:00
padding: '10px',
2016-06-21 22:18:32 +02:00
justifyContent: 'center',
alignItems: 'center',
},
}, [
h('i.fa.fa-plus.fa-lg', {key: ''}),
]),
2016-09-12 23:27:26 +02:00
h('hr.horizontal-line'),
2016-05-23 23:48:01 +02:00
]),
unapprovedTxList.length ? (
2016-05-23 23:48:01 +02:00
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.onShowDetail = function (address, event) {
2016-05-23 23:48:01 +02:00
event.stopPropagation()
this.props.dispatch(actions.showAccountDetail(address))
}
AccountsScreen.prototype.addNewAccount = function () {
this.props.dispatch(actions.addNewAccount(0))
2016-05-23 23:48:01 +02:00
}
/* An optional view proposed in this design:
* https://consensys.quip.com/zZVrAysM5znY
AccountsScreen.prototype.addNewAccount = function () {
2016-11-04 20:00:56 +01:00
this.props.dispatch(actions.navigateToNewAccountScreen())
2016-05-23 23:48:01 +02:00
}
*/
2016-05-23 23:48:01 +02:00
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())
}