diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-11-21 05:47:35 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-11-21 06:03:12 +0800 |
commit | 65cb9704872fe7730285f4185ea6bc1a2d28c149 (patch) | |
tree | 16c93fa964475e7923e110e7c9b5c984d03eafca | |
parent | c0aa7ce8574c6a88c348d86c71678fcd24ac168d (diff) | |
download | tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar.gz tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar.bz2 tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar.lz tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar.xz tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.tar.zst tangerine-wallet-browser-65cb9704872fe7730285f4185ea6bc1a2d28c149.zip |
Prevent creation of multiple vaults
Fixes #2577 by ensuring only one seed phrase can be set for a new vault.
Also cleans up logs and reproduction logic.
-rw-r--r-- | app/scripts/metamask-controller.js | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 69cf65554..a4c77e468 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -39,9 +39,6 @@ module.exports = class MetamaskController extends EventEmitter { constructor (opts) { super() - this.createVaultRequestStart = [] - this.createVaultRequestEnd = [] - this.createVaultMutex = new Mutex() this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200) @@ -54,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) @@ -474,36 +474,25 @@ module.exports = class MetamaskController extends EventEmitter { async createNewVaultAndKeychain (password) { const release = await this.createVaultMutex.acquire() - this.createVaultRequestStart.push(performance.now()) - this.createVaultRequestEnd.push(0); - const idx = this.createVaultRequestStart.length - 1; - if(idx === 1) { - await this.sleep(8000) - } - const vault = await this.keyringController.createNewVaultAndKeychain(password) - if(idx === 0) { - //await this.sleep(3000) + 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 } - console.log({ - "idx": idx, - "when": "before", - "obj": vault - }); - this.selectFirstIdentity(vault) - console.log({ - "idx": idx, - "when": "after", - "obj": vault - }); - this.createVaultRequestEnd[idx] = performance.now() - console.log(this.createVaultRequestStart) - console.log(this.createVaultRequestEnd) - release() - return vault - } - sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return vault } async createNewVaultAndRestore (password, seed) { |