aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js29
-rw-r--r--app/scripts/metamask-controller.js13
2 files changed, 24 insertions, 18 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 76422bf6b..5c75ca04a 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -171,11 +171,8 @@ module.exports = class KeyringController extends EventEmitter {
//
// Used when creating a first vault, to allow confirmation.
// Also used when revealing the seed words in the confirmation view.
- placeSeedWords () {
- const hdKeyrings = this.keyrings.filter((keyring) => keyring.type === 'HD Key Tree')
- const firstKeyring = hdKeyrings[0]
- if (!firstKeyring) throw new Error('KeyringController - No HD Key Tree found')
- return firstKeyring.serialize()
+ placeSeedWords (selectedKeyring) {
+ return selectedKeyring.serialize()
.then((serialized) => {
const seedWords = serialized.mnemonic
this.configManager.setSeedWords(seedWords)
@@ -259,11 +256,8 @@ module.exports = class KeyringController extends EventEmitter {
// Calls the `addAccounts` method on the Keyring
// in the kryings array at index `keyringNum`,
// and then saves those changes.
- addNewAccount () {
- const hdKeyrings = this.keyrings.filter((keyring) => keyring.type === 'HD Key Tree')
- const firstKeyring = hdKeyrings[0]
- if (!firstKeyring) throw new Error('KeyringController - No HD Key Tree found')
- return firstKeyring.addAccounts(1)
+ addNewAccount (selectedKeyring) {
+ return selectedKeyring.addAccounts(1)
.then(this.setupAccounts.bind(this))
.then(this.persistAllKeyrings.bind(this))
.then(this.fullUpdate.bind(this))
@@ -428,18 +422,17 @@ module.exports = class KeyringController extends EventEmitter {
// puts the current seed words into the state tree.
createFirstKeyTree () {
this.clearKeyrings()
- return this.addNewKeyring('HD Key Tree', {numberOfAccounts: 1})
- .then(() => {
- return this.keyrings[0].getAccounts()
- })
- .then((accounts) => {
+ return this.addNewKeyring('HD Key Tree', { numberOfAccounts: 1 })
+ .then((keyring) => {
+ const accounts = keyring.getAccounts()
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()
+ return this.placeSeedWords(this.getKeyringsByType('HD Key Tree')[0])
})
.then(this.persistAllKeyrings.bind(this))
}
@@ -589,6 +582,10 @@ module.exports = class KeyringController extends EventEmitter {
return this.keyringTypes.find(kr => kr.type === type)
}
+ getKeyringsByType (type) {
+ return this.keyrings.filter((keyring) => keyring.type === type)
+ }
+
// Get Accounts
// returns Promise( @Array[ @string accounts ] )
//
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 629216e42..a235be75b 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -1,5 +1,6 @@
const EventEmitter = require('events')
const extend = require('xtend')
+const promiseToCallback = require('promise-to-callback')
const EthStore = require('./lib/eth-store')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
const KeyringController = require('./keyring-controller')
@@ -106,7 +107,11 @@ module.exports = class MetamaskController extends EventEmitter {
// forward directly to keyringController
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
- placeSeedWords: nodeify(keyringController.placeSeedWords).bind(keyringController),
+ 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)
+ },
clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController),
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
submitPassword: (password, cb) => {
@@ -121,7 +126,11 @@ module.exports = class MetamaskController extends EventEmitter {
.then((newState) => { cb(null, newState) })
.catch((reason) => { cb(reason) })
},
- addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController),
+ addNewAccount: (cb) => {
+ const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0]
+ if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
+ promiseToCallback(keyringController.addNewAccount(primaryKeyring))(cb)
+ },
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),