diff options
-rw-r--r-- | app/scripts/keyring-controller.js | 9 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 7 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | ui/app/actions.js | 4 |
4 files changed, 15 insertions, 6 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 86c93f5a3..95f0a1d63 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -259,9 +259,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 (keyRingNum = 0) { - const ring = this.keyrings[keyRingNum] - return ring.addAccounts(1) + addNewAccount (selectedKeyring) { + return selectedKeyring.addAccounts(1) .then(this.setupAccounts.bind(this)) .then(this.persistAllKeyrings.bind(this)) .then(this.fullUpdate.bind(this)) @@ -587,6 +586,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..6b6424f2a 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') @@ -121,7 +122,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), diff --git a/package.json b/package.json index 2c0c30523..595d579f2 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "polyfill-crypto.getrandomvalues": "^1.0.0", "post-message-stream": "^1.0.0", "promise-filter": "^1.1.0", + "promise-to-callback": "^1.0.0", "pumpify": "^1.3.4", "qrcode-npm": "0.0.3", "react": "^15.0.2", diff --git a/ui/app/actions.js b/ui/app/actions.js index 7934a329a..9a68d231a 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -270,8 +270,8 @@ function navigateToNewAccountScreen() { } } -function addNewAccount (ringNumber = 0) { - return callBackgroundThenUpdate(background.addNewAccount, ringNumber) +function addNewAccount () { + return callBackgroundThenUpdate(background.addNewAccount) } function showInfoPage () { |