diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-01-25 04:06:59 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2017-01-25 04:06:59 +0800 |
commit | 8642ced310890c7a3202a2826a2c74fad1fefca3 (patch) | |
tree | 5a3946e331dd5cb49a5aa88804cab072854098b6 /app | |
parent | 85b34e3f2b89df9e8fbacc99b7bb39de977319d5 (diff) | |
download | tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar.gz tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar.bz2 tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar.lz tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar.xz tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.tar.zst tangerine-wallet-browser-8642ced310890c7a3202a2826a2c74fad1fefca3.zip |
Fix issue where generating a new account would put it in loose keys
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/keyring-controller.js | 9 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 7 |
2 files changed, 12 insertions, 4 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), |