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

Commit 89b7448

Browse files
Merge pull request #1106 from lightninglabs/dev/seed-recovery-mobile
Dev/seed recovery mobile
2 parents e110f57 + 87d1b60 commit 89b7448

File tree

12 files changed

+154
-118
lines changed

12 files changed

+154
-118
lines changed

src/action/nav-mobile.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ class NavAction {
5555
this._navigate('RestoreSeed');
5656
}
5757

58-
goRestorePin() {
59-
this._navigate('RestorePin');
60-
}
61-
6258
goSeedSuccess() {
6359
this._navigate('SeedSuccess');
6460
}

src/action/nav.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class NavAction {
2929
this._store.route = 'RestoreSeed';
3030
}
3131

32-
goRestorePassword() {
33-
this._store.route = 'RestorePassword';
34-
}
35-
3632
goSeedSuccess() {
3733
this._store.route = 'SeedSuccess';
3834
}

src/action/wallet.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ class WalletAction {
5353
* @param {number} options.index The seed index
5454
*/
5555
setRestoreSeed({ word, index }) {
56-
this._store.wallet.restoreSeed[index] = word;
56+
this._store.seedMnemonic[index] = word;
57+
}
58+
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;
5765
}
5866

5967
//
@@ -212,6 +220,7 @@ class WalletAction {
212220
}
213221
await this.initWallet({
214222
walletPassword: newPassword,
223+
recoveryWindow: this._store.settings.restoring ? RECOVERY_WINDOW : 0,
215224
seedMnemonic: this._store.seedMnemonic.toJSON(),
216225
});
217226
}
@@ -311,6 +320,7 @@ class WalletAction {
311320
* @return {undefined}
312321
*/
313322
initRestoreWallet() {
323+
this._store.seedMnemonic = Array(24).fill('');
314324
this._store.wallet.restoreIndex = 0;
315325
this._nav.goRestoreSeed();
316326
}
@@ -324,8 +334,9 @@ class WalletAction {
324334
initNextRestorePage() {
325335
if (this._store.wallet.restoreIndex < 21) {
326336
this._store.wallet.restoreIndex += 3;
337+
this._store.wallet.focusedRestoreInd = this._store.wallet.restoreIndex;
327338
} else {
328-
this._nav.goRestorePassword();
339+
this.initSetPassword();
329340
}
330341
}
331342

@@ -337,6 +348,7 @@ class WalletAction {
337348
initPrevRestorePage() {
338349
if (this._store.wallet.restoreIndex >= 3) {
339350
this._store.wallet.restoreIndex -= 3;
351+
this._store.wallet.focusedRestoreInd = this._store.wallet.restoreIndex;
340352
} else {
341353
this._nav.goSelectSeed();
342354
}
@@ -375,20 +387,6 @@ class WalletAction {
375387
await this.unlockWallet({ walletPassword: password });
376388
}
377389

378-
/**
379-
* Initialize the wallet with the password input the seed that was already
380-
* inputted, and the default recovery window.
381-
* @return {Promise<undefined>}
382-
*/
383-
async restoreWallet() {
384-
const { password, restoreSeed } = this._store.wallet;
385-
await this.initWallet({
386-
walletPassword: password,
387-
seedMnemonic: restoreSeed.toJSON(),
388-
recoveryWindow: RECOVERY_WINDOW,
389-
});
390-
}
391-
392390
/**
393391
* Unlock the wallet by calling the grpc api with the user chosen password.
394392
* @param {string} options.walletPassword The password used to encrypt the wallet

src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Store {
5151
seedVerify: ['', '', ''],
5252
seedIndex: 0,
5353
restoreIndex: 0,
54-
restoreSeed: Array(24).fill(''),
54+
focusedRestoreInd: 0,
5555
},
5656
transactions: [],
5757
selectedTransaction: null,

src/view/main-mobile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import SeedVerifyView from './seed-verify-mobile';
1616
import SetPinView from './set-pin-mobile';
1717
import SetPinConfirmView from './set-pin-confirm-mobile';
1818
import SeedSuccessView from './seed-success-mobile';
19+
import RestoreSeedView from './restore-seed-mobile';
1920
import NewAddressView from './new-address-mobile';
2021

2122
import PinView from './pin-mobile';
@@ -84,6 +85,8 @@ const SetPasswordConfirm = () => (
8485

8586
const SeedSuccess = () => <SeedSuccessView wallet={wallet} />;
8687

88+
const RestoreSeed = () => <RestoreSeedView store={store} wallet={wallet} />;
89+
8790
const NewAddress = () => (
8891
<NewAddressView store={store} invoice={invoice} info={info} />
8992
);
@@ -190,6 +193,7 @@ const MainStack = createStackNavigator(
190193
SetPassword,
191194
SetPasswordConfirm,
192195
SeedSuccess,
196+
RestoreSeed,
193197
NewAddress,
194198
Password,
195199
LoaderSyncing,

src/view/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import SeedSuccess from './seed-success';
1111
import SetPassword from './set-password';
1212
import SetPasswordConfirm from './set-password-confirm';
1313
import RestoreSeed from './restore-seed';
14-
import RestorePassword from './restore-password';
1514
import Password from './password';
1615
import ResetPasswordCurrent from './reset-password-current';
1716
import ResetPasswordNew from './reset-password-new';
@@ -83,9 +82,6 @@ class MainView extends Component {
8382
{route === 'RestoreSeed' && (
8483
<RestoreSeed store={store} wallet={wallet} />
8584
)}
86-
{route === 'RestorePassword' && (
87-
<RestorePassword store={store} wallet={wallet} nav={nav} />
88-
)}
8985
{route === 'Password' && <Password store={store} wallet={wallet} />}
9086
{route === 'ResetPasswordCurrent' && (
9187
<ResetPasswordCurrent store={store} nav={nav} wallet={wallet} />

src/view/restore-password.js

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

src/view/restore-seed-mobile.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React from 'react';
2+
import { observer } from 'mobx-react';
3+
import PropTypes from 'prop-types';
4+
import SeedEntry from '../component/seed-entry';
5+
import { Button, BackButton, SmallGlasButton } from '../component/button';
6+
import { FormSubText } from '../component/form';
7+
import Background from '../component/background';
8+
import MainContent from '../component/main-content';
9+
import { CopyOnboardText } from '../component/text';
10+
import { Header } from '../component/header';
11+
import Card from '../component/card';
12+
import { createStyles, maxWidth } from '../component/media-query';
13+
import { smallBreakWidth } from '../component/style';
14+
15+
//
16+
// Restore Seed View (Mobile)
17+
//
18+
19+
const baseStyles = {
20+
content: {
21+
justifyContent: 'flex-end',
22+
},
23+
title: {
24+
textAlign: 'center',
25+
marginBottom: 20,
26+
},
27+
subText: {
28+
maxWidth: 235,
29+
},
30+
};
31+
32+
const styles = createStyles(
33+
baseStyles,
34+
35+
maxWidth(smallBreakWidth, {
36+
title: {
37+
fontSize: 30,
38+
lineHeight: 40,
39+
},
40+
})
41+
);
42+
43+
const RestoreSeedView = ({ store, wallet }) => (
44+
<Background image="purple-gradient-bg">
45+
<Header>
46+
<BackButton onPress={() => wallet.initPrevRestorePage()} />
47+
<Button disabled onPress={() => {}} />
48+
</Header>
49+
<MainContent style={styles.content}>
50+
<CopyOnboardText style={styles.title}>
51+
Restore your wallet
52+
</CopyOnboardText>
53+
<Card>
54+
<FormSubText style={styles.subText}>
55+
{store.restoreVerifyCopy}
56+
</FormSubText>
57+
{store.restoreVerifyIndexes.map((seedIndex, i) => (
58+
<SeedEntry
59+
seedIndex={seedIndex}
60+
value={store.seedMnemonic[seedIndex - 1]}
61+
onChangeText={word =>
62+
wallet.setRestoreSeed({ word, index: seedIndex - 1 })
63+
}
64+
key={i}
65+
autoFocus={seedIndex - 1 === store.wallet.focusedRestoreInd}
66+
onSubmitEditing={() =>
67+
i === 2
68+
? wallet.initNextRestorePage()
69+
: wallet.setFocusedRestoreInd({ index: seedIndex })
70+
}
71+
onClick={() =>
72+
wallet.setFocusedRestoreInd({ index: seedIndex - 1 })
73+
}
74+
/>
75+
))}
76+
</Card>
77+
<SmallGlasButton onPress={() => wallet.initNextRestorePage()}>
78+
Next
79+
</SmallGlasButton>
80+
</MainContent>
81+
</Background>
82+
);
83+
84+
RestoreSeedView.propTypes = {
85+
store: PropTypes.object.isRequired,
86+
wallet: PropTypes.object.isRequired,
87+
};
88+
89+
export default observer(RestoreSeedView);

src/view/restore-seed.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ const RestoreSeedView = ({ store, wallet }) => (
4747
{store.restoreVerifyIndexes.map((seedIndex, i) => (
4848
<SeedEntry
4949
seedIndex={seedIndex}
50-
value={store.wallet.restoreSeed[seedIndex - 1]}
50+
value={store.seedMnemonic[seedIndex - 1]}
5151
onChangeText={word =>
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>

stories/screen-story.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import SetPasswordConfirm from '../src/view/set-password-confirm';
7373
import SetPinConfirmMobile from '../src/view/set-pin-confirm-mobile';
7474
import Password from '../src/view/password';
7575
import PinMobile from '../src/view/pin-mobile';
76-
import RestorePassword from '../src/view/restore-password';
7776
import ResetPasswordCurrent from '../src/view/reset-password-current';
7877
import ResetPasswordNew from '../src/view/reset-password-new';
7978
import ResetPasswordConfirm from '../src/view/reset-password-confirm';
@@ -83,6 +82,7 @@ import NewAddressMobile from '../src/view/new-address-mobile';
8382
import Wait from '../src/view/wait';
8483
import WaitMobile from '../src/view/wait-mobile';
8584
import RestoreSeed from '../src/view/restore-seed';
85+
import RestoreSeedMobile from '../src/view/restore-seed-mobile';
8686

8787
const store = new Store();
8888
store.init();
@@ -139,6 +139,9 @@ storiesOf('Screens', module)
139139
.add('Restore Wallet: Seed', () => (
140140
<RestoreSeed store={store} wallet={wallet} />
141141
))
142+
.add('Restore Wallet: Seed (Mobile)', () => (
143+
<RestoreSeedMobile store={store} wallet={wallet} />
144+
))
142145
.add('Seed Success', () => <SeedSuccess wallet={wallet} />)
143146
.add('Seed Success (Mobile)', () => <SeedSuccessMobile wallet={wallet} />)
144147
.add('Set Password', () => (
@@ -155,9 +158,6 @@ storiesOf('Screens', module)
155158
))
156159
.add('Password', () => <Password store={store} wallet={wallet} />)
157160
.add('PIN (Mobile)', () => <PinMobile store={store} auth={auth} />)
158-
.add('Restore Wallet: Password', () => (
159-
<RestorePassword store={store} wallet={wallet} nav={nav} />
160-
))
161161
.add('Reset Password - Current', () => (
162162
<ResetPasswordCurrent store={store} wallet={wallet} nav={nav} />
163163
))

0 commit comments

Comments
 (0)