1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/account-detail.js

272 lines
7.8 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 CopyButton = require('./components/copyButton')
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')
const AccountEtherBalance = require('./components/account-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')
const Tooltip = require('./components/tooltip')
2016-08-10 22:43:01 +02:00
const BuyButtonSubview = require('./components/buy-button-subview')
module.exports = connect(mapStateToProps)(AccountDetailScreen)
2016-06-21 22:18:32 +02:00
function mapStateToProps (state) {
return {
metamask: state.metamask,
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),
isEthWarningConfirmed: state.metamask.isEthConfirmed,
}
}
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 (
2016-06-30 20:15:32 +02:00
h('.account-detail-section', [
// identicon, label, balance, etc
2016-06-30 20:15:32 +02:00
h('.account-data-subsection', {
style: {
margin: '0 20px',
},
}, [
2016-05-11 11:11:31 +02:00
// header - identicon + nav
2016-06-30 20:15:32 +02:00
h('div', {
2016-05-11 11:11:31 +02:00
style: {
marginTop: '20px',
2016-06-30 20:15:32 +02:00
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'flex-start',
2016-05-11 11:11:31 +02:00
},
}, [
2016-05-11 11:11:31 +02:00
2016-06-30 20:15:32 +02:00
// large identicon and addresses
h('.identicon-wrapper.select-none', [
h(Identicon, {
diameter: 62,
address: selected,
}),
]),
2016-06-30 20:15:32 +02:00
h('flex-column', {
style: {
lineHeight: '10px',
marginLeft: '15px',
},
}, [
2016-06-30 20:15:32 +02:00
h(EditableLabel, {
textValue: identity ? identity.name : '',
state: {
isEditingLabel: false,
},
saveText: (text) => {
props.dispatch(actions.saveAccountLabel(selected, text))
},
}, [
2016-06-30 20:15:32 +02:00
// What is shown when not editing + edit text:
h('label.editing-label', [h('.edit-text', 'edit')]),
h('h2.font-medium.color-forest', {name: 'edit'}, identity && identity.name),
]),
2016-06-30 21:43:28 +02:00
h('.flex-row', {
style: {
2016-06-30 20:15:32 +02:00
width: '15em',
justifyContent: 'space-between',
alignItems: 'baseline',
2016-06-30 21:43:28 +02:00
},
}, [
// address
2016-06-30 20:15:32 +02:00
h('div', {
style: {
overflow: 'hidden',
textOverflow: 'ellipsis',
paddingTop: '3px',
width: '5em',
2016-06-30 21:43:28 +02:00
fontSize: '13px',
2016-07-06 00:39:51 +02:00
fontFamily: 'Montserrat Light',
2016-06-30 21:43:28 +02:00
textRendering: 'geometricPrecision',
marginTop: '10px',
marginBottom: '15px',
color: '#AEAEAE',
2016-06-30 20:15:32 +02:00
},
}, ethUtil.toChecksumAddress(selected)),
2016-05-11 11:11:31 +02:00
2016-06-30 21:43:28 +02:00
// copy and export
2016-05-11 11:11:31 +02:00
2016-06-30 20:15:32 +02:00
h('.flex-row', {
style: {
justifyContent: 'flex-end',
position: 'relative',
bottom: '15px',
2016-06-30 20:15:32 +02:00
},
}, [
h(CopyButton, {
value: ethUtil.toChecksumAddress(selected),
}),
h(Tooltip, {
title: 'Export Private Key',
}, [
h('div', {
style: {
margin: '5px',
},
}, [
h('img.cursor-pointer.color-orange', {
src: 'images/key-32.png',
onClick: () => this.requestAccountExport(selected),
style: {
margin: '0px 5px',
width: '20px',
height: '20px',
},
}),
]),
]),
]),
]),
2016-06-30 21:43:28 +02:00
// account ballence
]),
]),
h('.flex-row', {
style: {
justifyContent: 'space-between',
alignItems: 'flex-start',
},
}, [
2016-05-11 11:11:31 +02:00
h(AccountEtherBalance, {
value: account && account.balance,
2016-07-07 02:04:09 +02:00
mainBalance: true,
style: {
lineHeight: '7px',
marginTop: '10px',
},
}),
2016-05-11 11:11:31 +02:00
h('button', {
onClick: () => props.dispatch(actions.buyEthView(selected)),
style: {
marginBottom: '20px',
marginRight: '8px',
position: 'absolute',
left: '219px',
},
2016-08-10 22:43:01 +02:00
}, props.accountDetail.subview === 'buyForm' ? [h('i.fa.fa-arrow-left', {
style: {
width: '22.641px',
height: '14px',
},
})] : 'BUY'),
h('button', {
onClick: () => props.dispatch(actions.showSendPage()),
style: {
marginBottom: '20px',
marginRight: '8px',
},
}, 'SEND'),
2016-06-30 20:15:32 +02:00
]),
]),
// subview (tx history, pk export confirm, buy eth warning)
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)
2016-08-10 22:43:01 +02:00
case 'buyForm':
return h(BuyButtonSubview, extend({key: 'buyForm'}, this.props))
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())
}
2016-08-10 22:43:01 +02:00
2016-08-15 19:50:53 +02:00
2016-08-10 22:43:01 +02:00
AccountDetailScreen.prototype.buyButtonDeligator = function () {
var props = this.props
if (this.props.accountDetail.subview === 'buyForm') {
props.dispatch(actions.backToAccountDetail(props.address))
} else {
props.dispatch(actions.buyEthView())
2016-08-10 22:43:01 +02:00
}
}