aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/dropdowns/account-details-dropdown.js
blob: bda8b9517834aa1329da8c30fa8c7a38fbb867fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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,
  metricsEvent: 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 () {
  const {
    selectedIdentity,
    network,
    keyrings,
    showAccountDetailModal,
    viewOnEtherscan,
    showRemoveAccountConfirmationModal } = this.props

  const address = selectedIdentity.address

  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()
        this.context.metricsEvent({
          eventOpts: {
            category: 'Navigation',
            action: 'Account Options',
            name: 'Clicked Expand View',
          },
        })
        global.platform.openExtensionInBrowser()
        this.props.onClose()
      },
      text: this.context.t('expandView'),
      icon: h(`img`, { src: 'images/expand.svg', style: { height: '15px' } }),
    }),
    h(Item, {
      onClick: (e) => {
        e.stopPropagation()
        showAccountDetailModal()
        this.context.metricsEvent({
          eventOpts: {
            category: 'Navigation',
            action: 'Account Options',
            name: 'Viewed Account Details',
          },
        })
        this.props.onClose()
      },
      text: this.context.t('accountDetails'),
      icon: h(`img`, { src: 'images/info.svg', style: { height: '15px' } }),
    }),
    h(Item, {
      onClick: (e) => {
        e.stopPropagation()
        this.context.metricsEvent({
          eventOpts: {
            category: 'Navigation',
            action: 'Account Options',
            name: 'Clicked View on Etherscan',
          },
        })
        viewOnEtherscan(address, network)
        this.props.onClose()
      },
      text: this.context.t('viewOnEtherscan'),
      icon: h(`img`, { src: 'images/open-etherscan.svg', style: { height: '15px' } }),
    }),
    isRemovable ? h(Item, {
      onClick: (e) => {
        e.stopPropagation()
        showRemoveAccountConfirmationModal(selectedIdentity)
        this.props.onClose()
      },
      text: this.context.t('removeAccount'),
      icon: h(`img`, { src: 'images/hide.svg', style: { height: '15px' } }),
    }) : null,
  ])
}