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

268 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 AccountInfoLink = require('./components/account-info-link')
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 EthBalance = 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')
const Tooltip = require('./components/tooltip')
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.selectedAddress,
accountDetail: state.appState.accountDetail,
network: state.metamask.network,
unapprovedMsgs: valuesFor(state.metamask.unapprovedMsgs),
2016-08-19 00:20:26 +02:00
shapeShiftTxList: state.metamask.shapeShiftTxList,
2017-02-01 21:57:00 +01:00
transactions: state.metamask.selectedAddressTxList || [],
conversionRate: state.metamask.conversionRate,
currentCurrency: state.metamask.currentCurrency,
}
}
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 checksumAddress = selected && ethUtil.toChecksumAddress(selected)
var identity = props.identities[selected]
var account = props.accounts[selected]
const { network, conversionRate, currentCurrency } = props
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: {
2017-04-05 22:38:33 +02:00
paddingTop: '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, {
2016-12-16 19:04:57 +01:00
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 : '',
2016-12-16 19:04:57 +01:00
state: {
isEditingLabel: false,
},
2016-06-30 20:15:32 +02:00
saveText: (text) => {
props.dispatch(actions.saveAccountLabel(selected, text))
},
}, [
2016-06-30 20:15:32 +02:00
// What is shown when not editing + edit text:
2016-12-16 19:04:57 +01:00
h('label.editing-label', [h('.edit-text', 'edit')]),
2016-06-30 20:15:32 +02:00
h('h2.font-medium.color-forest', {name: 'edit'}, identity && identity.name),
]),
2016-06-30 21:43:28 +02:00
h('.flex-row', {
style: {
2016-12-16 19:04:57 +01:00
width: '15em',
2016-06-30 20:15:32 +02:00
justifyContent: 'space-between',
alignItems: 'baseline',
2016-06-30 21:43:28 +02:00
},
}, [
2016-12-16 19:04:57 +01:00
// address
h('div', {
2016-06-30 20:15:32 +02:00
style: {
2016-12-16 19:04:57 +01:00
overflow: 'hidden',
textOverflow: 'ellipsis',
paddingTop: '3px',
width: '5em',
fontSize: '13px',
fontFamily: 'Montserrat Light',
textRendering: 'geometricPrecision',
2016-06-30 21:43:28 +02:00
marginTop: '10px',
2016-12-16 19:04:57 +01:00
marginBottom: '15px',
color: '#AEAEAE',
2016-06-30 20:15:32 +02:00
},
}, checksumAddress),
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',
},
}, [
h(AccountInfoLink, { selected, network }),
2016-06-30 20:15:32 +02:00
h(CopyButton, {
value: checksumAddress,
2016-06-30 20:15:32 +02:00
}),
h(Tooltip, {
title: 'QR Code',
}, [
h('i.fa.fa-qrcode.pointer.pop-hover', {
onClick: () => props.dispatch(actions.showQrView(selected, identity ? identity.name : '')),
style: {
fontSize: '18px',
position: 'relative',
color: 'rgb(247, 134, 28)',
top: '5px',
marginLeft: '3px',
marginRight: '3px',
},
}),
]),
2016-06-30 20:15:32 +02:00
h(Tooltip, {
title: 'Export Private Key',
}, [
h('div', {
style: {
display: 'flex',
alignItems: 'center',
2016-08-23 02:21:54 +02:00
},
2016-06-30 20:15:32 +02:00
}, [
h('img.cursor-pointer.color-orange', {
src: 'images/key-32.png',
onClick: () => this.requestAccountExport(selected),
style: {
height: '19px',
2016-06-30 20:15:32 +02:00
},
}),
]),
]),
]),
]),
2016-12-16 19:04:57 +01:00
// account ballence
]),
]),
h('.flex-row', {
style: {
2016-12-16 19:04:57 +01:00
justifyContent: 'space-between',
alignItems: 'flex-start',
},
}, [
2016-12-16 19:04:57 +01:00
h(EthBalance, {
value: account && account.balance,
conversionRate,
currentCurrency,
2016-12-16 19:04:57 +01:00
style: {
lineHeight: '7px',
marginTop: '10px',
},
}),
h('button', {
onClick: () => props.dispatch(actions.buyEthView(selected)),
style: {
marginBottom: '20px',
marginRight: '8px',
2016-12-16 19:04:57 +01:00
position: 'absolute',
left: '219px',
},
2016-08-18 19:40:35 +02:00
}, '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)
default:
return this.transactionList()
}
}
2016-06-21 22:18:32 +02:00
AccountDetailScreen.prototype.transactionList = function () {
const {transactions, unapprovedMsgs, address,
network, shapeShiftTxList, conversionRate } = this.props
return h(TransactionList, {
2017-01-13 19:44:22 +01:00
transactions: transactions.sort((a, b) => b.time - a.time),
network,
unapprovedMsgs,
conversionRate,
address,
2016-08-18 19:40:35 +02:00
shapeShiftTxList,
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())
}