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

110 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-10-03 03:29:03 +02:00
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
const actions = require('../../actions')
const { getSelectedIdentity } = require('../../selectors')
const genAccountLink = require('../../../lib/account-link.js')
const { Menu, Item, CloseArea } = require('./components/menu')
AccountDetailsDropdown.contextTypes = {
t: PropTypes.func,
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(AccountDetailsDropdown)
function mapStateToProps (state) {
return {
selectedIdentity: getSelectedIdentity(state),
network: state.metamask.network,
keyrings: state.metamask.keyrings,
}
}
function mapDispatchToProps (dispatch) {
return {
showAccountDetailModal: () => {
dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' }))
},
viewOnEtherscan: (address, network) => {
global.platform.openWindow({ url: genAccountLink(address, network) })
},
showRemoveAccountConfirmationModal: (identity) => {
return dispatch(actions.showModal({ name: 'CONFIRM_REMOVE_ACCOUNT', identity }))
},
}
}
inherits(AccountDetailsDropdown, Component)
function AccountDetailsDropdown () {
Component.call(this)
this.onClose = this.onClose.bind(this)
}
AccountDetailsDropdown.prototype.onClose = function (e) {
e.stopPropagation()
this.props.onClose()
}
AccountDetailsDropdown.prototype.render = function () {
2018-10-03 17:35:07 +02:00
const {
selectedIdentity,
2018-10-03 03:29:03 +02:00
network,
keyrings,
2018-10-03 17:35:07 +02:00
showAccountDetailModal,
2018-10-03 03:29:03 +02:00
viewOnEtherscan,
showRemoveAccountConfirmationModal } = this.props
2018-10-03 17:35:07 +02:00
const address = selectedIdentity.address
2018-10-03 03:29:03 +02:00
const keyring = keyrings.find((kr) => {
return kr.accounts.includes(address)
})
const isRemovable = keyring.type !== 'HD Key Tree'
return h(Menu, { className: 'account-details-dropdown', isShowing: true }, [
h(CloseArea, {
onClick: this.onClose,
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
global.platform.openExtensionInBrowser()
this.props.onClose()
},
text: this.context.t('expandView'),
2018-10-03 17:35:07 +02:00
icon: h(`img`, { src: 'images/expand.svg', style: { height: '15px' } }),
2018-10-03 03:29:03 +02:00
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
showAccountDetailModal()
this.props.onClose()
},
text: this.context.t('accountDetails'),
2018-10-03 17:35:07 +02:00
icon: h(`img`, { src: 'images/info.svg', style: { height: '15px' } }),
2018-10-03 03:29:03 +02:00
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
viewOnEtherscan(address, network)
this.props.onClose()
},
text: this.context.t('viewOnEtherscan'),
2018-10-03 17:35:07 +02:00
icon: h(`img`, { src: 'images/open-etherscan.svg', style: { height: '15px' } }),
2018-10-03 03:29:03 +02:00
}),
isRemovable ? h(Item, {
onClick: (e) => {
e.stopPropagation()
showRemoveAccountConfirmationModal(selectedIdentity)
this.props.onClose()
},
text: this.context.t('removeAccount'),
2018-10-03 17:35:07 +02:00
icon: h(`img`, { src: 'images/hide.svg', style: { height: '15px' } }),
}) : null,
2018-10-03 03:29:03 +02:00
])
2018-10-03 17:35:07 +02:00
}