Skip to content

Commit ebe9f86

Browse files
committed
RestoreWalletFromPrivateKey component is created to improve visual components
1 parent 80a468d commit ebe9f86

File tree

8 files changed

+47
-73
lines changed

8 files changed

+47
-73
lines changed

examples/wallet/app/Routes.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ChooseRestoreOrImport from './containers/ChooseRestoreOrImport';
1010
import Delegate from './pages/Delegate';
1111
import Index from './containers/Index';
1212
import InputKeys from './containers/InputKeys';
13-
import CreateSpendingPassword from './containers/CreateSpendingPassword';
1413

1514
export default () => (
1615
<App>
@@ -24,10 +23,6 @@ export default () => (
2423
path={routes.CHOOSE_RESTORE_OR_IMPORT}
2524
component={ChooseRestoreOrImport}
2625
/>
27-
<Route
28-
path={routes.CREATE_SPENDING_PASSWORD}
29-
component={CreateSpendingPassword}
30-
/>
3126
<Route path={routes.INDEX} component={Index} />
3227
</Switch>
3328
</App>

examples/wallet/app/actions/router.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ import type { Address } from '../models';
55
import routes from '../constants/routes';
66
import { setAccountFromPrivateKey } from './account';
77

8-
import {
9-
readAccountKeysFromLocalStorage,
10-
isSpedingPasswordCreated
11-
} from '../utils/storage';
8+
import { readAccountKeysFromLocalStorage } from '../utils/storage';
129

1310
// eslint-disable-next-line import/prefer-default-export
1411
export const redirectToFirstAppPage = () => {
1512
return (dispatch: Dispatch, getState: GetState) => {
16-
if (!isSpedingPasswordCreated())
17-
return dispatch(push(routes.CREATE_SPENDING_PASSWORD));
1813
const accountKeys = readAccountKeysFromLocalStorage();
1914
if (accountKeys !== undefined) {
2015
return dispatch(setAccountFromPrivateKey(accountKeys.privateKey));

examples/wallet/app/pages/CreateSpendingPassword.js renamed to examples/wallet/app/components/RestoreWalletFromPrivateKey.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import Form from 'react-bootstrap/Form';
44
import Button from 'react-bootstrap/Button';
55
import Container from 'react-bootstrap/Container';
66
import Row from 'react-bootstrap/Row';
7-
import typeof { setAccountFromMnemonic as SetAccountFromMnemonic } from '../actions/account';
7+
import typeof { setAccount as SetAccount } from '../actions/account';
88

99
type Props = {
10-
setAccountFromMnemonic: SetAccountFromMnemonic
10+
setAccount: SetAccount
1111
};
1212

1313
// FIXME: this has no error handling, neither while parsing the address
1414
// nor when fetching the balance.
15-
export default ({ setAccountFromMnemonic }: Props) => {
15+
export default ({ setAccount }: Props) => {
1616
const handleSubmitCreateSpending = function handleSubmitCreateSpending(
1717
event
1818
) {
1919
event.preventDefault();
2020
if (checkValidPassword(password, confirmPassword)) {
21-
return Promise.all([setAccountFromMnemonic(password, confirmPassword)]);
21+
setAccount(newPrivateKey);
2222
}
2323
};
2424

2525
const checkValidPassword = function checkValidPassword(pass, confirmation) {
26-
if (!pass) return false;
26+
if (!pass && !confirmation) return true;
2727
if (pass.length < 8) {
2828
setIsValidPassword(false);
2929
return false;
@@ -39,6 +39,8 @@ export default ({ setAccountFromMnemonic }: Props) => {
3939
};
4040

4141
const [isValidPassword, setIsValidPassword] = useState(true);
42+
const [newPrivateKey, setNewPrivateKey] = useState('');
43+
4244
const [
4345
arePasswordAndConfirmationEqual,
4446
setArePasswordAndConfirmationEqual
@@ -52,9 +54,26 @@ export default ({ setAccountFromMnemonic }: Props) => {
5254
<Container>
5355
<Form onSubmit={handleSubmitCreateSpending} className="mt-5">
5456
<Form.Group>
55-
<Form.Label>Create a password for your encrypted storage</Form.Label>
57+
<Form.Label>Private key:</Form.Label>
5658
<Form.Control
5759
required
60+
type="text"
61+
name="privateKey"
62+
value={newPrivateKey}
63+
onChange={event => setNewPrivateKey(event.target.value)}
64+
/>
65+
<Form.Text>
66+
It&apos;s a string like:
67+
<br />
68+
<code>
69+
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
70+
</code>
71+
</Form.Text>
72+
<Form.Label>
73+
Create a password to store your settings securely in an encrypted
74+
storage
75+
</Form.Label>
76+
<Form.Control
5877
type="password"
5978
id="password"
6079
name="password"
@@ -84,7 +103,7 @@ export default ({ setAccountFromMnemonic }: Props) => {
84103
</Form.Group>
85104
<Row className="justify-content-center">
86105
<Button variant="primary" type="submit">
87-
Create
106+
Initialize wallet using key string
88107
</Button>
89108
</Row>
90109
</Form>

examples/wallet/app/constants/routes.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
"INPUT_KEYS": "/input_keys",
66
"SEND": "/send",
77
"STAKING": "/staking",
8-
"SETTINGS": "/settings",
9-
"CREATE_SPENDING_PASSWORD": "/create_spending_password"
8+
"SETTINGS": "/settings"
109
}

examples/wallet/app/containers/CreateSpendingPassword.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/wallet/app/containers/InputKeys.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { bindActionCreators } from 'redux';
33
import { connect } from 'react-redux';
44
import InputKeys from '../pages/InputKeys';
5-
import { setAccount, setAccountFromMnemonic } from '../actions/account';
5+
import { setAccountFromMnemonic, setAccount } from '../actions/account';
66

77
function mapDispatchToProps(dispatch) {
8-
return bindActionCreators({ setAccount, setAccountFromMnemonic }, dispatch);
8+
return bindActionCreators({ setAccountFromMnemonic, setAccount }, dispatch);
99
}
1010

1111
export default connect(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @flow
2+
import { bindActionCreators } from 'redux';
3+
import { connect } from 'react-redux';
4+
import RestoreWalletFromPrivateKey from '../components/RestoreWalletFromPrivateKey';
5+
import { setAccount } from '../actions/account';
6+
7+
function mapDispatchToProps(dispatch) {
8+
return bindActionCreators({ setAccount }, dispatch);
9+
}
10+
11+
export default connect(
12+
undefined,
13+
mapDispatchToProps
14+
)(RestoreWalletFromPrivateKey);

examples/wallet/app/pages/InputKeys.js

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Container from 'react-bootstrap/Container';
66
import Tabs from 'react-bootstrap/Tabs';
77
import Tab from 'react-bootstrap/Tab';
88
import Row from 'react-bootstrap/Row';
9+
import RestoreWalletFromPrivateKey from '../components/RestoreWalletFromPrivateKey';
910
import typeof {
1011
setAccountFromMnemonic as SetAccountFromMnemonic,
1112
setAccount as SetAccount
@@ -19,11 +20,7 @@ type Props = {
1920

2021
// FIXME: this has no error handling, neither while parsing the address
2122
// nor when fetching the balance.
22-
export default ({ setAccount, setAccountFromMnemonic }: Props) => {
23-
const handleSubmitKeyString = function handleSubmitKeyString(event) {
24-
event.preventDefault();
25-
return setAccount(newPrivateKey);
26-
};
23+
export default ({ setAccountFromMnemonic, setAccount }: Props) => {
2724
const checkIsValidMnemonicPhrase = function checkIsValidMnemonicPhrase() {
2825
setIsMnemonicValid(isValidMnemonic(newMnemonicPhrase));
2926
};
@@ -40,45 +37,14 @@ export default ({ setAccount, setAccountFromMnemonic }: Props) => {
4037

4138
const [isMnemonicValid, setIsMnemonicValid] = useState(true);
4239

43-
const [newPrivateKey, setNewPrivateKey] = useState('');
44-
4540
const [newMnemonicPhrase, setNewMnemonicPhrase] = useState('');
4641

4742
const [newMnemonicPassword, setNewMnemonicPassword] = useState('');
4843

4944
return (
5045
<Tabs fill defaultActiveKey="keyString" className="justify-content-center">
5146
<Tab eventKey="keyString" title="Use key string">
52-
<Container>
53-
<Form onSubmit={handleSubmitKeyString} className="mt-5">
54-
<Form.Group>
55-
<Form.Label>Private key:</Form.Label>
56-
<Form.Control
57-
required
58-
type="text"
59-
name="privateKey"
60-
value={newPrivateKey}
61-
onChange={event => setNewPrivateKey(event.target.value)}
62-
/>
63-
<Form.Text>
64-
It&apos;s a string like:
65-
<br />
66-
<code>
67-
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
68-
</code>
69-
</Form.Text>
70-
</Form.Group>
71-
<Row className="justify-content-between">
72-
{/* TODO: bind this button */}
73-
<Button variant="secondary" type="button">
74-
Go back
75-
</Button>
76-
<Button variant="primary" type="submit">
77-
Initialize wallet using key string
78-
</Button>
79-
</Row>
80-
</Form>
81-
</Container>
47+
<RestoreWalletFromPrivateKey setAccount={setAccount} />
8248
</Tab>
8349
<Tab eventKey="mnemonic" title="Use mnemonic phrase">
8450
<Container>

0 commit comments

Comments
 (0)