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

Commit d8f3340

Browse files
valentinewallacetanx
authored andcommitted
Automatically focus first input during restore seed pagination.
1 parent f4c5f32 commit d8f3340

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/action/wallet.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class WalletAction {
5656
this._store.wallet.restoreSeed[index] = word;
5757
}
5858

59+
/**
60+
* Set which seed restore input is in focus.
61+
* @param {number} options.index The index of the input.
62+
*/
63+
setFocusedRestoreInd({ index }) {
64+
this._store.wallet.focusedRestoreInd = index;
65+
}
66+
5967
//
6068
// Wallet Password actions
6169
//
@@ -327,6 +335,7 @@ class WalletAction {
327335
initNextRestorePage() {
328336
if (this._store.wallet.restoreIndex < 21) {
329337
this._store.wallet.restoreIndex += 3;
338+
this._store.wallet.focusedRestoreInd = this._store.wallet.restoreIndex;
330339
} else {
331340
this.initSetPassword();
332341
}
@@ -340,6 +349,7 @@ class WalletAction {
340349
initPrevRestorePage() {
341350
if (this._store.wallet.restoreIndex >= 3) {
342351
this._store.wallet.restoreIndex -= 3;
352+
this._store.wallet.focusedRestoreInd = this._store.wallet.restoreIndex;
343353
} else {
344354
this._nav.goSelectSeed();
345355
}

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class Store {
5151
seedVerify: ['', '', ''],
5252
seedIndex: 0,
5353
restoreIndex: 0,
54+
focusedRestoreInd: 0,
5455
restoreSeed: Array(24).fill(''),
5556
},
5657
transactions: [],

src/view/restore-seed.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ const RestoreSeedView = ({ store, wallet }) => (
5252
wallet.setRestoreSeed({ word, index: seedIndex - 1 })
5353
}
5454
key={i}
55-
autoFocus={i === 0}
56-
onSubmitEditing={() => wallet.initNextRestorePage()}
55+
autoFocus={seedIndex - 1 === store.wallet.focusedRestoreInd}
56+
onSubmitEditing={() =>
57+
i === 2
58+
? wallet.initNextRestorePage()
59+
: wallet.setFocusedRestoreInd({ index: seedIndex })
60+
}
61+
onClick={() =>
62+
wallet.setFocusedRestoreInd({ index: seedIndex - 1 })
63+
}
5764
/>
5865
))}
5966
</Card>

test/unit/action/wallet.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ describe('Action Wallet Unit Tests', () => {
381381
});
382382
});
383383

384+
describe('setFocusedRestoreInd()', () => {
385+
it('should set the currently focused restore seed index', () => {
386+
wallet.setFocusedRestoreInd({ index: 5 });
387+
expect(store.wallet.focusedRestoreInd, 'to equal', 5);
388+
});
389+
});
390+
384391
describe('initPrevRestorePage()', () => {
385392
it('should navigate to select seed if restoreIndex < 3', () => {
386393
store.wallet.restoreIndex = 2;
@@ -391,9 +398,11 @@ describe('Action Wallet Unit Tests', () => {
391398

392399
it('should decrement restoreIndex if greater than 2', async () => {
393400
store.wallet.restoreIndex = 3;
401+
store.wallet.focusedRestoreInd = 5;
394402
wallet.initPrevRestorePage();
395403
expect(nav.goSelectSeed, 'was not called');
396404
expect(store.wallet.restoreIndex, 'to equal', 0);
405+
expect(store.wallet.focusedRestoreInd, 'to equal', 0);
397406
});
398407
});
399408

@@ -407,9 +416,11 @@ describe('Action Wallet Unit Tests', () => {
407416

408417
it('should increment restoreIndex if less than 21', async () => {
409418
store.wallet.restoreIndex = 18;
419+
store.wallet.focusedRestoreInd = 19;
410420
wallet.initNextRestorePage();
411421
expect(nav.goSetPassword, 'was not called');
412422
expect(store.wallet.restoreIndex, 'to equal', 21);
423+
expect(store.wallet.focusedRestoreInd, 'to equal', 21);
413424
});
414425
});
415426

0 commit comments

Comments
 (0)