Remove InfuraController

This commit is contained in:
Victor Baranov 2021-02-17 16:15:08 +03:00
parent 1bf007c028
commit e4f4590c7b
3 changed files with 0 additions and 113 deletions

View File

@ -1,42 +0,0 @@
import { ObservableStore } from '@metamask/obs-store'
const extend = require('xtend')
const log = require('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)
}
}
module.exports = InfuraController

View File

@ -25,7 +25,6 @@ const CurrencyController = require('./controllers/currency')
const NoticeController = require('./notice-controller')
const ShapeShiftController = require('./controllers/shapeshift')
const AddressBookController = require('./controllers/address-book')
const InfuraController = require('./controllers/infura')
const CachedBalancesController = require('./controllers/cached-balances')
const RecentBlocksController = require('./controllers/recent-blocks')
import MessageManager from './lib/message-manager'
@ -120,12 +119,6 @@ module.exports = class MetamaskController extends EventEmitter {
this.currencyController.updateConversionRate()
this.currencyController.scheduleConversionInterval()
// infura controller
this.infuraController = new InfuraController({
initState: initState.InfuraController,
})
this.infuraController.scheduleInfuraNetworkCheck()
this.phishingController = new PhishingController()
// rpc provider
@ -304,7 +297,6 @@ module.exports = class MetamaskController extends EventEmitter {
NoticeController: this.noticeController.store,
ShapeShiftController: this.shapeshiftController.store,
NetworkController: this.networkController.store,
InfuraController: this.infuraController.store,
CachedBalancesController: this.cachedBalancesController.store,
PermissionsController: this.permissionsController.permissions,
PermissionsMetadata: this.permissionsController.store,
@ -329,7 +321,6 @@ module.exports = class MetamaskController extends EventEmitter {
CurrencyController: this.currencyController.store,
NoticeController: this.noticeController.memStore,
ShapeshiftController: this.shapeshiftController.store,
InfuraController: this.infuraController.store,
PermissionsController: this.permissionsController.permissions,
PermissionsMetadata: this.permissionsController.store,
})

View File

@ -1,62 +0,0 @@
const assert = require('assert')
const sinon = require('sinon')
const InfuraController = require('../../../../app/scripts/controllers/infura')
describe('infura-controller', function () {
let infuraController, sandbox, networkStatus
const response = {'mainnet': 'degraded', 'ropsten': 'ok', 'kovan': 'ok', 'rinkeby': 'down'}
before(async function () {
infuraController = new InfuraController()
sandbox = sinon.createSandbox()
sinon.stub(infuraController, 'checkInfuraNetworkStatus').resolves(response)
networkStatus = await infuraController.checkInfuraNetworkStatus()
})
after(function () {
sandbox.restore()
})
describe('Network status queries', function () {
describe('Mainnet', function () {
it('should have Mainnet', function () {
assert.equal(Object.keys(networkStatus)[0], 'mainnet')
})
it('should have a value for Mainnet status', function () {
assert.equal(networkStatus.mainnet, 'degraded')
})
})
describe('Ropsten', function () {
it('should have Ropsten', function () {
assert.equal(Object.keys(networkStatus)[1], 'ropsten')
})
it('should have a value for Ropsten status', function () {
assert.equal(networkStatus.ropsten, 'ok')
})
})
describe('Kovan', function () {
it('should have Kovan', function () {
assert.equal(Object.keys(networkStatus)[2], 'kovan')
})
it('should have a value for Kovan status', function () {
assert.equal(networkStatus.kovan, 'ok')
})
})
describe('Rinkeby', function () {
it('should have Rinkeby', function () {
assert.equal(Object.keys(networkStatus)[3], 'rinkeby')
})
it('should have a value for Rinkeby status', function () {
assert.equal(networkStatus.rinkeby, 'down')
})
})
})
})