You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
import ObservableStore from 'obs-store'
|
|
import extend from 'xtend'
|
|
import log from 'loglevel'
|
|
|
|
// every ten minutes
|
|
const POLLING_INTERVAL = 10 * 60 * 1000
|
|
|
|
class InfuraController {
|
|
|
|
constructor (opts = {}) {
|
|
const initState = extend({
|
|
infuraNetworkStatus: {},
|
|
}, opts.initState)
|
|
this.store = new ObservableStore(initState)
|
|
}
|
|
|
|
//
|
|
// PUBLIC METHODS
|
|
//
|
|
|
|
// Responsible for retrieving the status of Infura's nodes. Can return either
|
|
// ok, degraded, or down.
|
|
async checkInfuraNetworkStatus () {
|
|
const response = await fetch('https://api.infura.io/v1/status/metamask')
|
|
const parsedResponse = await response.json()
|
|
this.store.updateState({
|
|
infuraNetworkStatus: parsedResponse,
|
|
})
|
|
return parsedResponse
|
|
}
|
|
|
|
scheduleInfuraNetworkCheck () {
|
|
if (this.conversionInterval) {
|
|
clearInterval(this.conversionInterval)
|
|
}
|
|
this.conversionInterval = setInterval(() => {
|
|
this.checkInfuraNetworkStatus().catch(log.warn)
|
|
}, POLLING_INTERVAL)
|
|
}
|
|
}
|
|
|
|
export default InfuraController
|
|
|