diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2017-11-28 03:37:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 03:37:42 +0800 |
commit | e71115735c9b9d34fe85bc9e644f3b910bdaa014 (patch) | |
tree | 847d13545af412929a2e313af9dcf1e7b2e921a9 /app/scripts | |
parent | 94fe294cafbe9bfef91f2b9c1aff4caddb35ebd3 (diff) | |
parent | bd45022a2f04fd3d60f1e0da6963344d90aa91a1 (diff) | |
download | tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar.gz tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar.bz2 tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar.lz tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar.xz tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.tar.zst tangerine-wallet-browser-e71115735c9b9d34fe85bc9e644f3b910bdaa014.zip |
Merge pull request #2605 from MetaMask/i2577-SeedPhraseBug
Fix a possible seed phrase bug
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/metamask-controller.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 968589f6e..a4c77e468 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -31,6 +31,7 @@ const ConfigManager = require('./lib/config-manager') const nodeify = require('./lib/nodeify') const accountImporter = require('./account-import-strategies') const getBuyEthUrl = require('./lib/buy-eth-url') +const Mutex = require('await-semaphore').Mutex const version = require('../manifest.json').version module.exports = class MetamaskController extends EventEmitter { @@ -38,6 +39,7 @@ module.exports = class MetamaskController extends EventEmitter { constructor (opts) { super() + this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200) this.opts = opts @@ -49,6 +51,9 @@ module.exports = class MetamaskController extends EventEmitter { // observable state store this.store = new ObservableStore(initState) + // lock to ensure only one vault created at once + this.createVaultMutex = new Mutex() + // network store this.networkController = new NetworkController(initState.NetworkController) @@ -467,15 +472,34 @@ module.exports = class MetamaskController extends EventEmitter { // Vault Management // - async createNewVaultAndKeychain (password, cb) { - const vault = await this.keyringController.createNewVaultAndKeychain(password) - this.selectFirstIdentity(vault) + async createNewVaultAndKeychain (password) { + const release = await this.createVaultMutex.acquire() + let vault + + try { + const accounts = await this.keyringController.getAccounts() + + if (accounts.length > 0) { + vault = await this.keyringController.fullUpdate() + + } else { + let vault = await this.keyringController.createNewVaultAndKeychain(password) + this.selectFirstIdentity(vault) + } + release() + } catch (err) { + release() + throw err + } + return vault } - async createNewVaultAndRestore (password, seed, cb) { + async createNewVaultAndRestore (password, seed) { + const release = await this.createVaultMutex.acquire() const vault = await this.keyringController.createNewVaultAndRestore(password, seed) this.selectFirstIdentity(vault) + release() return vault } |