From e4f4590c7b3e3b3c2912e0cc86759ad4d0d6bf8f Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 17 Feb 2021 16:15:08 +0300 Subject: [PATCH] Remove InfuraController --- app/scripts/controllers/infura.js | 42 ------------- app/scripts/metamask-controller.js | 9 --- .../app/controllers/infura-controller-test.js | 62 ------------------- 3 files changed, 113 deletions(-) delete mode 100644 app/scripts/controllers/infura.js delete mode 100644 test/unit/app/controllers/infura-controller-test.js diff --git a/app/scripts/controllers/infura.js b/app/scripts/controllers/infura.js deleted file mode 100644 index 2454423b4..000000000 --- a/app/scripts/controllers/infura.js +++ /dev/null @@ -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 diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5ba8a49e3..05c2ebbe3 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -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, }) diff --git a/test/unit/app/controllers/infura-controller-test.js b/test/unit/app/controllers/infura-controller-test.js deleted file mode 100644 index 7bd95dd4b..000000000 --- a/test/unit/app/controllers/infura-controller-test.js +++ /dev/null @@ -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') - }) - }) - }) -})