1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/account-detail.js

281 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 actions = require('./actions')
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 TabBar = require('./components/tab-bar')
const TokenList = require('./components/token-list')
2017-07-25 02:04:13 +02:00
const AccountDropdowns = require('./components/account-dropdowns').AccountDropdowns
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,
currentAccountTab: state.metamask.currentAccountTab,
tokens: state.metamask.tokens,
}
}
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 (
h('.account-detail-section.full-flex-height', [
// identicon, label, balance, etc
2016-06-30 20:15:32 +02:00
h('.account-data-subsection', {
style: {
margin: '0 20px',
2017-07-25 02:04:13 +02:00
flex: '1 0 auto',
},
}, [
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',
2017-07-25 02:04:13 +02:00
width: '100%',
},
}, [
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')]),
2017-07-25 02:04:13 +02:00
h(
'div',
{
style: {
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
},
},
[
h(
'h2.font-medium.color-forest',
{
name: 'edit',
style: {
},
},
[
identity && identity.name,
]
),
h(
AccountDropdowns,
{
style: {
marginRight: '8px',
marginLeft: 'auto',
cursor: 'pointer',
},
selected,
network,
identities: props.identities,
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
},
}, checksumAddress),
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',
},
}),
2017-07-25 02:04:13 +02:00
h('.flex-grow'),
h('button', {
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'),
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)
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.tabSections()
case 'export':
var state = extend({key: 'export'}, this.props)
return h(ExportAccountView, state)
default:
return this.tabSections()
}
}
AccountDetailScreen.prototype.tabSections = function () {
const { currentAccountTab } = this.props
return h('section.tabSection.full-flex-height.grow-tenx', [
h(TabBar, {
tabs: [
2017-06-14 03:00:06 +02:00
{ content: 'Sent', key: 'history' },
{ content: 'Tokens', key: 'tokens' },
],
defaultTab: currentAccountTab || 'history',
tabSelected: (key) => {
this.props.dispatch(actions.setCurrentAccountTab(key))
},
}),
this.tabSwitchView(),
])
}
AccountDetailScreen.prototype.tabSwitchView = function () {
const props = this.props
const { address, network } = props
const { currentAccountTab, tokens } = this.props
switch (currentAccountTab) {
case 'tokens':
return h(TokenList, {
userAddress: address,
network,
tokens,
addToken: () => this.props.dispatch(actions.showAddTokenPage()),
})
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
},
})
}