2019-01-23 16:25:34 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-03-22 00:03:30 +01:00
|
|
|
import Button from '../../../../components/ui/button'
|
2019-01-23 16:25:34 +01:00
|
|
|
import {
|
2019-03-05 16:45:01 +01:00
|
|
|
INITIALIZE_SEED_PHRASE_ROUTE,
|
2019-02-27 15:46:41 +01:00
|
|
|
INITIALIZE_SELECT_ACTION_ROUTE,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../../../helpers/constants/routes'
|
|
|
|
import TextField from '../../../../components/ui/text-field'
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
export default class NewAccount extends PureComponent {
|
|
|
|
static contextTypes = {
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2019-01-23 16:25:34 +01:00
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
password: '',
|
|
|
|
confirmPassword: '',
|
|
|
|
passwordError: '',
|
|
|
|
confirmPasswordError: '',
|
2019-02-27 15:46:41 +01:00
|
|
|
termsChecked: false,
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
isValid () {
|
|
|
|
const {
|
|
|
|
password,
|
|
|
|
confirmPassword,
|
|
|
|
passwordError,
|
|
|
|
confirmPasswordError,
|
|
|
|
} = this.state
|
|
|
|
|
|
|
|
if (!password || !confirmPassword || password !== confirmPassword) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password.length < 8) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return !passwordError && !confirmPasswordError
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePasswordChange (password) {
|
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
this.setState(state => {
|
|
|
|
const { confirmPassword } = state
|
|
|
|
let passwordError = ''
|
|
|
|
let confirmPasswordError = ''
|
|
|
|
|
|
|
|
if (password && password.length < 8) {
|
|
|
|
passwordError = t('passwordNotLongEnough')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (confirmPassword && password !== confirmPassword) {
|
|
|
|
confirmPasswordError = t('passwordsDontMatch')
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
password,
|
|
|
|
passwordError,
|
|
|
|
confirmPasswordError,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
handleConfirmPasswordChange (confirmPassword) {
|
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
this.setState(state => {
|
|
|
|
const { password } = state
|
|
|
|
let confirmPasswordError = ''
|
|
|
|
|
|
|
|
if (password !== confirmPassword) {
|
|
|
|
confirmPasswordError = t('passwordsDontMatch')
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
confirmPassword,
|
|
|
|
confirmPasswordError,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCreate = async event => {
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
if (!this.isValid()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const { password } = this.state
|
|
|
|
const { onSubmit, history } = this.props
|
|
|
|
|
|
|
|
try {
|
|
|
|
await onSubmit(password)
|
2019-03-05 16:45:01 +01:00
|
|
|
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Create Password',
|
|
|
|
name: 'Submit Password',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
history.push(INITIALIZE_SEED_PHRASE_ROUTE)
|
2019-01-23 16:25:34 +01:00
|
|
|
} catch (error) {
|
|
|
|
this.setState({ passwordError: error.message })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 15:46:41 +01:00
|
|
|
toggleTermsCheck = () => {
|
2019-03-05 16:45:01 +01:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Create Password',
|
|
|
|
name: 'Check ToS',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-02-27 15:46:41 +01:00
|
|
|
this.setState((prevState) => ({
|
|
|
|
termsChecked: !prevState.termsChecked,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2019-12-03 21:50:55 +01:00
|
|
|
onTermsKeyPress = ({ key }) => {
|
2019-11-23 05:56:39 +01:00
|
|
|
if (key === ' ' || key === 'Enter') {
|
|
|
|
this.toggleTermsCheck()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
render () {
|
|
|
|
const { t } = this.context
|
2019-02-27 15:46:41 +01:00
|
|
|
const { password, confirmPassword, passwordError, confirmPasswordError, termsChecked } = this.state
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2019-02-27 15:46:41 +01:00
|
|
|
<div className="first-time-flow__create-back">
|
|
|
|
<a
|
|
|
|
onClick={e => {
|
|
|
|
e.preventDefault()
|
2019-03-05 16:45:01 +01:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Create Password',
|
|
|
|
name: 'Go Back from Onboarding Create',
|
|
|
|
},
|
|
|
|
})
|
2019-02-27 15:46:41 +01:00
|
|
|
this.props.history.push(INITIALIZE_SELECT_ACTION_ROUTE)
|
|
|
|
}}
|
|
|
|
href="#"
|
|
|
|
>
|
|
|
|
{`< Back`}
|
|
|
|
</a>
|
|
|
|
</div>
|
2019-01-23 16:25:34 +01:00
|
|
|
<div className="first-time-flow__header">
|
|
|
|
{ t('createPassword') }
|
|
|
|
</div>
|
|
|
|
<form
|
|
|
|
className="first-time-flow__form"
|
|
|
|
onSubmit={this.handleCreate}
|
|
|
|
>
|
|
|
|
<TextField
|
|
|
|
id="create-password"
|
|
|
|
label={t('newPassword')}
|
|
|
|
type="password"
|
|
|
|
className="first-time-flow__input"
|
|
|
|
value={password}
|
|
|
|
onChange={event => this.handlePasswordChange(event.target.value)}
|
|
|
|
error={passwordError}
|
|
|
|
autoFocus
|
|
|
|
autoComplete="new-password"
|
|
|
|
margin="normal"
|
|
|
|
fullWidth
|
|
|
|
largeLabel
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="confirm-password"
|
|
|
|
label={t('confirmPassword')}
|
|
|
|
type="password"
|
|
|
|
className="first-time-flow__input"
|
|
|
|
value={confirmPassword}
|
|
|
|
onChange={event => this.handleConfirmPasswordChange(event.target.value)}
|
|
|
|
error={confirmPasswordError}
|
|
|
|
autoComplete="confirm-password"
|
|
|
|
margin="normal"
|
|
|
|
fullWidth
|
|
|
|
largeLabel
|
|
|
|
/>
|
2019-02-27 15:46:41 +01:00
|
|
|
<div className="first-time-flow__checkbox-container" onClick={this.toggleTermsCheck}>
|
2019-11-23 05:56:39 +01:00
|
|
|
<div
|
|
|
|
className="first-time-flow__checkbox"
|
|
|
|
tabIndex="0"
|
|
|
|
role="checkbox"
|
|
|
|
onKeyPress={this.onTermsKeyPress}
|
|
|
|
aria-checked={termsChecked}
|
|
|
|
aria-labelledby="ftf-chk1-label"
|
|
|
|
>
|
2019-02-27 15:46:41 +01:00
|
|
|
{termsChecked ? <i className="fa fa-check fa-2x" /> : null}
|
|
|
|
</div>
|
2019-11-23 05:56:39 +01:00
|
|
|
<span id="ftf-chk1-label" className="first-time-flow__checkbox-label">
|
2019-12-03 17:35:44 +01:00
|
|
|
I have read and agree to the
|
|
|
|
<a
|
2019-03-05 16:45:01 +01:00
|
|
|
href="https://metamask.io/terms.html"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
<span className="first-time-flow__link-text">
|
|
|
|
{ 'Terms of Use' }
|
|
|
|
</span>
|
|
|
|
</a>
|
2019-02-27 15:46:41 +01:00
|
|
|
</span>
|
|
|
|
</div>
|
2019-01-23 16:25:34 +01:00
|
|
|
<Button
|
2019-04-16 21:35:22 +02:00
|
|
|
type="primary"
|
2019-01-23 16:25:34 +01:00
|
|
|
className="first-time-flow__button"
|
2019-02-27 15:46:41 +01:00
|
|
|
disabled={!this.isValid() || !termsChecked}
|
2019-01-23 16:25:34 +01:00
|
|
|
onClick={this.handleCreate}
|
|
|
|
>
|
|
|
|
{ t('create') }
|
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|