Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 49c2c2c

Browse files
authored
Merge pull request #759 from lightninglabs/password-cleanup
Password cleanup
2 parents feb9cce + c0bde85 commit 49c2c2c

File tree

15 files changed

+225
-215
lines changed

15 files changed

+225
-215
lines changed

src/action/nav.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class NavAction {
4141
this._store.route = 'SetPassword';
4242
}
4343

44+
goSetPasswordConfirm() {
45+
this._store.route = 'SetPasswordConfirm';
46+
}
47+
4448
goPassword() {
4549
this._store.route = 'Password';
4650
}

src/action/wallet.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class WalletAction {
6666
* @return {undefined}
6767
*/
6868
initSetPassword() {
69-
this._store.wallet.password = '';
69+
this._store.wallet.newPassword = '';
7070
this._store.wallet.passwordVerify = '';
7171
this._nav.goSetPassword();
7272
}
@@ -203,17 +203,19 @@ class WalletAction {
203203
* @return {Promise<undefined>}
204204
*/
205205
async checkNewPassword() {
206-
const { password, passwordVerify } = this._store.wallet;
207-
if (!password || password.length < MIN_PASSWORD_LENGTH) {
208-
return this._notification.display({
209-
msg: `Set a password with at least ${MIN_PASSWORD_LENGTH} characters.`,
210-
});
206+
const { newPassword, passwordVerify } = this._store.wallet;
207+
let errorMsg;
208+
if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) {
209+
errorMsg = `Set a password with at least ${MIN_PASSWORD_LENGTH} characters.`;
210+
} else if (newPassword !== passwordVerify) {
211+
errorMsg = 'Passwords do not match!';
211212
}
212-
if (password !== passwordVerify) {
213-
return this._notification.display({ msg: 'Passwords do not match!' });
213+
if (errorMsg) {
214+
this.initSetPassword();
215+
return this._notification.display({ msg: errorMsg });
214216
}
215217
await this.initWallet({
216-
walletPassword: password,
218+
walletPassword: newPassword,
217219
seedMnemonic: this._store.seedMnemonic.toJSON(),
218220
});
219221
}

src/component/card.js

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import { View, StyleSheet } from 'react-native';
33
import PropTypes from 'prop-types';
4-
import PasswordEntry from './password-entry';
5-
import { FormSubText, FormStretcher } from '../component/form';
6-
import { color, font } from './style';
4+
import { color } from './style';
75

86
//
97
// Card
@@ -31,59 +29,4 @@ Card.propTypes = {
3129
style: View.propTypes.style,
3230
};
3331

34-
//
35-
// Password Card
36-
//
37-
38-
const passwordStyles = StyleSheet.create({
39-
card: {
40-
maxHeight: 420,
41-
maxWidth: 680,
42-
paddingLeft: 55,
43-
paddingRight: 55,
44-
paddingBottom: 50,
45-
},
46-
newCopy: {
47-
marginTop: 10,
48-
maxWidth: 250,
49-
color: color.blackText,
50-
height: font.lineHeightSub * 2,
51-
},
52-
});
53-
54-
export const PasswordCard = ({
55-
copy,
56-
placeholder,
57-
password,
58-
onChangeText,
59-
onSubmitEditing,
60-
newCopy,
61-
success,
62-
}) => (
63-
<Card style={passwordStyles.card}>
64-
<FormSubText>{copy}</FormSubText>
65-
<FormStretcher>
66-
<PasswordEntry
67-
placeholder={placeholder}
68-
value={password}
69-
autoFocus={true}
70-
onChangeText={onChangeText}
71-
onSubmitEditing={onSubmitEditing}
72-
success={success}
73-
/>
74-
<FormSubText style={passwordStyles.newCopy}>{newCopy}</FormSubText>
75-
</FormStretcher>
76-
</Card>
77-
);
78-
79-
PasswordCard.propTypes = {
80-
copy: PropTypes.string,
81-
placeholder: PropTypes.string,
82-
password: PropTypes.string,
83-
onChangeText: PropTypes.func.isRequired,
84-
onSubmitEditing: PropTypes.func.isRequired,
85-
newCopy: PropTypes.string,
86-
success: PropTypes.bool,
87-
};
88-
8932
export default Card;

src/component/password-entry.js

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,66 @@
11
import React, { Component } from 'react';
22
import { View, TouchableOpacity, StyleSheet } from 'react-native';
33
import PropTypes from 'prop-types';
4-
import Icon from './icon';
4+
import { FormSubText, FormStretcher } from './form';
5+
import { color, font } from './style';
56
import { InputField } from './field';
6-
import { color } from './style';
7+
import Card from './card';
8+
import Icon from './icon';
9+
10+
//
11+
// Password Card
12+
//
13+
14+
const passwordStyles = StyleSheet.create({
15+
card: {
16+
maxHeight: 350,
17+
maxWidth: 680,
18+
paddingLeft: 45,
19+
paddingRight: 45,
20+
paddingBottom: 50,
21+
},
22+
newCopy: {
23+
marginTop: 10,
24+
maxWidth: 250,
25+
color: color.blackText,
26+
height: font.lineHeightSub * 2,
27+
},
28+
});
29+
30+
export const PasswordCard = ({
31+
copy,
32+
placeholder,
33+
password,
34+
onChangeText,
35+
onSubmitEditing,
36+
newCopy,
37+
success,
38+
}) => (
39+
<Card style={passwordStyles.card}>
40+
<FormSubText>{copy}</FormSubText>
41+
<FormStretcher>
42+
<PasswordEntry
43+
placeholder={placeholder}
44+
value={password}
45+
autoFocus={true}
46+
onChangeText={onChangeText}
47+
onSubmitEditing={onSubmitEditing}
48+
success={success}
49+
/>
50+
<FormSubText style={passwordStyles.newCopy}>{newCopy}</FormSubText>
51+
</FormStretcher>
52+
</Card>
53+
);
54+
55+
PasswordCard.propTypes = {
56+
copy: PropTypes.string,
57+
placeholder: PropTypes.string,
58+
password: PropTypes.string,
59+
onChangeText: PropTypes.func.isRequired,
60+
onSubmitEditing: PropTypes.func.isRequired,
61+
newCopy: PropTypes.string,
62+
success: PropTypes.bool,
63+
};
764

865
//
966
// Password Entry

src/view/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Seed from './seed';
99
import SeedVerify from './seed-verify';
1010
import SeedSuccess from './seed-success';
1111
import SetPassword from './set-password';
12+
import SetPasswordConfirm from './set-password-confirm';
1213
import RestoreSeed from './restore-seed';
1314
import RestorePassword from './restore-password';
1415
import Password from './password';
@@ -73,7 +74,10 @@ class MainView extends Component {
7374
)}
7475
{route === 'SeedSuccess' && <SeedSuccess wallet={wallet} />}
7576
{route === 'SetPassword' && (
76-
<SetPassword store={store} wallet={wallet} />
77+
<SetPassword store={store} wallet={wallet} nav={nav} />
78+
)}
79+
{route === 'SetPasswordConfirm' && (
80+
<SetPasswordConfirm store={store} wallet={wallet} />
7781
)}
7882
{route === 'RestoreSeed' && (
7983
<RestoreSeed store={store} wallet={wallet} />

src/view/password.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React from 'react';
2-
import { StyleSheet, View } from 'react-native';
2+
import { StyleSheet } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
5-
import Background from '../component/background';
5+
import { SplitBackground } from '../component/background';
66
import MainContent from '../component/main-content';
77
import { H1Text } from '../component/text';
88
import { GlasButton } from '../component/button';
9-
import { InputField } from '../component/field';
10-
import Card from '../component/card';
11-
import { FormSubText, FormStretcher } from '../component/form';
9+
import { PasswordCard } from '../component/password-entry';
10+
import { color } from '../component/style';
1211

1312
//
1413
// Password View
@@ -22,38 +21,22 @@ const styles = StyleSheet.create({
2221
textAlign: 'center',
2322
marginBottom: 20,
2423
},
25-
card: {
26-
maxHeight: 350,
27-
maxWidth: 680,
28-
paddingLeft: 45,
29-
paddingRight: 45,
30-
paddingBottom: 50,
31-
},
3224
});
3325

3426
const PasswordView = ({ store, wallet }) => (
35-
<Background image="purple-gradient-bg">
27+
<SplitBackground image="purple-gradient-bg" bottom={color.blackDark}>
3628
<MainContent style={styles.content}>
37-
<View>
38-
<H1Text style={styles.title}>Unlock wallet</H1Text>
39-
</View>
40-
<Card style={styles.card}>
41-
<FormSubText>Please enter your password.</FormSubText>
42-
<FormStretcher>
43-
<InputField
44-
style={styles.input}
45-
placeholder="Password"
46-
secureTextEntry={true}
47-
autoFocus={true}
48-
value={store.wallet.password}
49-
onChangeText={password => wallet.setPassword({ password })}
50-
onSubmitEditing={() => wallet.checkPassword()}
51-
/>
52-
</FormStretcher>
53-
</Card>
29+
<H1Text style={styles.title}>Unlock wallet</H1Text>
30+
<PasswordCard
31+
copy="Please enter your password."
32+
placeholder="Password"
33+
password={store.wallet.password}
34+
onChangeText={password => wallet.setPassword({ password })}
35+
onSubmitEditing={() => wallet.checkPassword()}
36+
/>
5437
<GlasButton onPress={() => wallet.checkPassword()}>Unlock</GlasButton>
5538
</MainContent>
56-
</Background>
39+
</SplitBackground>
5740
);
5841

5942
PasswordView.propTypes = {

src/view/reset-password-confirm.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import { StyleSheet } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
5-
import { SplitBackground } from '../component/background';
5+
import Background from '../component/background';
66
import MainContent from '../component/main-content';
7-
import { PasswordCard } from '../component/card';
7+
import { PasswordCard } from '../component/password-entry';
88
import { Header, Title } from '../component/header';
99
import { H1Text } from '../component/text';
10-
import { Button, GlasButton, CancelButton } from '../component/button';
10+
import { BackButton, GlasButton, CancelButton } from '../component/button';
1111
import { color } from '../component/style';
1212

1313
//
@@ -25,24 +25,24 @@ const styles = StyleSheet.create({
2525
});
2626

2727
const ResetPasswordConfirmView = ({ store, nav, wallet }) => (
28-
<SplitBackground image="purple-gradient-bg" bottom={color.blackDark}>
29-
<Header shadow color={color.purple}>
30-
<Button disabled onPress={() => {}} />
28+
<Background color={color.blackDark}>
29+
<Header separator>
30+
<BackButton onPress={() => nav.goResetPasswordNew()} />
3131
<Title title="Change Password" />
32-
<CancelButton onPress={() => nav.goHome()} />
32+
<CancelButton onPress={() => nav.goSettings()} />
3333
</Header>
3434
<MainContent style={styles.content}>
35-
<H1Text style={styles.title}>Confirm new password</H1Text>
35+
<H1Text style={styles.title}>Confirm password</H1Text>
3636
<PasswordCard
3737
copy="Re-type your new password to confirm it."
38-
placeholder="New password"
38+
placeholder="Confirm password"
3939
password={store.wallet.passwordVerify}
4040
onChangeText={password => wallet.setPasswordVerify({ password })}
4141
onSubmitEditing={() => wallet.checkResetPassword()}
4242
/>
4343
<GlasButton onPress={() => wallet.checkResetPassword()}>Save</GlasButton>
4444
</MainContent>
45-
</SplitBackground>
45+
</Background>
4646
);
4747

4848
ResetPasswordConfirmView.propTypes = {

src/view/reset-password-current.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import { StyleSheet } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
5-
import { SplitBackground } from '../component/background';
5+
import Background from '../component/background';
66
import MainContent from '../component/main-content';
7-
import { PasswordCard } from '../component/card';
7+
import { PasswordCard } from '../component/password-entry';
88
import { Header, Title } from '../component/header';
99
import { H1Text } from '../component/text';
10-
import { Button, GlasButton, CancelButton } from '../component/button';
10+
import { BackButton, Button, GlasButton } from '../component/button';
1111
import { color } from '../component/style';
1212

1313
//
@@ -25,11 +25,11 @@ const styles = StyleSheet.create({
2525
});
2626

2727
const ResetPasswordCurrentView = ({ store, nav, wallet }) => (
28-
<SplitBackground image="purple-gradient-bg" bottom={color.blackDark}>
29-
<Header shadow color={color.purple}>
30-
<Button disabled onPress={() => {}} />
28+
<Background color={color.blackDark}>
29+
<Header separator>
30+
<BackButton onPress={() => nav.goSettings()} />
3131
<Title title="Change Password" />
32-
<CancelButton onPress={() => nav.goHome()} />
32+
<Button disabled onPress={() => {}} />
3333
</Header>
3434
<MainContent style={styles.content}>
3535
<H1Text style={styles.title}>Current password</H1Text>
@@ -42,7 +42,7 @@ const ResetPasswordCurrentView = ({ store, nav, wallet }) => (
4242
/>
4343
<GlasButton onPress={() => nav.goResetPasswordNew()}>Next</GlasButton>
4444
</MainContent>
45-
</SplitBackground>
45+
</Background>
4646
);
4747

4848
ResetPasswordCurrentView.propTypes = {

0 commit comments

Comments
 (0)