2018-06-05 20:51:27 +02:00
|
|
|
class DiagnosticsReporter {
|
|
|
|
|
|
|
|
constructor ({ firstTimeInfo, version }) {
|
|
|
|
this.firstTimeInfo = firstTimeInfo
|
|
|
|
this.version = version
|
|
|
|
}
|
|
|
|
|
|
|
|
async reportOrphans(orphans) {
|
|
|
|
try {
|
2018-06-05 21:20:24 +02:00
|
|
|
return await this.submit({
|
2018-06-05 20:51:27 +02:00
|
|
|
accounts: Object.keys(orphans),
|
|
|
|
metadata: {
|
2018-06-05 20:53:21 +02:00
|
|
|
type: 'orphans',
|
2018-06-05 20:51:27 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
} 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(),
|
|
|
|
}
|
|
|
|
}))
|
2018-06-05 21:20:24 +02:00
|
|
|
return await this.submit({
|
2018-06-05 20:51:27 +02:00
|
|
|
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:')
|
2018-06-05 21:20:24 +02:00
|
|
|
throw err
|
2018-06-05 20:51:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|