You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
4.8 KiB
178 lines
4.8 KiB
7 years ago
|
const { Component } = require('react')
|
||
|
const { connect } = require('react-redux')
|
||
|
const PropTypes = require('prop-types')
|
||
|
const h = require('react-hyperscript')
|
||
7 years ago
|
const classnames = require('classnames')
|
||
|
|
||
6 years ago
|
const { requestRevealSeedWords } = require('../../store/actions')
|
||
|
const { DEFAULT_ROUTE } = require('../../helpers/constants/routes')
|
||
|
const ExportTextContainer = require('../../components/ui/export-text-container')
|
||
7 years ago
|
|
||
6 years ago
|
import Button from '../../components/ui/button'
|
||
6 years ago
|
|
||
7 years ago
|
const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN'
|
||
|
const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN'
|
||
7 years ago
|
|
||
|
class RevealSeedPage extends Component {
|
||
7 years ago
|
constructor (props) {
|
||
|
super(props)
|
||
|
|
||
|
this.state = {
|
||
|
screen: PASSWORD_PROMPT_SCREEN,
|
||
|
password: '',
|
||
|
seedWords: null,
|
||
|
error: null,
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
componentDidMount () {
|
||
7 years ago
|
const passwordBox = document.getElementById('password-box')
|
||
|
if (passwordBox) {
|
||
|
passwordBox.focus()
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
handleSubmit (event) {
|
||
|
event.preventDefault()
|
||
|
this.setState({ seedWords: null, error: null })
|
||
|
this.props.requestRevealSeedWords(this.state.password)
|
||
|
.then(seedWords => this.setState({ seedWords, screen: REVEAL_SEED_SCREEN }))
|
||
|
.catch(error => this.setState({ error: error.message }))
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
renderWarning () {
|
||
7 years ago
|
return (
|
||
7 years ago
|
h('.page-container__warning-container', [
|
||
|
h('img.page-container__warning-icon', {
|
||
|
src: 'images/warning.svg',
|
||
7 years ago
|
}),
|
||
7 years ago
|
h('.page-container__warning-message', [
|
||
|
h('.page-container__warning-title', [this.context.t('revealSeedWordsWarningTitle')]),
|
||
|
h('div', [this.context.t('revealSeedWordsWarning')]),
|
||
|
]),
|
||
7 years ago
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
renderContent () {
|
||
|
return this.state.screen === PASSWORD_PROMPT_SCREEN
|
||
|
? this.renderPasswordPromptContent()
|
||
|
: this.renderRevealSeedContent()
|
||
|
}
|
||
|
|
||
|
renderPasswordPromptContent () {
|
||
|
const { t } = this.context
|
||
7 years ago
|
|
||
|
return (
|
||
7 years ago
|
h('form', {
|
||
|
onSubmit: event => this.handleSubmit(event),
|
||
7 years ago
|
}, [
|
||
7 years ago
|
h('label.input-label', {
|
||
|
htmlFor: 'password-box',
|
||
|
}, t('enterPasswordContinue')),
|
||
|
h('.input-group', [
|
||
|
h('input.form-control', {
|
||
7 years ago
|
type: 'password',
|
||
7 years ago
|
placeholder: t('password'),
|
||
7 years ago
|
id: 'password-box',
|
||
7 years ago
|
value: this.state.password,
|
||
|
onChange: event => this.setState({ password: event.target.value }),
|
||
|
className: classnames({ 'form-control--error': this.state.error }),
|
||
7 years ago
|
}),
|
||
7 years ago
|
]),
|
||
|
this.state.error && h('.reveal-seed__error', this.state.error),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
renderRevealSeedContent () {
|
||
|
const { t } = this.context
|
||
7 years ago
|
|
||
7 years ago
|
return (
|
||
|
h('div', [
|
||
|
h('label.reveal-seed__label', t('yourPrivateSeedPhrase')),
|
||
|
h(ExportTextContainer, {
|
||
|
text: this.state.seedWords,
|
||
|
filename: t('metamaskSeedWords'),
|
||
|
}),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
renderFooter () {
|
||
|
return this.state.screen === PASSWORD_PROMPT_SCREEN
|
||
|
? this.renderPasswordPromptFooter()
|
||
|
: this.renderRevealSeedFooter()
|
||
|
}
|
||
|
|
||
|
renderPasswordPromptFooter () {
|
||
|
return (
|
||
|
h('.page-container__footer', [
|
||
6 years ago
|
h('header', [
|
||
|
h(Button, {
|
||
|
type: 'default',
|
||
|
large: true,
|
||
|
className: 'page-container__footer-button',
|
||
|
onClick: () => this.props.history.push(DEFAULT_ROUTE),
|
||
|
}, this.context.t('cancel')),
|
||
|
h(Button, {
|
||
|
type: 'primary',
|
||
|
large: true,
|
||
|
className: 'page-container__footer-button',
|
||
|
onClick: event => this.handleSubmit(event),
|
||
|
disabled: this.state.password === '',
|
||
|
}, this.context.t('next')),
|
||
|
]),
|
||
7 years ago
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
|
renderRevealSeedFooter () {
|
||
|
return (
|
||
|
h('.page-container__footer', [
|
||
6 years ago
|
h(Button, {
|
||
|
type: 'default',
|
||
|
large: true,
|
||
|
className: 'page-container__footer-button',
|
||
7 years ago
|
onClick: () => this.props.history.push(DEFAULT_ROUTE),
|
||
|
}, this.context.t('close')),
|
||
7 years ago
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
|
render () {
|
||
7 years ago
|
return (
|
||
|
h('.page-container', [
|
||
|
h('.page-container__header', [
|
||
|
h('.page-container__title', this.context.t('revealSeedWordsTitle')),
|
||
|
h('.page-container__subtitle', this.context.t('revealSeedWordsDescription')),
|
||
|
]),
|
||
|
h('.page-container__content', [
|
||
|
this.renderWarning(),
|
||
|
h('.reveal-seed__content', [
|
||
|
this.renderContent(),
|
||
|
]),
|
||
|
]),
|
||
|
this.renderFooter(),
|
||
|
])
|
||
|
)
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
RevealSeedPage.propTypes = {
|
||
7 years ago
|
requestRevealSeedWords: PropTypes.func,
|
||
7 years ago
|
history: PropTypes.object,
|
||
|
}
|
||
|
|
||
7 years ago
|
RevealSeedPage.contextTypes = {
|
||
|
t: PropTypes.func,
|
||
7 years ago
|
}
|
||
|
|
||
|
const mapDispatchToProps = dispatch => {
|
||
|
return {
|
||
7 years ago
|
requestRevealSeedWords: password => dispatch(requestRevealSeedWords(password)),
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
module.exports = connect(null, mapDispatchToProps)(RevealSeedPage)
|