You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
5.5 KiB
220 lines
5.5 KiB
7 years ago
|
const Component = require('react').Component
|
||
|
const PropTypes = require('react').PropTypes
|
||
|
const h = require('react-hyperscript')
|
||
|
const actions = require('../actions')
|
||
|
const genAccountLink = require('../../lib/account-link.js')
|
||
|
const connect = require('react-redux').connect
|
||
|
const Dropdown = require('./dropdown').Dropdown
|
||
|
const DropdownMenuItem = require('./dropdown').DropdownMenuItem
|
||
|
const Identicon = require('./identicon')
|
||
|
const ethUtil = require('ethereumjs-util')
|
||
|
const copyToClipboard = require('copy-to-clipboard')
|
||
|
|
||
|
class AccountDropdowns extends Component {
|
||
|
constructor (props) {
|
||
|
super(props)
|
||
|
this.state = {
|
||
7 years ago
|
accountSelectorActive: false,
|
||
|
optionsMenuActive: false,
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
renderAccounts () {
|
||
7 years ago
|
const { identities, selected } = this.props
|
||
|
|
||
|
return Object.keys(identities).map((key) => {
|
||
|
const identity = identities[key]
|
||
|
const isSelected = identity.address === selected
|
||
|
|
||
|
return h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => {
|
||
|
this.props.actions.showAccountDetail(identity.address)
|
||
|
},
|
||
|
},
|
||
|
[
|
||
|
h(
|
||
|
Identicon,
|
||
|
{
|
||
|
address: identity.address,
|
||
|
diameter: 16,
|
||
|
},
|
||
|
),
|
||
|
h('span', { style: { marginLeft: '10px' } }, identity.name || ''),
|
||
|
h('span', { style: { marginLeft: '10px' } }, isSelected ? h('.check', '✓') : null),
|
||
|
]
|
||
|
)
|
||
|
})
|
||
|
}
|
||
|
|
||
7 years ago
|
renderAccountSelector () {
|
||
|
const { actions } = this.props
|
||
|
const { accountSelectorActive } = this.state
|
||
|
|
||
|
return h(
|
||
|
Dropdown,
|
||
|
{
|
||
|
style: {
|
||
|
marginLeft: '-125px',
|
||
|
minWidth: '180px',
|
||
|
},
|
||
|
isOpen: accountSelectorActive,
|
||
|
onClickOutside: () => { this.setState({ accountSelectorActive: false }) },
|
||
|
},
|
||
|
[
|
||
|
...this.renderAccounts(),
|
||
|
h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => actions.addNewAccount(),
|
||
|
},
|
||
|
[
|
||
|
h(
|
||
|
Identicon,
|
||
|
{
|
||
|
diameter: 16,
|
||
|
},
|
||
|
),
|
||
|
h('span', { style: { marginLeft: '10px' } }, 'Create Account'),
|
||
|
],
|
||
|
),
|
||
|
h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => actions.showImportPage(),
|
||
|
},
|
||
|
[
|
||
|
h(
|
||
|
Identicon,
|
||
|
{
|
||
|
diameter: 16,
|
||
|
},
|
||
|
),
|
||
|
h('span', { style: { marginLeft: '10px' } }, 'Import Account'),
|
||
|
]
|
||
|
),
|
||
|
]
|
||
|
)
|
||
|
}
|
||
|
|
||
|
renderAccountOptions () {
|
||
|
const { actions } = this.props
|
||
|
const { optionsMenuActive } = this.state
|
||
|
|
||
|
return h(
|
||
|
Dropdown,
|
||
|
{
|
||
|
style: {
|
||
|
marginLeft: '-162px',
|
||
|
minWidth: '180px',
|
||
|
},
|
||
|
isOpen: optionsMenuActive,
|
||
|
onClickOutside: () => { this.setState({ optionsMenuActive: false }) },
|
||
|
},
|
||
|
[
|
||
|
h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => {
|
||
|
const { selected, network } = this.props
|
||
|
const url = genAccountLink(selected, network)
|
||
|
global.platform.openWindow({ url })
|
||
|
},
|
||
|
},
|
||
|
'View account on Etherscan',
|
||
|
),
|
||
|
h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => {
|
||
|
const { selected } = this.props
|
||
|
const checkSumAddress = selected && ethUtil.toChecksumAddress(selected)
|
||
|
copyToClipboard(checkSumAddress)
|
||
|
},
|
||
|
},
|
||
|
'Copy Address to clipboard',
|
||
|
),
|
||
|
h(
|
||
|
DropdownMenuItem,
|
||
|
{
|
||
|
closeMenu: () => {},
|
||
|
onClick: () => {
|
||
|
actions.requestAccountExport()
|
||
|
},
|
||
|
},
|
||
|
'Export Private Key',
|
||
|
),
|
||
|
]
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
7 years ago
|
const { style } = this.props
|
||
|
const { optionsMenuActive, accountSelectorActive } = this.state
|
||
7 years ago
|
|
||
|
return h(
|
||
|
'span',
|
||
|
{
|
||
|
style: style,
|
||
|
},
|
||
|
[
|
||
|
h(
|
||
|
'i.fa.fa-angle-down',
|
||
|
{
|
||
|
style: {},
|
||
|
onClick: (event) => {
|
||
|
event.stopPropagation()
|
||
|
this.setState({
|
||
7 years ago
|
accountSelectorActive: !accountSelectorActive,
|
||
|
optionsMenuActive: false,
|
||
7 years ago
|
})
|
||
|
},
|
||
|
},
|
||
7 years ago
|
this.renderAccountSelector(),
|
||
7 years ago
|
),
|
||
|
h(
|
||
|
'i.fa.fa-ellipsis-h',
|
||
|
{
|
||
|
style: { 'marginLeft': '10px'},
|
||
|
onClick: (event) => {
|
||
|
event.stopPropagation()
|
||
|
this.setState({
|
||
7 years ago
|
accountSelectorActive: false,
|
||
|
optionsMenuActive: !optionsMenuActive,
|
||
7 years ago
|
})
|
||
|
},
|
||
|
},
|
||
7 years ago
|
this.renderAccountOptions()
|
||
7 years ago
|
),
|
||
|
]
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
AccountDropdowns.propTypes = {
|
||
|
identities: PropTypes.objectOf(PropTypes.object),
|
||
|
selected: PropTypes.string,
|
||
|
}
|
||
|
|
||
7 years ago
|
const mapDispatchToProps = (dispatch) => {
|
||
7 years ago
|
return {
|
||
|
actions: {
|
||
|
showConfigPage: () => dispatch(actions.showConfigPage()),
|
||
|
requestAccountExport: () => dispatch(actions.requestExportAccount()),
|
||
|
showAccountDetail: (address) => dispatch(actions.showAccountDetail(address)),
|
||
|
addNewAccount: () => dispatch(actions.addNewAccount()),
|
||
|
showImportPage: () => dispatch(actions.showImportPage()),
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
AccountDropdowns: connect(null, mapDispatchToProps)(AccountDropdowns),
|
||
|
}
|