aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorCsaba Solya <csaba.solya@gmail.com>2018-03-06 22:56:27 +0800
committerCsaba Solya <csaba.solya@gmail.com>2018-03-06 22:56:27 +0800
commit59007a6c36055f9197ad83ccb1741fa186b85f53 (patch)
treec4454834ea717ee70173dfcbf433001065a29770 /app/scripts/metamask-controller.js
parent8fde208f0b1da39ccd63b5f256902786e73e9368 (diff)
downloadtangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar.gz
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar.bz2
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar.lz
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar.xz
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.tar.zst
tangerine-wallet-browser-59007a6c36055f9197ad83ccb1741fa186b85f53.zip
modify verifySeedPhrase to async and call it from addNewAccount also
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js66
1 files changed, 34 insertions, 32 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index f523e3919..0a5c1d36f 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -345,7 +345,7 @@ module.exports = class MetamaskController extends EventEmitter {
// primary HD keyring management
addNewAccount: nodeify(this.addNewAccount, this),
placeSeedWords: this.placeSeedWords.bind(this),
- verifySeedPhrase: this.verifySeedPhrase.bind(this),
+ verifySeedPhrase: nodeify(this.verifySeedPhrase, this),
clearSeedWordCache: this.clearSeedWordCache.bind(this),
resetAccount: this.resetAccount.bind(this),
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
@@ -567,14 +567,18 @@ module.exports = class MetamaskController extends EventEmitter {
// Opinionated Keyring Management
//
- async addNewAccount (cb) {
+ async addNewAccount () {
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
- if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
+ if (!primaryKeyring) {
+ throw new Error('MetamaskController - No HD Key Tree found')
+ }
const keyringController = this.keyringController
const oldAccounts = await keyringController.getAccounts()
const keyState = await keyringController.addNewAccount(primaryKeyring)
const newAccounts = await keyringController.getAccounts()
+ await this.verifySeedPhrase()
+
newAccounts.forEach((address) => {
if (!oldAccounts.includes(address)) {
this.preferencesController.setSelectedAddress(address)
@@ -590,44 +594,42 @@ module.exports = class MetamaskController extends EventEmitter {
// Also used when revealing the seed words in the confirmation view.
placeSeedWords (cb) {
- this.verifySeedPhrase((err, seedWords) => {
-
- if (err) {
+ this.verifySeedPhrase()
+ .then((seedWords) => {
+ this.configManager.setSeedWords(seedWords)
+ return cb(null, seedWords)
+ })
+ .catch((err) => {
return cb(err)
- }
- this.configManager.setSeedWords(seedWords)
- return cb(null, seedWords)
- })
+ })
}
// Verifies the current vault's seed words if they can restore the
// accounts belonging to the current vault.
//
// Called when the first account is created and on unlocking the vault.
- verifySeedPhrase (cb) {
+ async verifySeedPhrase () {
const primaryKeyring = this.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
-
- primaryKeyring.getAccounts()
- .then((accounts) => {
- if (accounts.length < 1) {
- return cb(new Error('MetamaskController - No accounts found'))
- }
-
- seedPhraseVerifier.verifyAccounts(accounts, seedWords)
- .then(() => {
- return cb(null, seedWords)
- })
- .catch((err) => {
- log.error(err)
- return cb(err)
- })
- })
- })
+ if (!primaryKeyring) {
+ throw new Error('MetamaskController - No HD Key Tree found')
+ }
+
+ const serialized = await primaryKeyring.serialize()
+ const seedWords = serialized.mnemonic
+
+ const accounts = await primaryKeyring.getAccounts()
+ if (accounts.length < 1) {
+ throw new Error('MetamaskController - No accounts found')
+ }
+
+ try {
+ await seedPhraseVerifier.verifyAccounts(accounts, seedWords)
+ return seedWords
+ } catch (err) {
+ log.error(err.message)
+ throw err
+ }
}
// ClearSeedWordCache