2017-07-31 06:25:32 +02:00
|
|
|
const Component = require('react').Component
|
2018-03-29 17:00:44 +02:00
|
|
|
const PropTypes = require('prop-types')
|
|
|
|
const connect = require('react-redux').connect
|
2017-07-31 06:25:32 +02:00
|
|
|
const h = require('react-hyperscript')
|
2017-11-29 05:24:35 +01:00
|
|
|
const { withRouter } = require('react-router-dom')
|
|
|
|
const { compose } = require('recompose')
|
2017-07-31 06:25:32 +02:00
|
|
|
const inherits = require('util').inherits
|
2018-02-01 01:27:35 +01:00
|
|
|
const classnames = require('classnames')
|
2018-04-17 21:57:55 +02:00
|
|
|
const { checksumAddress } = require('../util')
|
2017-07-31 06:25:32 +02:00
|
|
|
const Identicon = require('./identicon')
|
2017-10-24 08:59:21 +02:00
|
|
|
// const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns
|
2018-02-01 01:27:35 +01:00
|
|
|
const Tooltip = require('./tooltip-v2.js')
|
2017-10-24 08:59:21 +02:00
|
|
|
const copyToClipboard = require('copy-to-clipboard')
|
2017-08-01 08:21:11 +02:00
|
|
|
const actions = require('../actions')
|
2017-08-11 09:31:06 +02:00
|
|
|
const BalanceComponent = require('./balance-component')
|
2017-09-05 10:48:52 +02:00
|
|
|
const TokenList = require('./token-list')
|
2017-08-10 06:40:21 +02:00
|
|
|
const selectors = require('../selectors')
|
2017-11-29 05:24:35 +01:00
|
|
|
const { ADD_TOKEN_ROUTE } = require('../routes')
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2017-11-29 05:24:35 +01:00
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(WalletView)
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
WalletView.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2017-07-31 06:25:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2017-08-10 08:48:05 +02:00
|
|
|
|
2017-07-31 06:25:32 +02:00
|
|
|
return {
|
|
|
|
network: state.metamask.network,
|
2017-08-02 23:17:58 +02:00
|
|
|
sidebarOpen: state.appState.sidebarOpen,
|
2017-08-07 06:54:42 +02:00
|
|
|
identities: state.metamask.identities,
|
2017-08-10 06:40:21 +02:00
|
|
|
accounts: state.metamask.accounts,
|
2017-09-05 10:48:52 +02:00
|
|
|
tokens: state.metamask.tokens,
|
2017-10-24 08:59:21 +02:00
|
|
|
keyrings: state.metamask.keyrings,
|
2017-08-10 06:40:21 +02:00
|
|
|
selectedAddress: selectors.getSelectedAddress(state),
|
|
|
|
selectedAccount: selectors.getSelectedAccount(state),
|
2017-09-06 12:17:49 +02:00
|
|
|
selectedTokenAddress: state.metamask.selectedTokenAddress,
|
2017-07-31 06:25:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:21:11 +02:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-10-24 08:59:21 +02:00
|
|
|
showSendPage: () => dispatch(actions.showSendPage()),
|
|
|
|
hideSidebar: () => dispatch(actions.hideSidebar()),
|
2017-09-06 12:17:49 +02:00
|
|
|
unsetSelectedToken: () => dispatch(actions.setSelectedToken()),
|
2017-10-24 08:59:21 +02:00
|
|
|
showAccountDetailModal: () => {
|
|
|
|
dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' }))
|
|
|
|
},
|
2017-10-24 09:29:20 +02:00
|
|
|
showAddTokenPage: () => dispatch(actions.showAddTokenPage()),
|
2017-08-01 08:21:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 06:25:32 +02:00
|
|
|
inherits(WalletView, Component)
|
|
|
|
function WalletView () {
|
|
|
|
Component.call(this)
|
2017-10-25 05:04:29 +02:00
|
|
|
this.state = {
|
|
|
|
hasCopied: false,
|
2018-02-01 01:27:35 +01:00
|
|
|
copyToClipboardPressed: false,
|
2017-10-25 05:04:29 +02:00
|
|
|
}
|
2017-07-31 06:25:32 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 12:17:49 +02:00
|
|
|
WalletView.prototype.renderWalletBalance = function () {
|
2017-09-28 13:55:04 +02:00
|
|
|
const {
|
|
|
|
selectedTokenAddress,
|
|
|
|
selectedAccount,
|
|
|
|
unsetSelectedToken,
|
|
|
|
hideSidebar,
|
2017-10-16 07:27:51 +02:00
|
|
|
sidebarOpen,
|
2017-09-28 13:55:04 +02:00
|
|
|
} = this.props
|
2017-10-24 08:59:21 +02:00
|
|
|
|
2017-09-06 12:17:49 +02:00
|
|
|
const selectedClass = selectedTokenAddress
|
|
|
|
? ''
|
|
|
|
: 'wallet-balance-wrapper--active'
|
|
|
|
const className = `flex-column wallet-balance-wrapper ${selectedClass}`
|
|
|
|
|
|
|
|
return h('div', { className }, [
|
|
|
|
h('div.wallet-balance',
|
|
|
|
{
|
2017-09-28 13:55:04 +02:00
|
|
|
onClick: () => {
|
|
|
|
unsetSelectedToken()
|
|
|
|
selectedTokenAddress && sidebarOpen && hideSidebar()
|
|
|
|
},
|
2017-09-06 12:17:49 +02:00
|
|
|
},
|
|
|
|
[
|
|
|
|
h(BalanceComponent, {
|
2017-10-19 21:47:44 +02:00
|
|
|
balanceValue: selectedAccount ? selectedAccount.balance : '',
|
2017-09-06 12:17:49 +02:00
|
|
|
style: {},
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
])
|
2017-09-05 10:48:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-31 06:25:32 +02:00
|
|
|
WalletView.prototype.render = function () {
|
2017-09-05 10:48:52 +02:00
|
|
|
const {
|
2017-10-24 08:59:21 +02:00
|
|
|
responsiveDisplayClassname,
|
|
|
|
selectedAddress,
|
|
|
|
keyrings,
|
|
|
|
showAccountDetailModal,
|
2018-05-11 01:51:26 +02:00
|
|
|
sidebarOpen,
|
2017-10-24 08:59:21 +02:00
|
|
|
hideSidebar,
|
2017-11-29 05:24:35 +01:00
|
|
|
history,
|
2018-06-05 21:23:30 +02:00
|
|
|
identities,
|
2017-09-05 10:48:52 +02:00
|
|
|
} = this.props
|
2017-08-11 18:17:14 +02:00
|
|
|
// temporary logs + fake extra wallets
|
2017-09-07 12:14:53 +02:00
|
|
|
// console.log('walletview, selectedAccount:', selectedAccount)
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2018-04-17 21:57:55 +02:00
|
|
|
const checksummedAddress = checksumAddress(selectedAddress)
|
|
|
|
|
2018-06-05 21:04:03 +02:00
|
|
|
if (!selectedAddress) {
|
|
|
|
throw new Error('selectedAddress should not be ' + String(selectedAddress))
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:59:21 +02:00
|
|
|
const keyring = keyrings.find((kr) => {
|
2018-06-05 21:23:30 +02:00
|
|
|
return kr.accounts.includes(selectedAddress)
|
2017-10-24 08:59:21 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const type = keyring.type
|
|
|
|
const isLoose = type !== 'HD Key Tree'
|
|
|
|
|
2017-08-02 22:03:36 +02:00
|
|
|
return h('div.wallet-view.flex-column' + (responsiveDisplayClassname || ''), {
|
2017-08-07 05:47:59 +02:00
|
|
|
style: {},
|
2017-07-31 06:25:32 +02:00
|
|
|
}, [
|
|
|
|
|
2017-07-31 07:10:59 +02:00
|
|
|
// TODO: Separate component: wallet account details
|
2017-08-11 18:17:14 +02:00
|
|
|
h('div.flex-column.wallet-view-account-details', {
|
2017-08-29 16:50:48 +02:00
|
|
|
style: {},
|
2017-07-31 06:25:32 +02:00
|
|
|
}, [
|
2017-10-24 08:59:21 +02:00
|
|
|
h('div.wallet-view__sidebar-close', {
|
|
|
|
onClick: hideSidebar,
|
|
|
|
}),
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
h('div.wallet-view__keyring-label.allcaps', isLoose ? this.context.t('imported') : ''),
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2017-10-24 09:54:49 +02:00
|
|
|
h('div.flex-column.flex-center.wallet-view__name-container', {
|
2017-10-24 08:59:21 +02:00
|
|
|
style: { margin: '0 auto' },
|
2017-10-24 09:54:49 +02:00
|
|
|
onClick: showAccountDetailModal,
|
2017-07-31 06:25:32 +02:00
|
|
|
}, [
|
2017-08-14 07:33:43 +02:00
|
|
|
h(Identicon, {
|
|
|
|
diameter: 54,
|
2018-04-17 21:57:55 +02:00
|
|
|
address: checksummedAddress,
|
2017-08-14 07:33:43 +02:00
|
|
|
}),
|
|
|
|
|
2017-08-07 06:54:42 +02:00
|
|
|
h('span.account-name', {
|
2017-08-29 16:50:48 +02:00
|
|
|
style: {},
|
2017-08-07 06:54:42 +02:00
|
|
|
}, [
|
2018-06-05 21:23:30 +02:00
|
|
|
identities[selectedAddress].name,
|
2017-08-07 06:54:42 +02:00
|
|
|
]),
|
2017-10-24 09:54:49 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
h('button.btn-clear.wallet-view__details-button.allcaps', this.context.t('details')),
|
2017-07-31 06:25:32 +02:00
|
|
|
]),
|
2017-07-31 07:10:59 +02:00
|
|
|
]),
|
2017-07-31 06:25:32 +02:00
|
|
|
|
2018-02-01 01:27:35 +01:00
|
|
|
h(Tooltip, {
|
|
|
|
position: 'bottom',
|
2018-03-29 17:00:44 +02:00
|
|
|
title: this.state.hasCopied ? this.context.t('copiedExclamation') : this.context.t('copyToClipboard'),
|
2018-02-01 01:27:35 +01:00
|
|
|
wrapperClassName: 'wallet-view__tooltip',
|
2017-10-25 05:04:29 +02:00
|
|
|
}, [
|
2018-02-01 01:27:35 +01:00
|
|
|
h('button.wallet-view__address', {
|
|
|
|
className: classnames({
|
|
|
|
'wallet-view__address__pressed': this.state.copyToClipboardPressed,
|
|
|
|
}),
|
|
|
|
onClick: () => {
|
2018-04-17 21:57:55 +02:00
|
|
|
copyToClipboard(checksummedAddress)
|
2018-02-01 01:27:35 +01:00
|
|
|
this.setState({ hasCopied: true })
|
|
|
|
setTimeout(() => this.setState({ hasCopied: false }), 3000)
|
|
|
|
},
|
|
|
|
onMouseDown: () => {
|
|
|
|
this.setState({ copyToClipboardPressed: true })
|
|
|
|
},
|
|
|
|
onMouseUp: () => {
|
|
|
|
this.setState({ copyToClipboardPressed: false })
|
|
|
|
},
|
|
|
|
}, [
|
2018-07-18 14:51:15 +02:00
|
|
|
`${checksummedAddress.slice(0, 6)}...${checksummedAddress.slice(-4)}`,
|
2018-02-01 01:27:35 +01:00
|
|
|
h('i.fa.fa-clipboard', { style: { marginLeft: '8px' } }),
|
|
|
|
]),
|
2017-10-24 08:59:21 +02:00
|
|
|
]),
|
|
|
|
|
2017-09-06 12:17:49 +02:00
|
|
|
this.renderWalletBalance(),
|
2017-08-11 09:31:06 +02:00
|
|
|
|
2017-09-06 12:17:49 +02:00
|
|
|
h(TokenList),
|
2017-09-05 10:48:52 +02:00
|
|
|
|
2018-03-26 07:19:42 +02:00
|
|
|
h('button.btn-primary.wallet-view__add-token-button', {
|
2018-05-11 01:51:26 +02:00
|
|
|
onClick: () => {
|
|
|
|
history.push(ADD_TOKEN_ROUTE)
|
|
|
|
sidebarOpen && hideSidebar()
|
|
|
|
},
|
2018-03-29 17:00:44 +02:00
|
|
|
}, this.context.t('addToken')),
|
2017-07-31 06:25:32 +02:00
|
|
|
])
|
|
|
|
}
|
2017-08-23 00:24:48 +02:00
|
|
|
|
|
|
|
// TODO: Extra wallets, for dev testing. Remove when PRing to master.
|
|
|
|
// const extraWallet = h('div.flex-column.wallet-balance-wrapper', {}, [
|
|
|
|
// h('div.wallet-balance', {}, [
|
|
|
|
// h(BalanceComponent, {
|
|
|
|
// balanceValue: selectedAccount.balance,
|
|
|
|
// style: {},
|
|
|
|
// }),
|
|
|
|
// ]),
|
|
|
|
// ])
|