aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/account-detail.js
blob: 6ed23d482ee8d234bfb6a9ee5694116835fd3e3a (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
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const copyToClipboard = require('copy-to-clipboard')
const actions = require('./actions')
const AccountPanel = require('./components/account-panel')

module.exports = connect(mapStateToProps)(AccountDetailScreen)

function mapStateToProps(state) {
  var accountDetail = state.appState.accountDetail
  return {
    identities: state.metamask.identities,
    accounts: state.metamask.accounts,
    address: state.appState.currentView.context,
    accountDetail: accountDetail,
  }
}

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


AccountDetailScreen.prototype.render = function() {
  var state = this.props
  var identity = state.identities[state.address]
  var account = state.accounts[state.address]
  var accountDetail = state.accountDetail

  return (

    h('.account-detail-section.flex-column.flex-grow', [

      // subtitle and nav
      h('.section-title.flex-row.flex-center', [
        h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
          onClick: this.navigateToAccounts.bind(this),
        }),
        h('h2.page-subtitle', 'Account Detail'),
      ]),

      // account summary, with embedded action buttons
      h(AccountPanel, {
        showFullAddress: true,
        identity: identity,
        account: account,
      }, [
        h('.flex-row.flex-space-around', [
          // h('button', 'GET ETH'), DISABLED UNTIL WORKING

          h('button', {
            onClick: () => {
              copyToClipboard(identity.address)
            },
          }, 'COPY ADDR'),

          h('button', {
            onClick: () => {
              this.props.dispatch(actions.showSendPage())
            },
          }, 'SEND'),

          h('button', {
            onClick: () => {
              this.requestAccountExport(identity.address)
            },
          }, 'EXPORT'),
        ]),
      ]),

      this.exportedAccount(accountDetail),

      // transaction table
      /*
      h('section.flex-column', [
        h('span', 'your transaction history will go here.'),
      ]),
      */
    ])
  )
}

AccountDetailScreen.prototype.navigateToAccounts = function(event){
  event.stopPropagation()
  this.props.dispatch(actions.showAccountsPage())
}

AccountDetailScreen.prototype.exportAccount = function(address) {
  this.props.dispatch(actions.exportAccount(address))
}

AccountDetailScreen.prototype.requestAccountExport = function() {
  this.props.dispatch(actions.requestExportAccount())
}

AccountDetailScreen.prototype.exportedAccount = function(accountDetail) {
  if (!accountDetail) return
  var accountExport = accountDetail.accountExport

  var notExporting = accountExport === 'none'
  var exportRequested = accountExport === 'requested'
  var accountExported = accountExport === 'completed'

  if (notExporting) return

  if (exportRequested) {
    var warning = `Exporting your private key is very dangerous,
      and you should only do it if you know what you're doing.`
    var confirmation = `If you're absolutely sure, type "I understand" below and
                        hit Enter.`
    return h('div', {}, [
      h('p.error', warning),
      h('p', confirmation),
      h('input#exportAccount', {
        onKeyPress: this.onExportKeyPress.bind(this),
      })
    ])
  }

  if (accountExported) {
    return h('div.privateKey', {

    }, [
      h('label', 'Your private key (click to copy):'),
      h('p.error.cursor-pointer', {
        style: {
          textOverflow: 'ellipsis',
          overflow: 'hidden',
          webkitUserSelect: 'text',
          width: '100%',
        },
        onClick: function(event) {
          copyToClipboard(accountDetail.privateKey)
        }
      }, accountDetail.privateKey),
    ])
  }
}

AccountDetailScreen.prototype.onExportKeyPress = function(event) {
  if (event.key !== 'Enter') return
  event.preventDefault()

  var input = document.getElementById('exportAccount')
  if (input.value === 'I understand') {
    this.props.dispatch(actions.exportAccount(this.props.address))
  } else {
    input.value = ''
    input.placeholder = 'Please retype "I understand" exactly.'
  }
}