2017-07-16 21:02:13 +00:00
|
|
|
// @flow
|
2017-06-20 03:15:38 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import * as generateWalletActions from 'actions/generateWallet';
|
2017-05-30 20:36:52 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-07-16 21:02:13 +00:00
|
|
|
import EnterPassword from './components/EnterPassword';
|
|
|
|
import DownloadWallet from './components/DownloadWallet';
|
|
|
|
import PaperWallet from './components/PaperWallet';
|
|
|
|
import type PrivKeyWallet from 'libs/wallet/privkey';
|
|
|
|
import type { State } from 'reducers';
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-07-16 21:02:13 +00:00
|
|
|
type Props = {
|
|
|
|
// FIXME union actual steps
|
|
|
|
activeStep: string,
|
|
|
|
password: string,
|
|
|
|
hasDownloadedWalletFile: boolean,
|
|
|
|
wallet: ?PrivKeyWallet
|
|
|
|
} & typeof generateWalletActions;
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-07-16 21:02:13 +00:00
|
|
|
class GenerateWallet extends Component {
|
|
|
|
props: Props;
|
2017-06-20 03:15:38 +00:00
|
|
|
static propTypes = {
|
2017-07-16 21:02:13 +00:00
|
|
|
// Store state
|
|
|
|
activeStep: PropTypes.string,
|
|
|
|
wallet: PropTypes.object,
|
|
|
|
password: PropTypes.string,
|
2017-07-18 01:47:01 +00:00
|
|
|
hasDownloadedWalletFile: PropTypes.bool,
|
2017-07-16 21:02:13 +00:00
|
|
|
// Actions
|
2017-06-20 06:28:22 +00:00
|
|
|
showPasswordGenerateWallet: PropTypes.func,
|
2017-07-16 21:02:13 +00:00
|
|
|
generateUTCGenerateWallet: PropTypes.func,
|
|
|
|
downloadUTCGenerateWallet: PropTypes.func,
|
|
|
|
confirmContinueToPaperGenerateWallet: PropTypes.func,
|
|
|
|
resetGenerateWallet: PropTypes.func
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
2017-04-12 05:04:27 +00:00
|
|
|
|
2017-07-16 21:02:13 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.props.resetGenerateWallet();
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:15:38 +00:00
|
|
|
render() {
|
2017-07-16 21:02:13 +00:00
|
|
|
const { activeStep, wallet, password } = this.props;
|
|
|
|
let content;
|
|
|
|
|
|
|
|
switch (activeStep) {
|
|
|
|
case 'password':
|
|
|
|
content = <EnterPassword {...this.props} />;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'download':
|
|
|
|
if (wallet) {
|
|
|
|
content = (
|
|
|
|
<DownloadWallet
|
|
|
|
hasDownloadedWalletFile={this.props.hasDownloadedWalletFile}
|
|
|
|
wallet={wallet}
|
|
|
|
password={password}
|
|
|
|
downloadUTCGenerateWallet={this.props.downloadUTCGenerateWallet}
|
|
|
|
confirmContinueToPaperGenerateWallet={
|
|
|
|
this.props.confirmContinueToPaperGenerateWallet
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'paper':
|
|
|
|
if (wallet) {
|
|
|
|
content = <PaperWallet wallet={wallet} />;
|
|
|
|
} else {
|
|
|
|
content = <h1>Uh oh. Not sure how you got here.</h1>;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
content = <h1>Uh oh. Not sure how you got here.</h1>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="container" style={{ minHeight: '50%' }}>
|
|
|
|
<div className="tab-content">
|
|
|
|
<main className="tab-pane active text-center" role="main">
|
|
|
|
<section role="main" className="row">
|
|
|
|
<br />
|
|
|
|
{content}
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
2017-06-20 03:15:38 +00:00
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 21:02:13 +00:00
|
|
|
function mapStateToProps(state: State) {
|
2017-06-20 03:15:38 +00:00
|
|
|
return {
|
|
|
|
generateWalletPassword: state.form.generateWalletPassword,
|
2017-07-16 21:02:13 +00:00
|
|
|
activeStep: state.generateWallet.activeStep,
|
|
|
|
password: state.generateWallet.password,
|
2017-06-20 03:15:38 +00:00
|
|
|
hasDownloadedWalletFile: state.generateWallet.hasDownloadedWalletFile,
|
2017-07-16 21:02:13 +00:00
|
|
|
wallet: state.generateWallet.wallet,
|
|
|
|
walletFile: state.generateWallet.walletFile
|
2017-06-20 03:15:38 +00:00
|
|
|
};
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 03:15:38 +00:00
|
|
|
export default connect(mapStateToProps, generateWalletActions)(GenerateWallet);
|