2017-11-29 05:24:35 +01:00
|
|
|
const { Component } = require('react')
|
|
|
|
const PropTypes = require('prop-types')
|
2018-03-30 23:51:11 +02:00
|
|
|
const connect = require('../../metamask-connect')
|
2017-11-29 05:24:35 +01:00
|
|
|
const h = require('react-hyperscript')
|
2017-12-04 21:13:02 +01:00
|
|
|
const { withRouter } = require('react-router-dom')
|
2017-11-29 05:24:35 +01:00
|
|
|
const { compose } = require('recompose')
|
2018-03-30 23:51:11 +02:00
|
|
|
const {
|
|
|
|
tryUnlockMetamask,
|
|
|
|
forgotPassword,
|
|
|
|
markPasswordForgotten,
|
|
|
|
setNetworkEndpoints,
|
|
|
|
setFeatureFlag,
|
|
|
|
} = require('../../actions')
|
|
|
|
const environmentType = require('../../../../app/scripts/lib/environment-type')
|
2017-11-29 05:24:35 +01:00
|
|
|
const getCaretCoordinates = require('textarea-caret')
|
|
|
|
const EventEmitter = require('events').EventEmitter
|
2017-12-04 21:13:02 +01:00
|
|
|
const Mascot = require('../mascot')
|
2018-03-30 23:51:11 +02:00
|
|
|
const { OLD_UI_NETWORK_TYPE } = require('../../../../app/scripts/config').enums
|
|
|
|
const { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } = require('../../routes')
|
2017-11-29 05:24:35 +01:00
|
|
|
|
|
|
|
class UnlockScreen extends Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
error: null,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.animationEventEmitter = new EventEmitter()
|
|
|
|
}
|
|
|
|
|
2017-12-04 21:13:02 +01:00
|
|
|
componentWillMount () {
|
|
|
|
const { isUnlocked, history } = this.props
|
|
|
|
|
|
|
|
if (isUnlocked) {
|
|
|
|
history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 05:24:35 +01:00
|
|
|
componentDidMount () {
|
|
|
|
const passwordBox = document.getElementById('password-box')
|
|
|
|
|
|
|
|
if (passwordBox) {
|
|
|
|
passwordBox.focus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tryUnlockMetamask (password) {
|
|
|
|
const { tryUnlockMetamask, history } = this.props
|
|
|
|
tryUnlockMetamask(password)
|
|
|
|
.then(() => history.push(DEFAULT_ROUTE))
|
|
|
|
.catch(({ message }) => this.setState({ error: message }))
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit (event) {
|
|
|
|
const input = document.getElementById('password-box')
|
|
|
|
const password = input.value
|
|
|
|
this.tryUnlockMetamask(password)
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyPress (event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
this.submitPassword(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
submitPassword (event) {
|
|
|
|
var element = event.target
|
|
|
|
var password = element.value
|
|
|
|
// reset input
|
|
|
|
element.value = ''
|
|
|
|
this.tryUnlockMetamask(password)
|
|
|
|
}
|
|
|
|
|
|
|
|
inputChanged (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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { error } = this.state
|
|
|
|
return (
|
2018-03-30 23:51:11 +02:00
|
|
|
h('.unlock-screen', [
|
|
|
|
|
|
|
|
h(Mascot, {
|
|
|
|
animationEventEmitter: this.animationEventEmitter,
|
|
|
|
}),
|
|
|
|
|
|
|
|
h('h1', {
|
|
|
|
style: {
|
|
|
|
fontSize: '1.4em',
|
|
|
|
textTransform: 'uppercase',
|
|
|
|
color: '#7F8082',
|
|
|
|
},
|
|
|
|
}, this.props.t('appName')),
|
|
|
|
|
|
|
|
h('input.large-input', {
|
|
|
|
type: 'password',
|
|
|
|
id: 'password-box',
|
|
|
|
placeholder: 'enter password',
|
|
|
|
style: {
|
|
|
|
background: 'white',
|
|
|
|
},
|
|
|
|
onKeyPress: this.onKeyPress.bind(this),
|
|
|
|
onInput: this.inputChanged.bind(this),
|
|
|
|
}),
|
|
|
|
|
|
|
|
h('.error', {
|
|
|
|
style: {
|
|
|
|
display: error ? 'block' : 'none',
|
|
|
|
padding: '0 20px',
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
}, error),
|
|
|
|
|
|
|
|
h('button.primary.cursor-pointer', {
|
|
|
|
onClick: this.onSubmit.bind(this),
|
|
|
|
style: {
|
|
|
|
margin: 10,
|
|
|
|
},
|
|
|
|
}, this.props.t('login')),
|
|
|
|
|
|
|
|
h('p.pointer', {
|
|
|
|
onClick: () => {
|
|
|
|
this.props.markPasswordForgotten()
|
|
|
|
this.props.history.push(RESTORE_VAULT_ROUTE)
|
|
|
|
|
|
|
|
console.log('typeeee', environmentType())
|
|
|
|
if (environmentType() === 'popup') {
|
|
|
|
global.platform.openExtensionInBrowser()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
fontSize: '0.8em',
|
|
|
|
color: 'rgb(247, 134, 28)',
|
|
|
|
textDecoration: 'underline',
|
|
|
|
},
|
|
|
|
}, this.props.t('restoreFromSeed')),
|
|
|
|
|
|
|
|
h('p.pointer', {
|
|
|
|
onClick: () => {
|
|
|
|
this.props.useOldInterface()
|
|
|
|
.then(() => this.props.setNetworkEndpoints(OLD_UI_NETWORK_TYPE))
|
|
|
|
},
|
2017-11-29 05:24:35 +01:00
|
|
|
style: {
|
2018-03-30 23:51:11 +02:00
|
|
|
fontSize: '0.8em',
|
|
|
|
color: '#aeaeae',
|
|
|
|
textDecoration: 'underline',
|
|
|
|
marginTop: '32px',
|
2017-11-29 05:24:35 +01:00
|
|
|
},
|
2018-03-30 23:51:11 +02:00
|
|
|
}, this.props.t('classicInterface')),
|
2017-11-29 05:24:35 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnlockScreen.propTypes = {
|
|
|
|
forgotPassword: PropTypes.func,
|
|
|
|
tryUnlockMetamask: PropTypes.func,
|
2018-02-08 23:16:58 +01:00
|
|
|
markPasswordForgotten: PropTypes.func,
|
2017-11-29 05:24:35 +01:00
|
|
|
history: PropTypes.object,
|
|
|
|
isUnlocked: PropTypes.bool,
|
2018-03-30 23:51:11 +02:00
|
|
|
t: PropTypes.func,
|
|
|
|
useOldInterface: PropTypes.func,
|
|
|
|
setNetworkEndpoints: PropTypes.func,
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const { metamask: { isUnlocked } } = state
|
|
|
|
return {
|
|
|
|
isUnlocked,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
forgotPassword: () => dispatch(forgotPassword()),
|
|
|
|
tryUnlockMetamask: password => dispatch(tryUnlockMetamask(password)),
|
2018-02-08 23:16:58 +01:00
|
|
|
markPasswordForgotten: () => dispatch(markPasswordForgotten()),
|
2018-03-30 23:51:11 +02:00
|
|
|
useOldInterface: () => dispatch(setFeatureFlag('betaUI', false, 'OLD_UI_NOTIFICATION_MODAL')),
|
|
|
|
setNetworkEndpoints: type => dispatch(setNetworkEndpoints(type)),
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(UnlockScreen)
|