1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/ui/app/components/dropdowns/token-menu-dropdown.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-09-29 12:10:50 +02:00
const Component = require('react').Component
const PropTypes = require('prop-types')
2017-09-29 12:10:50 +02:00
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
2017-09-29 21:03:29 +02:00
const actions = require('../../actions')
const genAccountLink = require('etherscan-link').createAccountLink
const copyToClipboard = require('copy-to-clipboard')
const { Menu, Item, CloseArea } = require('./components/menu')
2017-09-29 21:03:29 +02:00
TokenMenuDropdown.contextTypes = {
t: PropTypes.func,
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(TokenMenuDropdown)
2017-09-29 21:03:29 +02:00
function mapStateToProps (state) {
return {
network: state.metamask.network,
}
}
2017-09-29 21:03:29 +02:00
function mapDispatchToProps (dispatch) {
return {
showHideTokenConfirmationModal: (token) => {
dispatch(actions.showModal({ name: 'HIDE_TOKEN_CONFIRMATION', token }))
2017-11-02 13:15:59 +01:00
},
2017-09-29 21:03:29 +02:00
}
}
2017-09-29 12:10:50 +02:00
inherits(TokenMenuDropdown, Component)
function TokenMenuDropdown () {
Component.call(this)
this.onClose = this.onClose.bind(this)
}
TokenMenuDropdown.prototype.onClose = function (e) {
e.stopPropagation()
this.props.onClose()
}
TokenMenuDropdown.prototype.render = function () {
2017-09-29 21:03:29 +02:00
const { showHideTokenConfirmationModal } = this.props
return h(Menu, { className: 'token-menu-dropdown', isShowing: true }, [
h(CloseArea, {
2017-09-29 12:10:50 +02:00
onClick: this.onClose,
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
showHideTokenConfirmationModal(this.props.token)
this.props.onClose()
},
2018-07-03 00:49:33 +02:00
text: this.context.t('hideToken'),
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
copyToClipboard(this.props.token.address)
this.props.onClose()
},
2018-07-03 00:49:33 +02:00
text: this.context.t('copyContractAddress'),
}),
h(Item, {
onClick: (e) => {
e.stopPropagation()
const url = genAccountLink(this.props.token.address, this.props.network)
global.platform.openWindow({ url })
this.props.onClose()
},
2018-07-03 00:49:33 +02:00
text: this.context.t('viewOnEtherscan'),
}),
2017-09-29 12:10:50 +02:00
])
}