From 463a56ff54b0d850c86348e260e5f7c17b138ccb Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 24 Jan 2017 15:33:33 -0800 Subject: background controller - extract KeyringC.placeSeedWords to MetamaskC --- app/scripts/keyring-controller.js | 27 ++++++--------------------- app/scripts/metamask-controller.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'app') diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 5c75ca04a..741757c5a 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -150,12 +150,13 @@ module.exports = class KeyringController extends EventEmitter { mnemonic: seed, numberOfAccounts: 1, }) - }).then(() => { - const firstKeyring = this.keyrings[0] + }) + .then((firstKeyring) => { return firstKeyring.getAccounts() }) .then((accounts) => { const firstAccount = accounts[0] + if (!firstAccount) throw new Error('KeyringController - First Account not found.') const hexAccount = normalize(firstAccount) this.configManager.setSelectedAccount(hexAccount) return this.setupAccounts(accounts) @@ -164,22 +165,6 @@ module.exports = class KeyringController extends EventEmitter { .then(this.fullUpdate.bind(this)) } - // PlaceSeedWords - // returns Promise( @object state ) - // - // Adds the current vault's seed words to the UI's state tree. - // - // Used when creating a first vault, to allow confirmation. - // Also used when revealing the seed words in the confirmation view. - placeSeedWords (selectedKeyring) { - return selectedKeyring.serialize() - .then((serialized) => { - const seedWords = serialized.mnemonic - this.configManager.setSeedWords(seedWords) - return this.fullUpdate() - }) - } - // ClearSeedWordCache // // returns Promise( @string currentSelectedAccount ) @@ -424,15 +409,15 @@ module.exports = class KeyringController extends EventEmitter { this.clearKeyrings() return this.addNewKeyring('HD Key Tree', { numberOfAccounts: 1 }) .then((keyring) => { - const accounts = keyring.getAccounts() + return keyring.getAccounts() + }) + .then((accounts) => { const firstAccount = accounts[0] if (!firstAccount) throw new Error('KeyringController - No account found on keychain.') const hexAccount = normalize(firstAccount) this.configManager.setSelectedAccount(hexAccount) this.emit('newAccount', hexAccount) return this.setupAccounts(accounts) - }).then(() => { - return this.placeSeedWords(this.getKeyringsByType('HD Key Tree')[0]) }) .then(this.persistAllKeyrings.bind(this)) } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a235be75b..a1bb9a923 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -107,10 +107,19 @@ module.exports = class MetamaskController extends EventEmitter { // forward directly to keyringController createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController), createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController), + // Adds the current vault's seed words to the UI's state tree. + // + // Used when creating a first vault, to allow confirmation. + // Also used when revealing the seed words in the confirmation view. placeSeedWords: (cb) => { const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0] if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) - promiseToCallback(keyringController.placeSeedWords(primaryKeyring))(cb) + primaryKeyring.serialize() + .then((serialized) => { + const seedWords = serialized.mnemonic + this.configManager.setSeedWords(seedWords) + promiseToCallback(this.keyringController.fullUpdate())(cb) + }) }, clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController), setLocked: nodeify(keyringController.setLocked).bind(keyringController), -- cgit v1.2.3