aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/accounts/index.js
blob: 7551c498e1416f54896618ce64dfc05a1c489a39 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('../actions')
const valuesFor = require('../util').valuesFor
const findDOMNode = require('react-dom').findDOMNode
const AccountListItem = require('./account-list-item')

module.exports = connect(mapStateToProps)(AccountsScreen)

function mapStateToProps (state) {
  const pendingTxs = valuesFor(state.metamask.unconfTxs)
  .filter(tx => tx.txParams.metamaskNetworkId === state.metamask.network)
  const pendingMsgs = valuesFor(state.metamask.unconfMsgs)
  const pending = pendingTxs.concat(pendingMsgs)

  return {
    accounts: state.metamask.accounts,
    identities: state.metamask.identities,
    unconfTxs: state.metamask.unconfTxs,
    selectedAddress: state.metamask.selectedAddress,
    scrollToBottom: state.appState.scrollToBottom,
    pending,
  }
}

inherits(AccountsScreen, Component)
function AccountsScreen () {
  Component.call(this)
}

AccountsScreen.prototype.render = function () {
  var state = this.props
  var identityList = valuesFor(state.identities)
  var unconfTxList = valuesFor(state.unconfTxs)
  var actions = {
    onSelect: this.onSelect.bind(this),
    onShowDetail: this.onShowDetail.bind(this),
    goHome: this.goHome.bind(this),
  }
  return (

    h('.accounts-section.flex-grow', [

      // subtitle and nav
      h('.section-title.flex-center', [
        h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
          onClick: actions.goHome,
        }),
        h('h2.page-subtitle', 'Select Account'),
      ]),

      h('hr.horizontal-line'),

      // identity selection
      h('section.identity-section', {
        style: {
          height: '418px',
          overflowY: 'auto',
          overflowX: 'hidden',
        },
      },
        [
          identityList.map((identity) => {
            const pending = this.props.pending.filter((txOrMsg) => {
              if ('txParams' in txOrMsg) {
                return txOrMsg.txParams.from === identity.address
              } else if ('msgParams' in txOrMsg) {
                return txOrMsg.msgParams.from === identity.address
              } else {
                return false
              }
            })

            return h(AccountListItem, {
              key: `acct-panel-${identity.address}`,
              identity,
              selectedAddress: this.props.selectedAddress,
              accounts: this.props.accounts,
              onShowDetail: this.onShowDetail.bind(this),
              pending,
            })
          }),

          h('hr.horizontal-line'),
          h('div.footer.hover-white.pointer', {
            key: 'reveal-account-bar',
            onClick: () => {
              this.onRevealAccount()
            },
            style: {
              display: 'flex',
              height: '40px',
              paddint: '10px',
              justifyContent: 'center',
              alignItems: 'center',
            },
          }, [
            h('i.fa.fa-plus.fa-lg', {key: ''}),
          ]),
          h('hr.horizontal-line'),
        ]),

      unconfTxList.length ? (

        h('.unconftx-link.flex-row.flex-center', {
          onClick: this.navigateToConfTx.bind(this),
        }, [
          h('span', 'Unconfirmed Txs'),
          h('i.fa.fa-arrow-right.fa-lg'),
        ])

      ) : (
        null
      ),
    ])
  )
}

// If a new account was revealed, scroll to the bottom
AccountsScreen.prototype.componentDidUpdate = function () {
  const scrollToBottom = this.props.scrollToBottom

  if (scrollToBottom) {
    var container = findDOMNode(this)
    var scrollable = container.querySelector('.identity-section')
    scrollable.scrollTop = scrollable.scrollHeight
  }
}

AccountsScreen.prototype.navigateToConfTx = function () {
  event.stopPropagation()
  this.props.dispatch(actions.showConfTxPage())
}

AccountsScreen.prototype.onSelect = function (address, event) {
  event.stopPropagation()
  // if already selected, deselect
  if (this.props.selectedAddress === address) address = null
  this.props.dispatch(actions.setSelectedAddress(address))
}

AccountsScreen.prototype.onShowDetail = function (address, event) {
  event.stopPropagation()
  this.props.dispatch(actions.showAccountDetail(address))
}

AccountsScreen.prototype.onRevealAccount = function () {
  this.props.dispatch(actions.revealAccount())
}

AccountsScreen.prototype.goHome = function () {
  this.props.dispatch(actions.goHome())
}