aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-25 08:09:57 +0800
committerkumavis <aaron@kumavis.me>2017-01-25 08:09:57 +0800
commitbb1ee8e6497502427ee65fd60a62b1937cf0dd4c (patch)
tree6774f622ad14ede0b6c439d61bfdd00ca8d927ce /app/scripts
parent74dc20bdf179cbd8b25f6fae007553784466e3ff (diff)
parent4f39e8192cd94ad45d68992d5d1129f1612b1aa6 (diff)
downloadtangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar.gz
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar.bz2
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar.lz
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar.xz
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.tar.zst
tangerine-wallet-browser-bb1ee8e6497502427ee65fd60a62b1937cf0dd4c.zip
Merge branch 'dev' of github.com:MetaMask/metamask-plugin into obs-store2
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/keyring-controller.js42
-rw-r--r--app/scripts/metamask-controller.js22
2 files changed, 33 insertions, 31 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index 86c93f5a3..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,25 +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 () {
- 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()
- .then((serialized) => {
- const seedWords = serialized.mnemonic
- this.configManager.setSeedWords(seedWords)
- return this.fullUpdate()
- })
- }
-
// ClearSeedWordCache
//
// returns Promise( @string currentSelectedAccount )
@@ -259,9 +241,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))
@@ -426,18 +407,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()
+ return this.addNewKeyring('HD Key Tree', { numberOfAccounts: 1 })
+ .then((keyring) => {
+ 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()
})
.then(this.persistAllKeyrings.bind(this))
}
@@ -587,6 +567,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 2847873bd..d3077817d 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')
@@ -120,7 +121,20 @@ 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),
+ // 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'))
+ 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),
submitPassword: (password, cb) => {
@@ -135,6 +149,11 @@ module.exports = class MetamaskController extends EventEmitter {
.then((newState) => { cb(null, newState) })
.catch((reason) => { cb(reason) })
},
+ 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)
+ },
importAccountWithStrategy: (strategy, args, cb) => {
accountImporter.importAccount(strategy, args)
.then((privateKey) => {
@@ -145,7 +164,6 @@ module.exports = class MetamaskController extends EventEmitter {
.then(() => { cb(null, keyringController.fullUpdate()) })
.catch((reason) => { cb(reason) })
},
- addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController),
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),