@@ -112,41 +112,32 @@ class KeyringController extends EventEmitter {
112112 * either as a string or Uint8Array.
113113 * @returns {Promise<object> } A Promise that resolves to the state.
114114 */
115- createNewVaultAndRestore ( password , seedPhrase ) {
115+ async createNewVaultAndRestore ( password , seedPhrase ) {
116116 const encodedSeedPhrase = this . _mnemonicToUint8Array ( seedPhrase ) ;
117117
118118 if ( typeof password !== 'string' ) {
119119 throw new Error ( 'Password must be text.' ) ;
120120 }
121121
122122 if ( ! bip39 . validateMnemonic ( encodedSeedPhrase , wordlist ) ) {
123- return Promise . reject (
124- new Error ( 'KeyringController - Seed phrase is invalid.' ) ,
125- ) ;
123+ throw new Error ( 'KeyringController - Seed phrase is invalid.' ) ;
126124 }
127125
128126 this . password = password ;
129127
130- this . clearKeyrings ( ) ;
131- return this . persistAllKeyrings ( password )
132- . then ( ( ) => {
133- return this . addNewKeyring ( KEYRINGS_TYPE_MAP . HD_KEYRING , {
134- mnemonic : encodedSeedPhrase ,
135- numberOfAccounts : 1 ,
136- } ) ;
137- } )
138- . then ( ( firstKeyring ) => {
139- return firstKeyring . getAccounts ( ) ;
140- } )
141- . then ( ( [ firstAccount ] ) => {
142- if ( ! firstAccount ) {
143- throw new Error ( 'KeyringController - First Account not found.' ) ;
144- }
145- return null ;
146- } )
147- . then ( this . persistAllKeyrings . bind ( this , password ) )
148- . then ( this . setUnlocked . bind ( this ) )
149- . then ( this . fullUpdate . bind ( this ) ) ;
128+ await this . clearKeyrings ( ) ;
129+ await this . persistAllKeyrings ( password ) ;
130+ const keyring = await this . addNewKeyring ( KEYRINGS_TYPE_MAP . HD_KEYRING , {
131+ mnemonic : encodedSeedPhrase ,
132+ numberOfAccounts : 1 ,
133+ } ) ;
134+ const [ firstAccount ] = await keyring . getAccounts ( ) ;
135+
136+ if ( ! firstAccount ) {
137+ throw new Error ( 'KeyringController - First Account not found.' ) ;
138+ }
139+ this . setUnlocked ( ) ;
140+ return this . fullUpdate ( ) ;
150141 }
151142
152143 /**
0 commit comments