aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/unlock.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-04-14 06:28:44 +0800
committerDan Finlay <dan@danfinlay.com>2016-04-14 06:28:44 +0800
commitd814a45dffa6a872f6e336cad33ca41ffb102887 (patch)
treed8cdd0c4b8c6559efaf6846b24f0d6440f3c94f5 /ui/app/unlock.js
parent9f1438b85b3dac8f1dd98f7bd6e101035cfce0a5 (diff)
downloadtangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.gz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.bz2
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.lz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.xz
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.tar.zst
tangerine-wallet-browser-d814a45dffa6a872f6e336cad33ca41ffb102887.zip
Moved UI into repo with its own dependency stack
Diffstat (limited to 'ui/app/unlock.js')
-rw-r--r--ui/app/unlock.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/ui/app/unlock.js b/ui/app/unlock.js
new file mode 100644
index 000000000..8aac1b1ff
--- /dev/null
+++ b/ui/app/unlock.js
@@ -0,0 +1,101 @@
+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 Mascot = require('./components/mascot')
+const getCaretCoordinates = require('textarea-caret')
+const EventEmitter = require('events').EventEmitter
+
+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('.unlock-screen.flex-column.flex-center.flex-grow', [
+
+ h('h2.page-subtitle', 'Welcome!'),
+
+ h(Mascot, {
+ animationEventEmitter: this.animationEventEmitter,
+ }),
+
+ h('label', {
+ htmlFor: 'password-box',
+ }, 'Enter Password:'),
+
+ h('input', {
+ type: 'password',
+ id: 'password-box',
+ onKeyPress: this.onKeyPress.bind(this),
+ onInput: this.inputChanged.bind(this),
+ }),
+
+ h('.error', {
+ style: {
+ display: warning ? 'block' : 'none',
+ }
+ }, warning),
+
+ h('button.primary.cursor-pointer', {
+ onClick: this.onSubmit.bind(this),
+ }, 'Unlock'),
+
+ ])
+
+ )
+}
+
+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 boundingRect = element.getBoundingClientRect()
+ var coordinates = getCaretCoordinates(element, element.selectionEnd)
+ this.animationEventEmitter.emit('point', {
+ x: boundingRect.left + coordinates.left - element.scrollLeft,
+ y: boundingRect.top + coordinates.top - element.scrollTop,
+ })
+}
+
+UnlockScreen.prototype.emitAnim = function(name, a, b, c){
+ this.animationEventEmitter.emit(name, a, b, c)
+}