Begin adding unconfigured notifier

feature/default_network_editable
Dan Finlay 7 years ago
parent 8fcaa2cf56
commit fd1ce4d741
  1. 19
      app/scripts/controllers/preferences.js
  2. 13
      app/scripts/lib/bug-notifier.js

@ -1,6 +1,8 @@
const ObservableStore = require('obs-store') const ObservableStore = require('obs-store')
const normalizeAddress = require('eth-sig-util').normalize const normalizeAddress = require('eth-sig-util').normalize
const extend = require('xtend') const extend = require('xtend')
const BugNotifier = require('../lib/bug-notifier')
const notifier = new BugNotifier()
class PreferencesController { class PreferencesController {
@ -30,6 +32,7 @@ class PreferencesController {
identities: {}, identities: {},
lostIdentities: {}, lostIdentities: {},
}, opts.initState) }, opts.initState)
this.store = new ObservableStore(initState) this.store = new ObservableStore(initState)
} }
// PUBLIC METHODS // PUBLIC METHODS
@ -108,16 +111,26 @@ class PreferencesController {
*/ */
syncAddresses (addresses) { syncAddresses (addresses) {
let { identities, lostIdentities } = this.store.getState() let { identities, lostIdentities } = this.store.getState()
Object.keys(identities).forEach((identity) => { Object.keys(identities).forEach((identity) => {
if (!addresses.includes(identity)) { if (!addresses.includes(identity)) {
delete identities[identity] delete identities[identity]
lostIdentities[identity] = identities[identity] lostIdentities[identity] = identities[identity]
}
})
// TODO: Report the bug to Sentry including the now-lost identity. // Identities are no longer present.
if (Object.keys(lostIdentities).length > 0) {
// timeout to prevent blocking the thread:
setTimeout(() => {
alert('Error 4486: MetaMask has encountered a very strange error. Please open a support issue immediately at support@metamask.io.') alert('Error 4486: MetaMask has encountered a very strange error. Please open a support issue immediately at support@metamask.io.')
}, 10)
// Notify our servers:
const uri =
notifier.notify(uri, { accounts: Object.keys(lostIdentities) })
.catch(log.error)
} }
})
this.store.updateState({ identities, lostIdentities }) this.store.updateState({ identities, lostIdentities })
this.addAddresses(addresses) this.addAddresses(addresses)

@ -1,26 +1,21 @@
class BugNotifier { class BugNotifier {
notify (message) { notify (uri, message) {
return postData(uri, message)
postData('http://example.com/answer', {answer: 42})
.then(data => console.log(data)) // JSON from `response.json()` call .then(data => console.log(data)) // JSON from `response.json()` call
.catch(error => console.error(error)) .catch(error => console.error(error))
} }
} }
function postData(url, data) { function postData(uri, data) {
// Default options are marked with *
return fetch(url, { return fetch(url, {
body: JSON.stringify(data), // must match 'Content-Type' header body: JSON.stringify(data), // must match 'Content-Type' header
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, same-origin, *omit credentials: 'same-origin', // include, same-origin, *omit
headers: { headers: {
'user-agent': 'Mozilla/4.0 MDN Example',
'content-type': 'application/json' 'content-type': 'application/json'
}, },
method: 'POST', // *GET, POST, PUT, DELETE, etc. method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, cors, *same-origin mode: 'cors', // no-cors, cors, *same-origin
redirect: 'follow', // manual, *follow, error
referrer: 'no-referrer', // *client, no-referrer
}) })
.then(response => response.json()) // parses response to JSON .then(response => response.json()) // parses response to JSON
} }
Loading…
Cancel
Save