From 6247e54fcc11d4d8d857a977d00eee8012afb92f Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 5 Jun 2018 11:15:58 -0700 Subject: add multivault detection to diagnostics reporting --- app/scripts/metamask-controller.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'app') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c753fc06f..ad1d6d6a7 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -46,6 +46,7 @@ const GWEI_BN = new BN('1000000000') const percentile = require('percentile') const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const cleanErrorStack = require('./lib/cleanErrorStack') +const notifier = require('./lib/bug-notifier') const log = require('loglevel') module.exports = class MetamaskController extends EventEmitter { @@ -64,6 +65,9 @@ module.exports = class MetamaskController extends EventEmitter { const initState = opts.initState || {} this.recordFirstTimeInfo(initState) + // metamask diagnostics reporter + this.notifier = opts.notifier || notifier + // platform-specific api this.platform = opts.platform @@ -487,6 +491,35 @@ module.exports = class MetamaskController extends EventEmitter { await this.keyringController.submitPassword(password) const accounts = await this.keyringController.getAccounts() + // verify keyrings + try { + const nonSimpleKeyrings = this.keyringController.keyrings.filter(keyring => keyring.type !== 'Simple Key Pair') + if (nonSimpleKeyrings.length > 1) { + const keyrings = await Promise.all(nonSimpleKeyrings.map(async (keyring, index) => { + return { + index, + type: keyring.type, + accounts: await keyring.getAccounts() + } + })) + // unexpected number of keyrings, report to diagnostics + const uri = 'https://diagnostics.metamask.io/v1/orphanedAccounts' + const firstTimeInfo = this.getFirstTimeInfo ? this.getFirstTimeInfo() : {} + await this.notifier.notify(uri, { + accounts: [], + metadata: { + type: 'keyrings', + keyrings, + version, + firstTimeInfo, + }, + }) + } + } catch (err) { + console.error('Keyring validation error:') + console.error(err) + } + await this.preferencesController.syncAddresses(accounts) return this.keyringController.fullUpdate() } -- cgit