2019-11-24 05:58:32 +01:00
|
|
|
import React, { Component } from 'react'
|
2020-01-09 04:34:58 +01:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classnames from 'classnames'
|
|
|
|
import { requestRevealSeedWords } from '../../store/actions'
|
|
|
|
import ExportTextContainer from '../../components/ui/export-text-container'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
2018-04-22 09:14:40 +02:00
|
|
|
|
2019-03-22 00:03:30 +01:00
|
|
|
import Button from '../../components/ui/button'
|
2018-08-28 05:58:40 +02:00
|
|
|
|
2018-04-22 09:14:40 +02:00
|
|
|
const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN'
|
|
|
|
const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN'
|
2017-11-29 05:24:35 +01:00
|
|
|
|
|
|
|
class RevealSeedPage extends Component {
|
2019-11-24 05:58:32 +01:00
|
|
|
state = {
|
|
|
|
screen: PASSWORD_PROMPT_SCREEN,
|
|
|
|
password: '',
|
|
|
|
seedWords: null,
|
|
|
|
error: null,
|
2018-04-22 09:14:40 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2017-12-04 07:24:30 +01:00
|
|
|
const passwordBox = document.getElementById('password-box')
|
|
|
|
if (passwordBox) {
|
|
|
|
passwordBox.focus()
|
|
|
|
}
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleSubmit(event) {
|
2018-04-22 09:14:40 +02:00
|
|
|
event.preventDefault()
|
|
|
|
this.setState({ seedWords: null, error: null })
|
2020-11-03 00:41:28 +01:00
|
|
|
this.props
|
|
|
|
.requestRevealSeedWords(this.state.password)
|
|
|
|
.then((seedWords) =>
|
|
|
|
this.setState({ seedWords, screen: REVEAL_SEED_SCREEN }),
|
|
|
|
)
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((error) => this.setState({ error: error.message }))
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderWarning() {
|
2017-11-29 05:24:35 +01:00
|
|
|
return (
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="page-container__warning-container">
|
2020-11-03 00:41:28 +01:00
|
|
|
<img
|
|
|
|
className="page-container__warning-icon"
|
|
|
|
src="images/warning.svg"
|
|
|
|
alt=""
|
|
|
|
/>
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="page-container__warning-message">
|
|
|
|
<div className="page-container__warning-title">
|
|
|
|
{this.context.t('revealSeedWordsWarningTitle')}
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div>{this.context.t('revealSeedWordsWarning')}</div>
|
2019-11-24 05:58:32 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-11-29 05:24:35 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContent() {
|
2018-04-22 09:14:40 +02:00
|
|
|
return this.state.screen === PASSWORD_PROMPT_SCREEN
|
|
|
|
? this.renderPasswordPromptContent()
|
|
|
|
: this.renderRevealSeedContent()
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderPasswordPromptContent() {
|
2018-04-22 09:14:40 +02:00
|
|
|
const { t } = this.context
|
2017-11-29 05:24:35 +01:00
|
|
|
|
|
|
|
return (
|
2020-02-15 21:34:12 +01:00
|
|
|
<form onSubmit={(event) => this.handleSubmit(event)}>
|
2020-11-03 00:41:28 +01:00
|
|
|
<label className="input-label" htmlFor="password-box">
|
|
|
|
{t('enterPasswordContinue')}
|
|
|
|
</label>
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="input-group">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
placeholder={t('password')}
|
|
|
|
id="password-box"
|
|
|
|
value={this.state.password}
|
2020-11-03 00:41:28 +01:00
|
|
|
onChange={(event) =>
|
|
|
|
this.setState({ password: event.target.value })
|
|
|
|
}
|
|
|
|
className={classnames('form-control', {
|
|
|
|
'form-control--error': this.state.error,
|
|
|
|
})}
|
2019-11-24 05:58:32 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.state.error && (
|
|
|
|
<div className="reveal-seed__error">{this.state.error}</div>
|
|
|
|
)}
|
2019-11-24 05:58:32 +01:00
|
|
|
</form>
|
2018-04-22 09:14:40 +02:00
|
|
|
)
|
|
|
|
}
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderRevealSeedContent() {
|
2018-04-22 09:14:40 +02:00
|
|
|
const { t } = this.context
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2018-04-22 09:14:40 +02:00
|
|
|
return (
|
2019-11-24 05:58:32 +01:00
|
|
|
<div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<label className="reveal-seed__label">
|
|
|
|
{t('yourPrivateSeedPhrase')}
|
|
|
|
</label>
|
2020-01-22 02:22:55 +01:00
|
|
|
<ExportTextContainer text={this.state.seedWords} />
|
2019-11-24 05:58:32 +01:00
|
|
|
</div>
|
2018-04-22 09:14:40 +02:00
|
|
|
)
|
|
|
|
}
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderFooter() {
|
2018-04-22 09:14:40 +02:00
|
|
|
return this.state.screen === PASSWORD_PROMPT_SCREEN
|
|
|
|
? this.renderPasswordPromptFooter()
|
|
|
|
: this.renderRevealSeedFooter()
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderPasswordPromptFooter() {
|
2018-04-22 09:14:40 +02:00
|
|
|
return (
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="page-container__footer">
|
2020-02-27 23:00:20 +01:00
|
|
|
<footer>
|
2019-11-24 05:58:32 +01:00
|
|
|
<Button
|
|
|
|
type="default"
|
|
|
|
large
|
|
|
|
className="page-container__footer-button"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={() =>
|
|
|
|
this.props.history.push(this.props.mostRecentOverviewPage)
|
|
|
|
}
|
2019-11-24 05:58:32 +01:00
|
|
|
>
|
|
|
|
{this.context.t('cancel')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
large
|
|
|
|
className="page-container__footer-button"
|
2020-02-15 21:34:12 +01:00
|
|
|
onClick={(event) => this.handleSubmit(event)}
|
2019-11-24 05:58:32 +01:00
|
|
|
disabled={this.state.password === ''}
|
|
|
|
>
|
|
|
|
{this.context.t('next')}
|
|
|
|
</Button>
|
2020-02-27 23:00:20 +01:00
|
|
|
</footer>
|
2019-11-24 05:58:32 +01:00
|
|
|
</div>
|
2018-04-22 09:14:40 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderRevealSeedFooter() {
|
2018-04-22 09:14:40 +02:00
|
|
|
return (
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="page-container__footer">
|
|
|
|
<Button
|
|
|
|
type="default"
|
|
|
|
large
|
|
|
|
className="page-container__footer-button"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={() =>
|
|
|
|
this.props.history.push(this.props.mostRecentOverviewPage)
|
|
|
|
}
|
2019-11-24 05:58:32 +01:00
|
|
|
>
|
|
|
|
{this.context.t('close')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2017-11-29 05:24:35 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2018-04-22 09:14:40 +02:00
|
|
|
return (
|
2019-11-24 05:58:32 +01:00
|
|
|
<div className="page-container">
|
|
|
|
<div className="page-container__header">
|
|
|
|
<div className="page-container__title">
|
|
|
|
{this.context.t('revealSeedWordsTitle')}
|
|
|
|
</div>
|
|
|
|
<div className="page-container__subtitle">
|
|
|
|
{this.context.t('revealSeedWordsDescription')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="page-container__content">
|
|
|
|
{this.renderWarning()}
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="reveal-seed__content">{this.renderContent()}</div>
|
2019-11-24 05:58:32 +01:00
|
|
|
</div>
|
|
|
|
{this.renderFooter()}
|
|
|
|
</div>
|
2018-04-22 09:14:40 +02:00
|
|
|
)
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RevealSeedPage.propTypes = {
|
2018-04-22 09:14:40 +02:00
|
|
|
requestRevealSeedWords: PropTypes.func,
|
2017-11-29 05:24:35 +01:00
|
|
|
history: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-22 09:14:40 +02:00
|
|
|
RevealSeedPage.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
return {
|
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2017-11-29 05:24:35 +01:00
|
|
|
return {
|
2020-11-03 00:41:28 +01:00
|
|
|
requestRevealSeedWords: (password) =>
|
|
|
|
dispatch(requestRevealSeedWords(password)),
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(RevealSeedPage)
|