nifty-wallet/ui/app/account-detail.js

277 lines
8.0 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 02:11:31 -07: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')
2016-08-10 13:43:01 -07:00
const BuyButtonSubview = require('./components/buy-button-subview')
module.exports = connect(mapStateToProps)(AccountDetailScreen)
2016-06-21 13:18:32 -07: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-18 15:20:26 -07:00
shapeShiftTxList: state.metamask.shapeShiftTxList,
2017-02-01 12:57:00 -08:00
transactions: state.metamask.selectedAddressTxList || [],
}
}
inherits(AccountDetailScreen, Component)
2016-06-21 13:18:32 -07:00
function AccountDetailScreen () {
Component.call(this)
}
2016-06-21 13:18:32 -07: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 } = props
return (
2016-06-30 11:15:32 -07:00
h('.account-detail-section', [
// identicon, label, balance, etc
2016-06-30 11:15:32 -07:00
h('.account-data-subsection', {
style: {
margin: '0 20px',
},
}, [
2016-05-11 02:11:31 -07:00
// header - identicon + nav
2016-06-30 11:15:32 -07:00
h('div', {
2016-05-11 02:11:31 -07:00
style: {
marginTop: '20px',
2016-06-30 11:15:32 -07:00
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'flex-start',
2016-05-11 02:11:31 -07:00
},
}, [
2016-05-11 02:11:31 -07:00
2016-06-30 11:15:32 -07:00
// large identicon and addresses
h('.identicon-wrapper.select-none', [
h(Identicon, {
2016-12-16 10:04:57 -08:00
diameter: 62,
address: selected,
}),
]),
2016-06-30 11:15:32 -07:00
h('flex-column', {
style: {
lineHeight: '10px',
marginLeft: '15px',
},
}, [
2016-06-30 11:15:32 -07:00
h(EditableLabel, {
textValue: identity ? identity.name : '',
2016-12-16 10:04:57 -08:00
state: {
isEditingLabel: false,
},
2016-06-30 11:15:32 -07:00
saveText: (text) => {
props.dispatch(actions.saveAccountLabel(selected, text))
},
}, [
2016-06-30 11:15:32 -07:00
// What is shown when not editing + edit text:
2016-12-16 10:04:57 -08:00
h('label.editing-label', [h('.edit-text', 'edit')]),
2016-06-30 11:15:32 -07:00
h('h2.font-medium.color-forest', {name: 'edit'}, identity && identity.name),
]),
2016-06-30 12:43:28 -07:00
h('.flex-row', {
style: {
2016-12-16 10:04:57 -08:00
width: '15em',
2016-06-30 11:15:32 -07:00
justifyContent: 'space-between',
alignItems: 'baseline',
2016-06-30 12:43:28 -07:00
},
}, [
2016-12-16 10:04:57 -08:00
// address
h('div', {
2016-06-30 11:15:32 -07:00
style: {
2016-12-16 10:04:57 -08:00
overflow: 'hidden',
textOverflow: 'ellipsis',
paddingTop: '3px',
width: '5em',
fontSize: '13px',
fontFamily: 'Montserrat Light',
textRendering: 'geometricPrecision',
2016-06-30 12:43:28 -07:00
marginTop: '10px',
2016-12-16 10:04:57 -08:00
marginBottom: '15px',
color: '#AEAEAE',
2016-06-30 11:15:32 -07:00
},
}, checksumAddress),
2016-05-11 02:11:31 -07:00
2016-06-30 12:43:28 -07:00
// copy and export
2016-05-11 02:11:31 -07:00
2016-06-30 11:15:32 -07:00
h('.flex-row', {
style: {
justifyContent: 'flex-end',
},
}, [
h(AccountInfoLink, { selected, network }),
2016-06-30 11:15:32 -07:00
h(CopyButton, {
value: checksumAddress,
2016-06-30 11:15:32 -07: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 11:15:32 -07:00
h(Tooltip, {
title: 'Export Private Key',
}, [
h('div', {
style: {
display: 'flex',
alignItems: 'center',
2016-08-22 17:21:54 -07:00
},
2016-06-30 11:15:32 -07:00
}, [
h('img.cursor-pointer.color-orange', {
src: 'images/key-32.png',
onClick: () => this.requestAccountExport(selected),
style: {
height: '19px',
2016-06-30 11:15:32 -07:00
},
}),
]),
]),
]),
]),
2016-12-16 10:04:57 -08:00
// account ballence
]),
]),
h('.flex-row', {
style: {
2016-12-16 10:04:57 -08:00
justifyContent: 'space-between',
alignItems: 'flex-start',
},
}, [
2016-12-16 10:04:57 -08:00
h(EthBalance, {
value: account && account.balance,
style: {
lineHeight: '7px',
marginTop: '10px',
},
}),
h('button', {
onClick: () => props.dispatch(actions.buyEthView(selected)),
style: {
marginBottom: '20px',
marginRight: '8px',
2016-12-16 10:04:57 -08:00
position: 'absolute',
left: '219px',
},
2016-08-18 10:40:35 -07:00
}, 'BUY'),
h('button', {
onClick: () => props.dispatch(actions.showSendPage()),
style: {
marginBottom: '20px',
marginRight: '8px',
},
}, 'SEND'),
2016-06-30 11:15:32 -07: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 02:11:31 -07:00
])
)
}
2016-06-21 13:18:32 -07: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 13:43:01 -07:00
case 'buyForm':
return h(BuyButtonSubview, extend({key: 'buyForm'}, this.props))
default:
return this.transactionList()
}
}
2016-06-21 13:18:32 -07:00
AccountDetailScreen.prototype.transactionList = function () {
const {transactions, unapprovedMsgs, address, network, shapeShiftTxList } = this.props
return h(TransactionList, {
2017-01-13 10:44:22 -08:00
transactions: transactions.sort((a, b) => b.time - a.time),
network,
unapprovedMsgs,
address,
2016-08-18 10:40:35 -07:00
shapeShiftTxList,
2016-06-21 13:18:32 -07:00
viewPendingTx: (txId) => {
this.props.dispatch(actions.viewPendingTx(txId))
2016-06-21 13:18:32 -07:00
},
})
}
2016-06-21 13:18:32 -07:00
AccountDetailScreen.prototype.requestAccountExport = function () {
this.props.dispatch(actions.requestExportAccount())
}
2016-08-10 13:43:01 -07:00
2016-08-15 10:50:53 -07:00
2016-08-10 13:43:01 -07:00
AccountDetailScreen.prototype.buyButtonDeligator = function () {
var props = this.props
var selected = props.address || Object.keys(props.accounts)[0]
2016-08-10 13:43:01 -07:00
if (this.props.accountDetail.subview === 'buyForm') {
props.dispatch(actions.backToAccountDetail(props.address))
} else {
props.dispatch(actions.buyEthView(selected))
2016-08-10 13:43:01 -07:00
}
}