2018-02-02 06:01:30 +00:00
|
|
|
import { IV3Wallet } from 'ethereumjs-wallet';
|
2017-12-28 19:54:07 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-02-02 06:01:30 +00:00
|
|
|
import { generateKeystore } from 'libs/web-workers';
|
2017-12-28 19:54:07 +00:00
|
|
|
import { WalletType } from '../../GenerateWallet';
|
|
|
|
import Template from '../Template';
|
|
|
|
import DownloadWallet from './DownloadWallet';
|
|
|
|
import EnterPassword from './EnterPassword';
|
|
|
|
import PaperWallet from './PaperWallet';
|
|
|
|
import FinalSteps from '../FinalSteps';
|
|
|
|
|
|
|
|
export enum Steps {
|
|
|
|
Password = 'password',
|
|
|
|
Download = 'download',
|
|
|
|
Paper = 'paper',
|
|
|
|
Final = 'final'
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
activeStep: Steps;
|
|
|
|
password: string;
|
2018-02-02 06:01:30 +00:00
|
|
|
keystore: IV3Wallet | null | undefined;
|
|
|
|
filename: string;
|
|
|
|
privateKey: string;
|
|
|
|
isGenerating: boolean;
|
2017-12-28 19:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class GenerateKeystore extends Component<{}, State> {
|
|
|
|
public state: State = {
|
|
|
|
activeStep: Steps.Password,
|
|
|
|
password: '',
|
2018-02-02 06:01:30 +00:00
|
|
|
keystore: null,
|
|
|
|
filename: '',
|
|
|
|
privateKey: '',
|
|
|
|
isGenerating: false
|
2017-12-28 19:54:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public render() {
|
2018-02-02 06:01:30 +00:00
|
|
|
const { activeStep, keystore, privateKey, filename, isGenerating } = this.state;
|
2017-12-28 19:54:07 +00:00
|
|
|
let content;
|
|
|
|
|
|
|
|
switch (activeStep) {
|
|
|
|
case Steps.Password:
|
2018-02-02 06:01:30 +00:00
|
|
|
content = (
|
|
|
|
<EnterPassword continue={this.generateWalletAndContinue} isGenerating={isGenerating} />
|
|
|
|
);
|
2017-12-28 19:54:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Steps.Download:
|
2018-02-02 06:01:30 +00:00
|
|
|
if (keystore) {
|
2017-12-28 19:54:07 +00:00
|
|
|
content = (
|
2018-02-02 06:01:30 +00:00
|
|
|
<DownloadWallet
|
|
|
|
keystore={keystore}
|
|
|
|
filename={filename}
|
|
|
|
continue={this.continueToPaper}
|
|
|
|
/>
|
2017-12-28 19:54:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Steps.Paper:
|
2018-02-02 06:01:30 +00:00
|
|
|
if (keystore) {
|
|
|
|
content = (
|
|
|
|
<PaperWallet
|
|
|
|
keystore={keystore}
|
|
|
|
privateKey={privateKey}
|
|
|
|
continue={this.continueToFinal}
|
|
|
|
/>
|
|
|
|
);
|
2017-12-28 19:54:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Steps.Final:
|
|
|
|
content = (
|
|
|
|
<Template>
|
|
|
|
<FinalSteps walletType={WalletType.Keystore} />
|
|
|
|
</Template>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
content = <h1>Uh oh. Not sure how you got here.</h1>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
private generateWalletAndContinue = (password: string) => {
|
2018-02-02 06:01:30 +00:00
|
|
|
this.setState({ isGenerating: true });
|
|
|
|
|
|
|
|
generateKeystore(password).then(res => {
|
|
|
|
this.setState({
|
|
|
|
password,
|
|
|
|
activeStep: Steps.Download,
|
|
|
|
keystore: res.keystore,
|
|
|
|
filename: res.filename,
|
|
|
|
privateKey: res.privateKey,
|
|
|
|
isGenerating: false
|
|
|
|
});
|
2017-12-28 19:54:07 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
private continueToPaper = () => {
|
|
|
|
this.setState({ activeStep: Steps.Paper });
|
|
|
|
};
|
|
|
|
|
|
|
|
private continueToFinal = () => {
|
|
|
|
this.setState({ activeStep: Steps.Final });
|
|
|
|
};
|
|
|
|
}
|