2017-09-24 19:06:28 -07:00
|
|
|
import {
|
|
|
|
continueToPaper,
|
|
|
|
generateNewWallet,
|
|
|
|
resetGenerateWallet,
|
|
|
|
TContinueToPaper,
|
|
|
|
TGenerateNewWallet,
|
|
|
|
TResetGenerateWallet
|
|
|
|
} from 'actions/generateWallet';
|
2017-11-07 13:42:53 -05:00
|
|
|
import { IFullWallet } from 'ethereumjs-wallet';
|
2017-06-19 22:15:38 -05:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { AppState } from 'reducers';
|
2017-07-16 16:02:13 -05:00
|
|
|
import DownloadWallet from './components/DownloadWallet';
|
2017-09-24 19:06:28 -07:00
|
|
|
import EnterPassword from './components/EnterPassword';
|
2017-07-16 16:02:13 -05:00
|
|
|
import PaperWallet from './components/PaperWallet';
|
2017-11-06 22:24:54 -08:00
|
|
|
import CryptoWarning from './components/CryptoWarning';
|
2017-10-04 00:13:49 -04:00
|
|
|
import TabSection from 'containers/TabSection';
|
2017-04-12 00:04:27 -05:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface Props {
|
2017-07-27 13:05:09 -04:00
|
|
|
// Redux state
|
2017-09-24 19:06:28 -07:00
|
|
|
activeStep: string; // FIXME union actual steps
|
|
|
|
password: string;
|
2017-11-07 13:42:53 -05:00
|
|
|
wallet: IFullWallet | null | undefined;
|
2017-09-24 19:06:28 -07:00
|
|
|
walletPasswordForm: any;
|
2017-07-27 13:05:09 -04:00
|
|
|
// Actions
|
2017-09-24 19:06:28 -07:00
|
|
|
generateNewWallet: TGenerateNewWallet;
|
|
|
|
continueToPaper: TContinueToPaper;
|
|
|
|
resetGenerateWallet: TResetGenerateWallet;
|
|
|
|
}
|
2017-04-12 00:04:27 -05:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
class GenerateWallet extends Component<Props, {}> {
|
|
|
|
public componentWillUnmount() {
|
2017-07-16 16:02:13 -05:00
|
|
|
this.props.resetGenerateWallet();
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public render() {
|
2017-07-16 16:02:13 -05:00
|
|
|
const { activeStep, wallet, password } = this.props;
|
|
|
|
let content;
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
const AnyEnterPassword = EnterPassword as new () => any;
|
|
|
|
|
2017-11-06 22:24:54 -08:00
|
|
|
if (window.crypto) {
|
|
|
|
switch (activeStep) {
|
|
|
|
case 'password':
|
2017-07-16 16:02:13 -05:00
|
|
|
content = (
|
2017-11-06 22:24:54 -08:00
|
|
|
<AnyEnterPassword
|
|
|
|
walletPasswordForm={this.props.walletPasswordForm}
|
|
|
|
generateNewWallet={this.props.generateNewWallet}
|
2017-07-16 16:02:13 -05:00
|
|
|
/>
|
|
|
|
);
|
2017-11-06 22:24:54 -08:00
|
|
|
break;
|
2017-07-16 16:02:13 -05:00
|
|
|
|
2017-11-06 22:24:54 -08:00
|
|
|
case 'download':
|
|
|
|
if (wallet) {
|
|
|
|
content = (
|
|
|
|
<DownloadWallet
|
|
|
|
wallet={wallet}
|
|
|
|
password={password}
|
|
|
|
continueToPaper={this.props.continueToPaper}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'paper':
|
|
|
|
if (wallet) {
|
|
|
|
content = <PaperWallet wallet={wallet} />;
|
|
|
|
} else {
|
|
|
|
content = <h1>Uh oh. Not sure how you got here.</h1>;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-16 16:02:13 -05:00
|
|
|
|
2017-11-06 22:24:54 -08:00
|
|
|
default:
|
|
|
|
content = <h1>Uh oh. Not sure how you got here.</h1>;
|
|
|
|
}
|
2017-11-07 13:42:53 -05:00
|
|
|
} else {
|
|
|
|
content = <CryptoWarning />;
|
2017-07-16 16:02:13 -05:00
|
|
|
}
|
|
|
|
|
2017-09-28 22:09:01 -04:00
|
|
|
return (
|
2017-10-04 00:13:49 -04:00
|
|
|
<TabSection>
|
2017-09-28 22:09:01 -04:00
|
|
|
<section className="Tab-content">{content}</section>
|
2017-10-04 00:13:49 -04:00
|
|
|
</TabSection>
|
2017-09-28 22:09:01 -04:00
|
|
|
);
|
2017-06-19 22:15:38 -05:00
|
|
|
}
|
2017-04-12 00:04:27 -05:00
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
function mapStateToProps(state: AppState) {
|
2017-06-19 22:15:38 -05:00
|
|
|
return {
|
2017-07-27 13:05:09 -04:00
|
|
|
walletPasswordForm: state.form.walletPasswordForm,
|
2017-07-16 16:02:13 -05:00
|
|
|
activeStep: state.generateWallet.activeStep,
|
|
|
|
password: state.generateWallet.password,
|
2017-07-27 13:05:09 -04:00
|
|
|
wallet: state.generateWallet.wallet
|
2017-06-19 22:15:38 -05:00
|
|
|
};
|
2017-04-12 00:04:27 -05:00
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
generateNewWallet,
|
|
|
|
continueToPaper,
|
|
|
|
resetGenerateWallet
|
|
|
|
})(GenerateWallet);
|