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

Commit c40da36

Browse files
committed
password validation on the first step
1 parent edb86d0 commit c40da36

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

src/action/auth-mobile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class AuthAction {
225225
await this._setToKeyStore(PASS, newPass);
226226
this._store.wallet.newPassword = newPass;
227227
this._store.wallet.passwordVerify = newPass;
228-
await this._wallet.checkNewPassword();
228+
await this._wallet.checkNewPasswordConfirmation();
229229
}
230230

231231
/**

src/action/wallet.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,23 @@ class WalletAction {
201201
this.initSetPassword();
202202
}
203203

204+
checkNewPassword() {
205+
const { newPassword } = this._store.wallet;
206+
if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) {
207+
this.initSetPassword();
208+
this._notification.display({ msg: `Set a password with at least ${MIN_PASSWORD_LENGTH} characters.` });
209+
} else {
210+
this._nav.goSetPasswordConfirm();
211+
}
212+
}
213+
204214
/**
205215
* Check the wallet password that was chosen by the user has the correct
206216
* length and that it was also entered correctly twice to make sure that
207217
* there was no typo.
208218
* @return {Promise<undefined>}
209219
*/
210-
async checkNewPassword() {
220+
async checkNewPasswordConfirmation() {
211221
const { newPassword, passwordVerify } = this._store.wallet;
212222
let errorMsg;
213223
if (!newPassword || newPassword.length < MIN_PASSWORD_LENGTH) {

src/view/set-password-confirm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const SetPasswordConfirmView = ({ store, wallet }) => (
3333
placeholder="Confirm password"
3434
password={store.wallet.passwordVerify}
3535
onChangeText={password => wallet.setPasswordVerify({ password })}
36-
onSubmitEditing={() => wallet.checkNewPassword()}
36+
onSubmitEditing={() => wallet.checkNewPasswordConfirmation()}
3737
/>
38-
<GlasButton onPress={() => wallet.checkNewPassword()}>Next</GlasButton>
38+
<GlasButton onPress={() => wallet.checkNewPasswordConfirmation()}>Next</GlasButton>
3939
</MainContent>
4040
</SplitBackground>
4141
);

src/view/set-password.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const SetPasswordView = ({ store, wallet, nav }) => (
3737
newCopy={store.newPasswordCopy}
3838
success={store.newPasswordSuccess}
3939
/>
40-
<GlasButton onPress={() => nav.goSetPasswordConfirm()}>Next</GlasButton>
40+
<GlasButton onPress={() => wallet.checkNewPassword()}>Next</GlasButton>
4141
</MainContent>
4242
</SplitBackground>
4343
);

stories/screen-story.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const autopilot = sinon.createStubInstance(AtplAction);
104104
sinon.stub(wallet, 'update');
105105
sinon.stub(wallet, 'checkSeed');
106106
sinon.stub(wallet, 'checkNewPassword');
107-
sinon.stub(wallet, 'checkPassword');
107+
sinon.stub(wallet, 'checkPasswordConfirmation');
108108
sinon.stub(wallet, 'getExchangeRate');
109109
const transaction = new TransactionAction(store, grpc, nav, notify);
110110
sinon.stub(transaction, 'update');

test/unit/action/auth-mobile.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ describe('Action AuthMobile Unit Tests', () => {
351351
);
352352
expect(store.wallet.newPassword, 'to match', /^[0-9a-f]{64}$/);
353353
expect(store.wallet.passwordVerify, 'to match', /^[0-9a-f]{64}$/);
354-
expect(wallet.checkNewPassword, 'was called once');
354+
expect(wallet.checkNewPasswordConfirmation, 'was called once');
355355
});
356356
});
357357

test/unit/action/wallet.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('Action Wallet Unit Tests', () => {
206206
});
207207
});
208208

209-
describe('checkNewPassword()', () => {
209+
describe('checkNewPasswordConfirmation()', () => {
210210
beforeEach(() => {
211211
sandbox.stub(wallet, 'initWallet');
212212
sandbox.stub(wallet, 'initSetPassword');
@@ -218,7 +218,7 @@ describe('Action Wallet Unit Tests', () => {
218218
it('init wallet if passwords match', async () => {
219219
wallet.setNewPassword({ password: 'secret123' });
220220
wallet.setPasswordVerify({ password: 'secret123' });
221-
await wallet.checkNewPassword();
221+
await wallet.checkNewPasswordConfirmation();
222222
expect(wallet.initWallet, 'was called with', {
223223
walletPassword: 'secret123',
224224
seedMnemonic: ['foo', 'bar', 'baz'],
@@ -229,7 +229,7 @@ describe('Action Wallet Unit Tests', () => {
229229
it('display notification if input does not match', async () => {
230230
wallet.setNewPassword({ password: 'secret123' });
231231
wallet.setPasswordVerify({ password: 'secret1234' });
232-
await wallet.checkNewPassword();
232+
await wallet.checkNewPasswordConfirmation();
233233
expect(wallet.initWallet, 'was not called');
234234
expect(wallet.initSetPassword, 'was called once');
235235
expect(notification.display, 'was called once');
@@ -238,7 +238,7 @@ describe('Action Wallet Unit Tests', () => {
238238
it('display notification if password is too short', async () => {
239239
wallet.setNewPassword({ password: 'secret' });
240240
wallet.setPasswordVerify({ password: 'secret' });
241-
await wallet.checkNewPassword();
241+
await wallet.checkNewPasswordConfirmation();
242242
expect(wallet.initWallet, 'was not called');
243243
expect(wallet.initSetPassword, 'was called once');
244244
expect(notification.display, 'was called once');
@@ -250,7 +250,7 @@ describe('Action Wallet Unit Tests', () => {
250250
store.settings.restoring = true;
251251
wallet.setNewPassword({ password: 'secret123' });
252252
wallet.setPasswordVerify({ password: 'secret123' });
253-
await wallet.checkNewPassword();
253+
await wallet.checkNewPasswordConfirmation();
254254
expect(wallet.initWallet, 'was called with', {
255255
walletPassword: 'secret123',
256256
seedMnemonic: restoreSeed,

0 commit comments

Comments
 (0)