aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/account-export.js
blob: 6d8b099a5e6a2424e59a966aae8a22658aa3464e (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
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const copyToClipboard = require('copy-to-clipboard')
const actions = require('../actions')
const ethUtil = require('ethereumjs-util')

module.exports = ExportAccountView

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

ExportAccountView.prototype.render = function () {
  console.log('EXPORT VIEW')
  console.dir(this.props)
  var state = this.props
  var accountDetail = state.accountDetail

  if (!accountDetail) return h('div')
  var accountExport = accountDetail.accountExport

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

  if (notExporting) return h('div')

  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
                        submit.`
    return (

      h('div', {
        key: 'exporting',
        style: {
          margin: '0 20px',
        },
      }, [
        h('p.error', warning),
        h('p', confirmation),
        h('input#exportAccount.sizing-input', {
          onKeyPress: this.onExportKeyPress.bind(this),
          style: {
            position: 'relative',
            top: '1.5px',
          },
        }),
        h('button', {
          onClick: () => this.onExportKeyPress({ key: 'Enter', preventDefault: () => {} }),
        }, 'Submit'),
        h('button', {
          onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
        }, 'Cancel'),
      ])

    )
  }

  if (accountExported) {
    return h('div.privateKey', {
      style: {
        margin: '0 20px',
      },
    }, [
      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(ethUtil.stripHexPrefix(accountDetail.privateKey))
        },
      }, ethUtil.stripHexPrefix(accountDetail.privateKey)),
      h('button', {
        onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
      }, 'Done'),
    ])
  }
}

ExportAccountView.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.'
  }
}

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