55
66import { observe , when } from 'mobx' ;
77import { toBuffer , parseSat , checkHttpStatus , nap , poll } from '../helper' ;
8- import { MIN_PASSWORD_LENGTH , NOTIFICATION_DELAY , RATE_DELAY } from '../config' ;
8+ import {
9+ MIN_PASSWORD_LENGTH ,
10+ NOTIFICATION_DELAY ,
11+ RATE_DELAY ,
12+ RECOVERY_WINDOW ,
13+ } from '../config' ;
914import * as log from './log' ;
1015
1116class WalletAction {
@@ -41,6 +46,16 @@ class WalletAction {
4146 this . _store . wallet . seedVerify [ index ] = word . toLowerCase ( ) ;
4247 }
4348
49+ /**
50+ * Set the restore seed input by the seed word and
51+ * seed index.
52+ * @param {string } options.word The seed word
53+ * @param {number } options.index The seed index
54+ */
55+ setRestoreSeed ( { word, index } ) {
56+ this . _store . wallet . restoreSeed [ index ] = word ;
57+ }
58+
4459 //
4560 // Wallet Password actions
4661 //
@@ -82,6 +97,14 @@ class WalletAction {
8297 this . _store . wallet . passwordVerify = password ;
8398 }
8499
100+ /**
101+ * Set whether or not we're restoring the wallet.
102+ * @param {boolean } options.restoring Whether or not we're restoring.
103+ */
104+ setRestoringWallet ( { restoring } ) {
105+ this . _store . wallet . restoring = restoring ;
106+ }
107+
85108 //
86109 // Wallet actions
87110 //
@@ -98,7 +121,7 @@ class WalletAction {
98121 this . _store . firstStart = true ;
99122 this . _nav . goLoader ( ) ;
100123 await nap ( NOTIFICATION_DELAY ) ;
101- this . _nav . goSeed ( ) ;
124+ this . _nav . goSelectSeed ( ) ;
102125 } catch ( err ) {
103126 this . initPassword ( ) ;
104127 }
@@ -181,18 +204,60 @@ class WalletAction {
181204 * screen.
182205 * @param {string } options.walletPassword The user chosen password
183206 * @param {Array } options.seedMnemonic The seed words to generate the wallet
207+ * @param {number } options.recoveryWindow The number of addresses to recover
184208 * @return {Promise<undefined> }
185209 */
186- async initWallet ( { walletPassword, seedMnemonic } ) {
210+ async initWallet ( { walletPassword, seedMnemonic, recoveryWindow = 0 } ) {
187211 try {
188212 await this . _grpc . sendUnlockerCommand ( 'InitWallet' , {
189213 wallet_password : toBuffer ( walletPassword ) ,
190214 cipher_seed_mnemonic : seedMnemonic ,
215+ recovery_window : recoveryWindow ,
191216 } ) ;
192217 this . _store . walletUnlocked = true ;
193218 this . _nav . goSeedSuccess ( ) ;
194219 } catch ( err ) {
195- this . _notification . display ( { msg : 'Initializing wallet failed' , err } ) ;
220+ this . _notification . display ( {
221+ type : 'error' ,
222+ msg : `Initializing wallet failed: ${ err . details } ` ,
223+ } ) ;
224+ }
225+ }
226+
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 ( ) ;
196261 }
197262 }
198263
@@ -205,6 +270,20 @@ class WalletAction {
205270 await this . unlockWallet ( { walletPassword : password } ) ;
206271 }
207272
273+ /**
274+ * Initialize the wallet with the password input the seed that was already
275+ * inputted, and the default recovery window.
276+ * @return {Promise<undefined> }
277+ */
278+ async restoreWallet ( ) {
279+ const { password, restoreSeed } = this . _store . wallet ;
280+ await this . initWallet ( {
281+ walletPassword : password ,
282+ seedMnemonic : restoreSeed . toJSON ( ) ,
283+ recoveryWindow : RECOVERY_WINDOW ,
284+ } ) ;
285+ }
286+
208287 /**
209288 * Unlock the wallet by calling the grpc api with the user chosen password.
210289 * @param {string } options.walletPassword The password used to encrypt the wallet
0 commit comments