1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/pages/keychains/reveal-seed.js

198 lines
5.3 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
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';
import { getMostRecentOverviewPage } from '../../ducks/history/history';
import Button from '../../components/ui/button';
const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN';
const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN';
class RevealSeedPage extends Component {
state = {
screen: PASSWORD_PROMPT_SCREEN,
password: '',
seedWords: null,
error: null,
};
2020-11-03 00:41:28 +01:00
componentDidMount() {
const passwordBox = document.getElementById('password-box');
2017-12-04 07:24:30 +01:00
if (passwordBox) {
passwordBox.focus();
2017-12-04 07:24:30 +01:00
}
}
2020-11-03 00:41:28 +01:00
handleSubmit(event) {
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 }),
)
.catch((error) => this.setState({ error: error.message }));
}
2020-11-03 00:41:28 +01:00
renderWarning() {
return (
<div className="page-container__warning-container">
<i className="fa fa-exclamation-triangle fa-2x page-container__warning-icon" />
<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>
</div>
</div>
);
}
2020-11-03 00:41:28 +01:00
renderContent() {
return this.state.screen === PASSWORD_PROMPT_SCREEN
? this.renderPasswordPromptContent()
: this.renderRevealSeedContent();
}
2020-11-03 00:41:28 +01:00
renderPasswordPromptContent() {
const { t } = this.context;
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>
<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,
})}
/>
</div>
2020-11-03 00:41:28 +01:00
{this.state.error && (
<div className="reveal-seed__error">{this.state.error}</div>
)}
</form>
);
}
2020-11-03 00:41:28 +01:00
renderRevealSeedContent() {
const { t } = this.context;
return (
<div>
2020-11-03 00:41:28 +01:00
<label className="reveal-seed__label">
{t('yourPrivateSeedPhrase')}
</label>
<ExportTextContainer text={this.state.seedWords} />
</div>
);
}
2020-11-03 00:41:28 +01:00
renderFooter() {
return this.state.screen === PASSWORD_PROMPT_SCREEN
? this.renderPasswordPromptFooter()
: this.renderRevealSeedFooter();
}
2020-11-03 00:41:28 +01:00
renderPasswordPromptFooter() {
return (
<div className="page-container__footer">
<footer>
<Button
type="secondary"
large
className="page-container__footer-button"
2020-11-03 00:41:28 +01:00
onClick={() =>
this.props.history.push(this.props.mostRecentOverviewPage)
}
>
{this.context.t('cancel')}
</Button>
<Button
type="primary"
large
className="page-container__footer-button"
2020-02-15 21:34:12 +01:00
onClick={(event) => this.handleSubmit(event)}
disabled={this.state.password === ''}
>
{this.context.t('next')}
</Button>
</footer>
</div>
);
}
2020-11-03 00:41:28 +01:00
renderRevealSeedFooter() {
return (
<div className="page-container__footer">
<Button
type="secondary"
large
className="page-container__footer-single-button"
2020-11-03 00:41:28 +01:00
onClick={() =>
this.props.history.push(this.props.mostRecentOverviewPage)
}
>
{this.context.t('close')}
</Button>
</div>
);
}
2020-11-03 00:41:28 +01:00
render() {
return (
<div className="page-container">
<div className="page-container__header">
<div className="page-container__title">
{this.context.t('secretRecoveryPhrase')}
</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>
</div>
{this.renderFooter()}
</div>
);
}
}
RevealSeedPage.propTypes = {
requestRevealSeedWords: PropTypes.func,
history: PropTypes.object,
mostRecentOverviewPage: PropTypes.string.isRequired,
};
RevealSeedPage.contextTypes = {
t: PropTypes.func,
};
const mapStateToProps = (state) => {
return {
mostRecentOverviewPage: getMostRecentOverviewPage(state),
};
};
2020-02-15 21:34:12 +01:00
const mapDispatchToProps = (dispatch) => {
return {
2020-11-03 00:41:28 +01:00
requestRevealSeedWords: (password) =>
dispatch(requestRevealSeedWords(password)),
};
};
export default connect(mapStateToProps, mapDispatchToProps)(RevealSeedPage);