Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 858c7e0

Browse files
committed
fix up
1 parent 390991b commit 858c7e0

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

index.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('KeyringController', function () {
180180
it('throws error if argument password is not a string', async function () {
181181
await expect(() =>
182182
keyringController.createNewVaultAndRestore(12, walletTwoSeedWords),
183-
).toThrow('Password must be text.');
183+
).rejects.toThrow('Password must be text.');
184184
});
185185

186186
it('throws error if mnemonic passed is invalid', async function () {

0 commit comments

Comments
 (0)