1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/ui/app/account-detail.js

211 lines
5.6 KiB
JavaScript
Raw Normal View History

const inherits = require('util').inherits
const extend = require('xtend')
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const copyToClipboard = require('copy-to-clipboard')
const actions = require('./actions')
const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
const valuesFor = require('./util').valuesFor
2016-05-11 11:11:31 +02:00
const Identicon = require('./components/identicon')
2016-05-18 22:41:08 +02:00
const EtherBalance = require('./components/eth-balance')
const TransactionList = require('./components/transaction-list')
const ExportAccountView = require('./components/account-export')
const ethUtil = require('ethereumjs-util')
const EditableLabel = require('./components/editable-label')
module.exports = connect(mapStateToProps)(AccountDetailScreen)
2016-06-21 22:18:32 +02:00
function mapStateToProps (state) {
return {
identities: state.metamask.identities,
accounts: state.metamask.accounts,
address: state.metamask.selectedAccount,
accountDetail: state.appState.accountDetail,
transactions: state.metamask.transactions,
network: state.metamask.network,
unconfTxs: valuesFor(state.metamask.unconfTxs),
unconfMsgs: valuesFor(state.metamask.unconfMsgs),
}
}
inherits(AccountDetailScreen, Component)
2016-06-21 22:18:32 +02:00
function AccountDetailScreen () {
Component.call(this)
}
2016-06-21 22:18:32 +02:00
AccountDetailScreen.prototype.render = function () {
var props = this.props
var selected = props.address || Object.keys(props.accounts)[0]
var identity = props.identities[selected]
var account = props.accounts[selected]
return (
h('.account-detail-section.flex-column.flex-grow', [
// identicon, label, balance, etc
h('.account-data-subsection.flex-column.flex-grow', {
style: {
margin: '0 20px',
},
}, [
2016-05-11 11:11:31 +02:00
// header - identicon + nav
h('.flex-row.flex-center', {
2016-05-11 11:11:31 +02:00
style: {
marginTop: 28,
2016-05-11 11:11:31 +02:00
},
}, [
2016-05-11 11:11:31 +02:00
// large identicon
h('.identicon-wrapper.flex-column.flex-center.select-none', [
h(Identicon, {
diameter: 62,
address: selected,
}),
]),
]),
h('.flex-center', {
style: {
height: '62px',
paddingTop: '8px',
2016-06-21 22:18:32 +02:00
},
}, [
h(EditableLabel, {
textValue: identity ? identity.name : '',
state: {
isEditingLabel: false,
},
saveText: (text) => {
props.dispatch(actions.saveAccountLabel(selected, text))
},
}, [
// What is shown when not editing + edit text:
2016-06-21 22:18:32 +02:00
h('label.editing-label', [h('.edit-text', 'edit')]),
2016-06-10 05:58:33 +02:00
h('h2.font-medium.color-forest', {name: 'edit'}, identity && identity.name),
]),
]),
// address and getter actions
2016-06-14 23:29:08 +02:00
h('.flex-row', {
2016-05-11 11:11:31 +02:00
style: {
marginBottom: 16,
},
}, [
h('div', {
style: {
2016-06-14 23:29:08 +02:00
overflow: 'hidden',
textOverflow: 'ellipsis',
paddingTop: '3px',
},
}, ethUtil.toChecksumAddress(selected)),
2016-05-11 11:11:31 +02:00
2016-06-14 21:43:43 +02:00
h('img.cursor-pointer.color-orange', {
src: 'images/copy.svg',
onClick: () => copyToClipboard(ethUtil.toChecksumAddress(selected)),
2016-06-21 22:18:32 +02:00
style: {
2016-06-14 23:29:08 +02:00
margin: '0px 5px',
},
}),
2016-05-11 11:11:31 +02:00
2016-06-14 22:01:04 +02:00
h('img.cursor-pointer.color-orange', {
2016-06-21 22:10:28 +02:00
src: 'images/key-32.png',
onClick: () => this.requestAccountExport(selected),
2016-06-22 00:19:10 +02:00
style: {
margin: '0px 5px',
width: '20px',
height: '20px',
position: 'relative',
top: '3px',
right: '4px',
},
}),
2016-05-11 11:11:31 +02:00
]),
2016-05-11 11:11:31 +02:00
// balance + send
h('.flex-row.flex-space-between', [
2016-05-18 22:41:08 +02:00
h(EtherBalance, {
value: account && account.balance,
style: {
lineHeight: '50px',
},
2016-05-18 22:41:08 +02:00
}),
h('button', {
onClick: () => props.dispatch(actions.showSendPage()),
2016-05-18 21:13:19 +02:00
style: {
margin: 10,
},
}, 'SEND ETH'),
2016-05-11 11:11:31 +02:00
]),
]),
// subview (tx history, pk export confirm)
h(ReactCSSTransitionGroup, {
className: 'css-transition-group',
transitionName: 'main',
transitionEnterTimeout: 300,
transitionLeaveTimeout: 300,
}, [
this.subview(),
]),
2016-05-11 11:11:31 +02:00
])
)
}
2016-06-21 22:18:32 +02:00
AccountDetailScreen.prototype.subview = function () {
var subview
try {
subview = this.props.accountDetail.subview
} catch (e) {
subview = null
}
switch (subview) {
case 'transactions':
return this.transactionList()
case 'export':
var state = extend({key: 'export'}, this.props)
return h(ExportAccountView, state)
default:
return this.transactionList()
}
}
2016-06-21 22:18:32 +02:00
AccountDetailScreen.prototype.transactionList = function () {
const { transactions, unconfTxs, unconfMsgs, address, network } = this.props
var txsToRender = transactions
// only transactions that are from the current address
.filter(tx => tx.txParams.from === address)
// only transactions that are on the current network
.filter(tx => tx.txParams.metamaskNetworkId === network)
// sort by recency
.sort((a, b) => b.time - a.time)
return h(TransactionList, {
txsToRender,
network,
unconfTxs,
unconfMsgs,
2016-06-21 22:18:32 +02:00
viewPendingTx: (txId) => {
this.props.dispatch(actions.viewPendingTx(txId))
2016-06-21 22:18:32 +02:00
},
})
}
2016-06-21 22:18:32 +02:00
AccountDetailScreen.prototype.requestAccountExport = function () {
this.props.dispatch(actions.requestExportAccount())
}