aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-01-25 04:06:59 +0800
committerFrankie <frankie.diamond@gmail.com>2017-01-25 04:06:59 +0800
commit8642ced310890c7a3202a2826a2c74fad1fefca3 (patch)
tree5a3946e331dd5cb49a5aa88804cab072854098b6
parent85b34e3f2b89df9e8fbacc99b7bb39de977319d5 (diff)
downloadtangerine-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
-rw-r--r--app/scripts/keyring-controller.js9
-rw-r--r--app/scripts/metamask-controller.js7
-rw-r--r--package.json1
-rw-r--r--ui/app/actions.js4
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 () {