2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
2016-05-05 03:08:31 +02:00
|
|
|
const extend = require('xtend')
|
2016-04-14 00:28:44 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const actions = require('./actions')
|
2016-05-26 02:18:04 +02:00
|
|
|
const valuesFor = require('./util').valuesFor
|
2016-05-11 11:11:31 +02:00
|
|
|
const Identicon = require('./components/identicon')
|
2016-09-07 01:45:06 +02:00
|
|
|
const EthBalance = require('./components/eth-balance')
|
2016-05-26 02:18:04 +02:00
|
|
|
const TransactionList = require('./components/transaction-list')
|
2016-05-05 03:08:31 +02:00
|
|
|
const ExportAccountView = require('./components/account-export')
|
2016-05-19 21:06:45 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
2016-05-21 01:18:54 +02:00
|
|
|
const EditableLabel = require('./components/editable-label')
|
2017-04-21 04:07:09 +02:00
|
|
|
const TabBar = require('./components/tab-bar')
|
2017-08-16 18:49:18 +02:00
|
|
|
const TokenList = require('./components/token-list')
|
2017-07-25 02:04:13 +02:00
|
|
|
const AccountDropdowns = require('./components/account-dropdowns').AccountDropdowns
|
2017-06-13 02:06:39 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
module.exports = connect(mapStateToProps)(AccountDetailScreen)
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-08-05 21:18:44 +02:00
|
|
|
metamask: state.metamask,
|
2016-04-14 00:28:44 +02:00
|
|
|
identities: state.metamask.identities,
|
|
|
|
accounts: state.metamask.accounts,
|
2017-01-31 00:08:31 +01:00
|
|
|
address: state.metamask.selectedAddress,
|
2016-04-25 21:20:33 +02:00
|
|
|
accountDetail: state.appState.accountDetail,
|
2016-05-26 02:18:04 +02:00
|
|
|
network: state.metamask.network,
|
2017-01-28 01:11:59 +01:00
|
|
|
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 || [],
|
2017-05-12 21:41:31 +02:00
|
|
|
conversionRate: state.metamask.conversionRate,
|
2017-05-16 20:34:53 +02:00
|
|
|
currentCurrency: state.metamask.currentCurrency,
|
2017-06-14 23:21:50 +02:00
|
|
|
currentAccountTab: state.metamask.currentAccountTab,
|
2017-06-16 01:22:53 +02:00
|
|
|
tokens: state.metamask.tokens,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(AccountDetailScreen, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function AccountDetailScreen () {
|
2016-04-14 00:28:44 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
AccountDetailScreen.prototype.render = function () {
|
2016-05-21 01:18:54 +02:00
|
|
|
var props = this.props
|
|
|
|
var selected = props.address || Object.keys(props.accounts)[0]
|
2017-01-29 04:19:03 +01:00
|
|
|
var checksumAddress = selected && ethUtil.toChecksumAddress(selected)
|
2016-05-21 01:18:54 +02:00
|
|
|
var identity = props.identities[selected]
|
|
|
|
var account = props.accounts[selected]
|
2017-05-16 20:34:53 +02:00
|
|
|
const { network, conversionRate, currentCurrency } = props
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
|
2017-07-26 03:22:31 +02:00
|
|
|
h('.account-detail-section.full-flex-height', [
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-07-26 03:22:31 +02:00
|
|
|
// identicon, label, balance, etc
|
2016-06-30 20:15:32 +02:00
|
|
|
h('.account-data-subsection', {
|
2016-05-14 01:28:46 +02:00
|
|
|
style: {
|
|
|
|
margin: '0 20px',
|
2017-07-25 02:04:13 +02:00
|
|
|
flex: '1 0 auto',
|
2016-05-14 01:28:46 +02:00
|
|
|
},
|
|
|
|
}, [
|
2016-05-11 11:11:31 +02:00
|
|
|
|
2016-05-14 01:28:46 +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-14 01:28:46 +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', [
|
2016-05-14 01:28:46 +02:00
|
|
|
h(Identicon, {
|
2016-12-16 19:04:57 +01:00
|
|
|
diameter: 62,
|
2016-05-14 01:28:46 +02:00
|
|
|
address: selected,
|
|
|
|
}),
|
|
|
|
]),
|
2016-06-30 20:15:32 +02:00
|
|
|
h('flex-column', {
|
|
|
|
style: {
|
|
|
|
lineHeight: '10px',
|
|
|
|
marginLeft: '15px',
|
2017-07-25 02:04:13 +02:00
|
|
|
width: '100%',
|
2016-05-21 01:18:54 +02:00
|
|
|
},
|
|
|
|
}, [
|
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-05-21 01:18:54 +02:00
|
|
|
|
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')]),
|
2017-07-25 02:04:13 +02:00
|
|
|
h(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
style: {
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[
|
|
|
|
h(
|
2017-08-11 02:49:12 +02:00
|
|
|
'div.font-medium.color-forest',
|
2017-07-25 02:04:13 +02:00
|
|
|
{
|
|
|
|
name: 'edit',
|
|
|
|
style: {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[
|
2017-08-11 02:49:12 +02:00
|
|
|
h('h2', {
|
|
|
|
style: {
|
|
|
|
maxWidth: '180px',
|
2017-08-15 17:13:11 +02:00
|
|
|
overflow: 'hidden',
|
2017-08-11 02:49:12 +02:00
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
padding: '5px 0px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
identity && identity.name,
|
|
|
|
]),
|
2017-07-25 02:04:13 +02:00
|
|
|
]
|
|
|
|
),
|
|
|
|
h(
|
|
|
|
AccountDropdowns,
|
|
|
|
{
|
|
|
|
style: {
|
|
|
|
marginRight: '8px',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
selected,
|
|
|
|
network,
|
|
|
|
identities: props.identities,
|
2017-08-04 02:08:19 +02:00
|
|
|
enableAccountOptions: true,
|
2017-07-25 02:04:13 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
2016-06-30 20:15:32 +02:00
|
|
|
]),
|
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',
|
|
|
|
marginBottom: '15px',
|
|
|
|
color: '#AEAEAE',
|
2016-06-30 20:15:32 +02:00
|
|
|
},
|
2017-01-29 04:19:03 +01:00
|
|
|
}, checksumAddress),
|
2016-06-30 20:15:32 +02:00
|
|
|
]),
|
2016-12-16 19:04:57 +01:00
|
|
|
|
|
|
|
// account ballence
|
|
|
|
|
2016-07-05 21:04:15 +02:00
|
|
|
]),
|
|
|
|
]),
|
|
|
|
h('.flex-row', {
|
|
|
|
style: {
|
2016-12-16 19:04:57 +01:00
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'flex-start',
|
2016-07-05 21:04:15 +02:00
|
|
|
},
|
|
|
|
}, [
|
2016-12-16 19:04:57 +01:00
|
|
|
|
|
|
|
h(EthBalance, {
|
|
|
|
value: account && account.balance,
|
2017-05-12 21:41:31 +02:00
|
|
|
conversionRate,
|
2017-05-16 20:34:53 +02:00
|
|
|
currentCurrency,
|
2016-12-16 19:04:57 +01:00
|
|
|
style: {
|
|
|
|
lineHeight: '7px',
|
|
|
|
marginTop: '10px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2017-07-25 02:04:13 +02:00
|
|
|
h('.flex-grow'),
|
|
|
|
|
2016-07-21 22:41:10 +02:00
|
|
|
h('button', {
|
2016-08-13 00:41:59 +02:00
|
|
|
onClick: () => props.dispatch(actions.buyEthView(selected)),
|
2017-07-25 02:04:13 +02:00
|
|
|
style: { marginRight: '10px' },
|
2016-08-18 19:40:35 +02:00
|
|
|
}, 'BUY'),
|
2016-07-21 22:41:10 +02:00
|
|
|
|
2016-07-05 21:04:15 +02:00
|
|
|
h('button', {
|
|
|
|
onClick: () => props.dispatch(actions.showSendPage()),
|
|
|
|
style: {
|
|
|
|
marginBottom: '20px',
|
|
|
|
marginRight: '8px',
|
|
|
|
},
|
|
|
|
}, 'SEND'),
|
2016-05-14 01:28:46 +02:00
|
|
|
|
2016-06-30 20:15:32 +02:00
|
|
|
]),
|
2016-04-14 00:28:44 +02:00
|
|
|
]),
|
|
|
|
|
2016-07-21 22:41:10 +02:00
|
|
|
// subview (tx history, pk export confirm, buy eth warning)
|
2017-07-26 03:22:31 +02:00
|
|
|
this.subview(),
|
2016-05-11 11:11:31 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
AccountDetailScreen.prototype.subview = function () {
|
2016-05-05 03:08:31 +02:00
|
|
|
var subview
|
|
|
|
try {
|
|
|
|
subview = this.props.accountDetail.subview
|
|
|
|
} catch (e) {
|
|
|
|
subview = null
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (subview) {
|
|
|
|
case 'transactions':
|
2017-04-21 04:07:09 +02:00
|
|
|
return this.tabSections()
|
2016-05-05 03:08:31 +02:00
|
|
|
case 'export':
|
|
|
|
var state = extend({key: 'export'}, this.props)
|
|
|
|
return h(ExportAccountView, state)
|
2017-04-21 04:07:09 +02:00
|
|
|
default:
|
|
|
|
return this.tabSections()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountDetailScreen.prototype.tabSections = function () {
|
2017-06-14 23:21:50 +02:00
|
|
|
const { currentAccountTab } = this.props
|
|
|
|
|
2017-07-26 03:22:31 +02:00
|
|
|
return h('section.tabSection.full-flex-height.grow-tenx', [
|
2017-04-21 04:07:09 +02:00
|
|
|
|
|
|
|
h(TabBar, {
|
|
|
|
tabs: [
|
2017-06-14 03:00:06 +02:00
|
|
|
{ content: 'Sent', key: 'history' },
|
2017-04-21 04:07:09 +02:00
|
|
|
{ content: 'Tokens', key: 'tokens' },
|
|
|
|
],
|
2017-06-14 23:21:50 +02:00
|
|
|
defaultTab: currentAccountTab || 'history',
|
2017-04-21 04:07:09 +02:00
|
|
|
tabSelected: (key) => {
|
2017-06-14 23:21:50 +02:00
|
|
|
this.props.dispatch(actions.setCurrentAccountTab(key))
|
2017-04-21 04:07:09 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
this.tabSwitchView(),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountDetailScreen.prototype.tabSwitchView = function () {
|
2017-06-14 02:47:56 +02:00
|
|
|
const props = this.props
|
2017-08-16 18:49:18 +02:00
|
|
|
const { address, network } = props
|
|
|
|
const { currentAccountTab, tokens } = this.props
|
2017-04-21 04:07:09 +02:00
|
|
|
|
2017-06-14 23:21:50 +02:00
|
|
|
switch (currentAccountTab) {
|
2017-04-21 04:07:09 +02:00
|
|
|
case 'tokens':
|
2017-08-16 18:49:18 +02:00
|
|
|
return h(TokenList, {
|
|
|
|
userAddress: address,
|
|
|
|
network,
|
|
|
|
tokens,
|
|
|
|
addToken: () => this.props.dispatch(actions.showAddTokenPage()),
|
|
|
|
})
|
2016-05-05 03:08:31 +02:00
|
|
|
default:
|
|
|
|
return this.transactionList()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
AccountDetailScreen.prototype.transactionList = function () {
|
2017-05-12 21:41:31 +02:00
|
|
|
const {transactions, unapprovedMsgs, address,
|
|
|
|
network, shapeShiftTxList, conversionRate } = this.props
|
2017-04-21 04:07:09 +02:00
|
|
|
|
2016-05-26 02:18:04 +02:00
|
|
|
return h(TransactionList, {
|
2017-01-13 19:44:22 +01:00
|
|
|
transactions: transactions.sort((a, b) => b.time - a.time),
|
2016-05-26 02:18:04 +02:00
|
|
|
network,
|
2017-01-28 01:11:59 +01:00
|
|
|
unapprovedMsgs,
|
2017-05-12 21:41:31 +02:00
|
|
|
conversionRate,
|
2016-08-19 01:23:12 +02:00
|
|
|
address,
|
2016-08-18 19:40:35 +02:00
|
|
|
shapeShiftTxList,
|
2016-06-21 22:18:32 +02:00
|
|
|
viewPendingTx: (txId) => {
|
2016-05-26 23:32:45 +02:00
|
|
|
this.props.dispatch(actions.viewPendingTx(txId))
|
2016-06-21 22:18:32 +02:00
|
|
|
},
|
2016-05-26 02:18:04 +02:00
|
|
|
})
|
2016-05-05 03:08:31 +02:00
|
|
|
}
|