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

Commit c5ef05a

Browse files
Add restoreIndex field to store and init functions for wallet restore.
restoreIndex keeps track of how many seed words the user has entered so we know which ones are remaining for the user to enter. We want to reset these values on the start of the restore process, as well as ensure they are up to date as the user goes from one page of restore entries to the next.
1 parent bc93d7e commit c5ef05a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/action/wallet.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,41 @@ class WalletAction {
224224
}
225225
}
226226

227+
/**
228+
* Initialize the restore wallet view by resetting input values and then
229+
* navigating to the view.
230+
* @return {undefined}
231+
*/
232+
initRestoreWallet() {
233+
this._store.wallet.restoreIndex = 0;
234+
this._nav.goRestoreSeed();
235+
}
236+
237+
/**
238+
* Initialize the next restore wallet view by setting a new restoreIndex or,
239+
* if all seed words have been entered, navigating to the password entry
240+
* view.
241+
* @return {undefined}
242+
*/
243+
initNextRestorePage() {
244+
if (this._store.wallet.restoreIndex < 21) {
245+
this._store.wallet.restoreIndex += 3;
246+
} else {
247+
this._nav.goRestorePassword();
248+
}
249+
}
250+
251+
/**
252+
* Initialize the previous restore wallet view by setting a new restoreIndex
253+
* or, if on the first seed entry page, navigating to the select seed view.
254+
* @return {undefined}
255+
*/
256+
initPrevRestorePage() {
257+
if (this._store.wallet.restoreIndex >= 3) {
258+
this._store.wallet.restoreIndex -= 3;
259+
} else {
260+
this._nav.goSelectSeed();
261+
}
227262
}
228263

229264
/**

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class Store {
4141
passwordVerify: '',
4242
seedVerify: ['', '', ''],
4343
restoring: false,
44+
restoreIndex: 0,
4445
restoreSeed: Array(24).fill(''),
4546
},
4647
transactions: [],

test/unit/action/wallet.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ describe('Action Wallet Unit Tests', () => {
236236
});
237237
});
238238

239+
describe('initRestoreWallet()', () => {
240+
it('should clear attributes and navigate to view', () => {
241+
store.wallet.restoreIndex = 42;
242+
wallet.initRestoreWallet();
243+
expect(store.wallet.restoreSeed.length, 'to equal', 24);
244+
expect(store.wallet.restoreIndex, 'to equal', 0);
245+
expect(nav.goRestoreSeed, 'was called once');
246+
});
247+
});
239248

240249
describe('setRestoreSeed()', () => {
241250
it('should clear attributes', () => {
@@ -244,6 +253,38 @@ describe('Action Wallet Unit Tests', () => {
244253
});
245254
});
246255

256+
describe('initPrevRestorePage()', () => {
257+
it('should navigate to select seed if restoreIndex < 3', () => {
258+
store.wallet.restoreIndex = 2;
259+
wallet.initPrevRestorePage();
260+
expect(nav.goSelectSeed, 'was called once');
261+
expect(store.wallet.restoreIndex, 'to equal', 2);
262+
});
263+
264+
it('should decrement restoreIndex if greater than 2', async () => {
265+
store.wallet.restoreIndex = 3;
266+
wallet.initPrevRestorePage();
267+
expect(nav.goSelectSeed, 'was not called');
268+
expect(store.wallet.restoreIndex, 'to equal', 0);
269+
});
270+
});
271+
272+
describe('initNextRestorePage()', () => {
273+
it('should navigate to password screen if restoreIndex > 20', () => {
274+
store.wallet.restoreIndex = 21;
275+
wallet.initNextRestorePage();
276+
expect(nav.goRestorePassword, 'was called once');
277+
expect(store.wallet.restoreIndex, 'to equal', 21);
278+
});
279+
280+
it('should increment restoreIndex if less than 21', async () => {
281+
store.wallet.restoreIndex = 18;
282+
wallet.initNextRestorePage();
283+
expect(nav.goRestorePassword, 'was not called');
284+
expect(store.wallet.restoreIndex, 'to equal', 21);
285+
});
286+
});
287+
247288
describe('initInitialDeposit()', () => {
248289
it('should navigate to new address screen if address is non-null', () => {
249290
store.walletAddress = 'non-null-addr';

0 commit comments

Comments
 (0)