From 20bdba3d1710a070d06c2a395f92d948b9396d47 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 5 Jun 2018 11:51:27 -0700 Subject: diagnostics - rewrite bug-notifier as diagnostics-reporter --- app/scripts/lib/bug-notifier.js | 22 ---------- app/scripts/lib/diagnostics-reporter.js | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 22 deletions(-) delete mode 100644 app/scripts/lib/bug-notifier.js create mode 100644 app/scripts/lib/diagnostics-reporter.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/bug-notifier.js b/app/scripts/lib/bug-notifier.js deleted file mode 100644 index 4d305b894..000000000 --- a/app/scripts/lib/bug-notifier.js +++ /dev/null @@ -1,22 +0,0 @@ -class BugNotifier { - notify (uri, message) { - return postData(uri, message) - } -} - -function postData(uri, data) { - return fetch(uri, { - body: JSON.stringify(data), // must match 'Content-Type' header - credentials: 'same-origin', // include, same-origin, *omit - headers: { - 'content-type': 'application/json', - }, - method: 'POST', // *GET, POST, PUT, DELETE, etc. - mode: 'cors', // no-cors, cors, *same-origin - }) -} - -const notifier = new BugNotifier() - -module.exports = notifier - diff --git a/app/scripts/lib/diagnostics-reporter.js b/app/scripts/lib/diagnostics-reporter.js new file mode 100644 index 000000000..6c77923bd --- /dev/null +++ b/app/scripts/lib/diagnostics-reporter.js @@ -0,0 +1,71 @@ +class DiagnosticsReporter { + + constructor ({ firstTimeInfo, version }) { + this.firstTimeInfo = firstTimeInfo + this.version = version + } + + async reportOrphans(orphans) { + try { + await this.submit({ + accounts: Object.keys(orphans), + metadata: { + type: 'orphans' + }, + }) + } catch (err) { + console.error('DiagnosticsReporter - "reportOrphans" encountered an error:') + console.error(err) + } + } + + async reportMultipleKeyrings(rawKeyrings) { + try { + const keyrings = await Promise.all(rawKeyrings.map(async (keyring, index) => { + return { + index, + type: keyring.type, + accounts: await keyring.getAccounts(), + } + })) + await this.submit({ + accounts: [], + metadata: { + type: 'keyrings', + keyrings, + }, + }) + } catch (err) { + console.error('DiagnosticsReporter - "reportMultipleKeyrings" encountered an error:') + console.error(err) + } + } + + async submit (message) { + try { + // add metadata + message.metadata.version = this.version + message.metadata.firstTimeInfo = this.firstTimeInfo + return await postData(message) + } catch (err) { + console.error('DiagnosticsReporter - "submit" encountered an error:') + console.error(err) + } + } + +} + +function postData(data) { + const uri = 'https://diagnostics.metamask.io/v1/orphanedAccounts' + return fetch(uri, { + body: JSON.stringify(data), // must match 'Content-Type' header + credentials: 'same-origin', // include, same-origin, *omit + headers: { + 'content-type': 'application/json', + }, + method: 'POST', // *GET, POST, PUT, DELETE, etc. + mode: 'cors', // no-cors, cors, *same-origin + }) +} + +module.exports = DiagnosticsReporter -- cgit From ece5cfc7858cb3e8077fad2c11f165a437e60413 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 5 Jun 2018 11:53:21 -0700 Subject: lint - fix diagnostics reporter --- app/scripts/lib/diagnostics-reporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/diagnostics-reporter.js b/app/scripts/lib/diagnostics-reporter.js index 6c77923bd..534a0fa8a 100644 --- a/app/scripts/lib/diagnostics-reporter.js +++ b/app/scripts/lib/diagnostics-reporter.js @@ -10,7 +10,7 @@ class DiagnosticsReporter { await this.submit({ accounts: Object.keys(orphans), metadata: { - type: 'orphans' + type: 'orphans', }, }) } catch (err) { -- cgit From 36a0574f566ba2b9aac53396721c0075dd1107e5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 5 Jun 2018 12:20:24 -0700 Subject: diagnostics - minor fixes --- app/scripts/lib/diagnostics-reporter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/diagnostics-reporter.js b/app/scripts/lib/diagnostics-reporter.js index 534a0fa8a..aa4ca6e26 100644 --- a/app/scripts/lib/diagnostics-reporter.js +++ b/app/scripts/lib/diagnostics-reporter.js @@ -7,7 +7,7 @@ class DiagnosticsReporter { async reportOrphans(orphans) { try { - await this.submit({ + return await this.submit({ accounts: Object.keys(orphans), metadata: { type: 'orphans', @@ -28,7 +28,7 @@ class DiagnosticsReporter { accounts: await keyring.getAccounts(), } })) - await this.submit({ + return await this.submit({ accounts: [], metadata: { type: 'keyrings', @@ -49,7 +49,7 @@ class DiagnosticsReporter { return await postData(message) } catch (err) { console.error('DiagnosticsReporter - "submit" encountered an error:') - console.error(err) + throw err } } -- cgit