Skip to content

Commit 0a0cb27

Browse files
committed
Add dispatch action to wallet setup UI component
1 parent d555588 commit 0a0cb27

13 files changed

Lines changed: 303 additions & 66 deletions

File tree

web/package-lock.json

Lines changed: 107 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
"@types/react": "^16.9.0",
1313
"@types/react-dom": "^16.9.0",
1414
"@types/react-redux": "^7.1.9",
15+
"@types/react-router": "^5.1.8",
1516
"@types/sjcl": "^1.0.29",
1617
"axios": "^0.20.0",
18+
"connected-react-router": "^6.8.0",
1719
"node-fetch": "^2.6.1",
1820
"node-forge": "0.10.0",
1921
"qrcode-generator": "^1.4.4",
2022
"react": "^16.13.1",
2123
"react-dom": "^16.13.1",
2224
"react-redux": "^7.2.1",
25+
"react-router": "^5.2.0",
2326
"react-scripts": "3.4.3",
2427
"redux": "^4.0.5",
2528
"redux-injectors": "^1.3.0",

web/src/components/SetupWizard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface SetupWizardProps {
99

1010
export interface SetupWizardState {
1111
currentStep?: number;
12+
mnemonic?: string;
1213
}
1314

1415
export class SetupWizard extends Component<SetupWizardProps, SetupWizardState> {
@@ -76,7 +77,11 @@ export class SetupWizard extends Component<SetupWizardProps, SetupWizardState> {
7677
<Grid.Row textAlign="center">
7778
{this.state && this.state.currentStep === 1 && (
7879
<Grid.Column>
79-
<WalletSetup onComplete={() => this.props.onComplete()} />
80+
<WalletSetup
81+
onComplete={() => this.props.onComplete()}
82+
onCancel={() => this.setState({ currentStep: 1 })}
83+
walletImportMnemonic={(mnemonic) => this.setState({ mnemonic: mnemonic })}
84+
/>
8085
</Grid.Column>
8186
)}
8287
</Grid.Row>

web/src/components/wallet/FileRestore.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { H3, Text } from "../ui/Text";
1010
import { FilePathInfo } from "../../shared/FilePathInfo";
1111
import { WalletRestoreFilePassword } from "./RestoreFilePassword";
1212
import { RequestConfig } from "../../api/Config";
13-
import { ImportMnemonicRequest } from "../../shared/Mnemonic";
1413
import axios from "axios";
1514

1615
export interface WalletFileRestoreProps {
1716
onComplete: () => void;
1817
onCancel: () => void;
18+
onRestoreMnemonic: (words: string) => void;
1919
}
2020

2121
export interface WalletFileRestoreState {
@@ -72,15 +72,8 @@ export class WalletFileRestore extends Component<
7272
wordCount === 24 ||
7373
wordCount === 25
7474
) {
75-
var request: ImportMnemonicRequest = {
76-
mnemonic: wordlist
77-
}
78-
axios.post<ImportMnemonicRequest>("/wallet/mnemonic", request, RequestConfig).then(function (response) {
79-
console.log(JSON.stringify(response.data, null, 2));
80-
self.setState( { loading: true, mnemonic: wordlist }, self.waitForRescan());
81-
}).catch(function (error) {
82-
console.log("onMnemonic execute wallet/mnemonic [Post] Error: " + error);
83-
});
75+
self.props.onRestoreMnemonic(wordlist);
76+
this.setState( { loading: true } );
8477
} else {
8578
var err: DropzoneError = {
8679
title: "Incorrect Word Count",
@@ -91,11 +84,6 @@ export class WalletFileRestore extends Component<
9184
}
9285
};
9386

94-
// Returns a Promise that resolves after "ms" Milliseconds
95-
private timer(ms: number) {
96-
return new Promise(res => setTimeout(res, ms));
97-
}
98-
9987
private waitForRescan(): | undefined {
10088
//TODO: Use redux-saga for these types of actions
10189
console.log('waitForRescan');

web/src/components/wallet/Setup.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { WalletRestore } from "./Restore";
1010
import { WalletFileRestore } from "./FileRestore";
1111
import { WalletMnemonicRestore } from "./MnemonicRestore";
1212
import { WalletPassword } from "./WalletPassword";
13+
import { PickedDispatchProps } from "../../state/shared/PickedDispatchProps";
14+
import { ManageWalletActions } from "../../state/actions/manageWallet";
1315

1416
enum SetupState {
1517
Init = 1,
@@ -18,36 +20,54 @@ enum SetupState {
1820
Restore,
1921
RestoreWithMnemonic,
2022
RestoreWithSecureFile,
21-
CreatePassword
23+
CreatePassword,
24+
Waiting,
25+
Complete,
2226
}
2327

2428
export interface WalletSetupProps {
2529
onComplete: () => void;
30+
onCancel: () => void;
2631
}
2732

33+
export type WalletViewDispatch = PickedDispatchProps<typeof ManageWalletActions, "walletImportMnemonic" >;
34+
35+
type WalletViewDispatchProps = WalletSetupProps & WalletViewDispatch;
36+
2837
export interface WalletSetupState {
2938
setupState: SetupState;
3039
}
3140

32-
export class WalletSetup extends Component<WalletSetupProps, WalletSetupState> {
33-
constructor(props: WalletSetupProps) {
41+
export class WalletSetup extends Component<WalletViewDispatchProps, WalletSetupState> {
42+
constructor(props: WalletViewDispatchProps) {
3443
super(props);
3544
// bind events
3645
this.componentDidMount = this.componentDidMount.bind(this);
3746
this.componentWillUnmount = this.componentWillUnmount.bind(this);
38-
this.onNewWallet = this.onNewWallet.bind(this);
47+
this.onInitWallet = this.onInitWallet.bind(this);
48+
this.onRequestNewWallet = this.onRequestNewWallet.bind(this);
49+
this.onRequestRestoreWallet = this.onRequestRestoreWallet.bind(this);
3950
}
4051

4152
componentDidMount(): void {
4253
this.setState({
4354
setupState: SetupState.Init
4455
});
56+
this.onInitWallet();
4557
}
4658

4759
componentWillUnmount(): void {}
4860

49-
private onNewWallet(): void {
50-
this.props.onComplete();
61+
private onInitWallet(): void {
62+
this.props.walletImportMnemonic("hello test green oil elephant");
63+
}
64+
65+
private onRequestNewWallet(): void {
66+
this.setState({ setupState: SetupState.New })
67+
}
68+
69+
private onRequestRestoreWallet(): void {
70+
this.setState({ setupState: SetupState.Restore })
5171
}
5272

5373
render() {
@@ -63,7 +83,7 @@ export class WalletSetup extends Component<WalletSetupProps, WalletSetupState> {
6383
<Box direction="column" align="center" width="100%">
6484
<Box display="flex" direction="row" align="center" width="100%">
6585
<SCard
66-
onClick={() => this.setState({ setupState: SetupState.New })}
86+
onClick={() => this.onRequestNewWallet()}
6787
>
6888
<ImportIconWhite height="80px" width="80px" />
6989
<H3 align="start" color="white" minwidth="50px">
@@ -74,10 +94,7 @@ export class WalletSetup extends Component<WalletSetupProps, WalletSetupState> {
7494
</Text>
7595
</SCard>
7696
<SCard
77-
onClick={() =>
78-
this.setState({ setupState: SetupState.Restore })
79-
}
80-
>
97+
onClick={() =>this.onRequestRestoreWallet()}>
8198
<RestoreIconWhite height="80px" width="80px" />
8299
<H3 align="start" color="white" minwidth="50px">
83100
Restore Wallet
@@ -136,7 +153,8 @@ export class WalletSetup extends Component<WalletSetupProps, WalletSetupState> {
136153
this.state.setupState === SetupState.RestoreWithSecureFile && (
137154
<WalletFileRestore
138155
onComplete={() => this.props.onComplete()}
139-
onCancel={() => this.setState({ setupState: SetupState.Restore })}
156+
onCancel={() => this.props.onCancel()}
157+
onRestoreMnemonic={(words) => this.props.walletImportMnemonic(words)}
140158
/>
141159
)}
142160
</>

0 commit comments

Comments
 (0)