aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/unlock.js
blob: de372817deeb6a88c89271048e427c96c410e6e8 (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
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 getCaretCoordinates = require('textarea-caret')
const EventEmitter = require('events').EventEmitter

const Mascot = require('./components/mascot')

module.exports = connect(mapStateToProps)(UnlockScreen)

inherits(UnlockScreen, Component)
function UnlockScreen () {
  Component.call(this)
  this.animationEventEmitter = new EventEmitter()
}

function mapStateToProps (state) {
  return {
    warning: state.appState.warning,
  }
}

UnlockScreen.prototype.render = function () {
  const state = this.props
  const warning = state.warning
  return (
    h('.flex-column', [
      h('.unlock-screen.flex-column.flex-center.flex-grow', [

        h(Mascot, {
          animationEventEmitter: this.animationEventEmitter,
        }),

        h('h1', {
          style: {
            fontSize: '1.4em',
            textTransform: 'uppercase',
            color: '#7F8082',
          },
        }, 'MetaMask'),

        h('input.large-input', {
          type: 'password',
          id: 'password-box',
          placeholder: 'enter password',
          style: {

          },
          onKeyPress: this.onKeyPress.bind(this),
          onInput: this.inputChanged.bind(this),
        }),

        h('.error', {
          style: {
            display: warning ? 'block' : 'none',
            padding: '0 20px',
            textAlign: 'center',
          },
        }, warning),

        h('button.primary.cursor-pointer', {
          onClick: this.onSubmit.bind(this),
          style: {
            margin: 10,
          },
        }, 'Unlock'),
      ]),

      h('.flex-row.flex-center.flex-grow', [
        h('p.pointer', {
          onClick: () => this.props.dispatch(actions.forgotPassword()),
          style: {
            fontSize: '0.8em',
            color: 'rgb(247, 134, 28)',
            textDecoration: 'underline',
          },
        }, 'I forgot my password.'),
      ]),
    ])
  )
}

UnlockScreen.prototype.componentDidMount = function () {
  document.getElementById('password-box').focus()
}

UnlockScreen.prototype.onSubmit = function (event) {
  const input = document.getElementById('password-box')
  const password = input.value
  this.props.dispatch(actions.tryUnlockMetamask(password))
}

UnlockScreen.prototype.onKeyPress = function (event) {
  if (event.key === 'Enter') {
    this.submitPassword(event)
  }
}

UnlockScreen.prototype.submitPassword = function (event) {
  var element = event.target
  var password = element.value
  // reset input
  element.value = ''
  this.props.dispatch(actions.tryUnlockMetamask(password))
}

UnlockScreen.prototype.inputChanged = function (event) {
  // tell mascot to look at page action
  var element = event.target
  var viewRect = element.getBoundingClientRect()
  var carat = getCaretCoordinates(element, element.selectionEnd)
  var x = viewRect.right - carat.left + element.scrollLeft
  var y = 300
  var pointAt = { x, y }
  this.animationEventEmitter.emit('point', pointAt)
}