aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorThomas Huang <tmashuang@users.noreply.github.com>2017-06-27 03:06:23 +0800
committerGitHub <noreply@github.com>2017-06-27 03:06:23 +0800
commit8b5b2d832995ca4b928c47abebd7e5476ac71e6a (patch)
treee008ea15657ec0019caa119c6af6ef6e0b1f4fad /app
parent27a0694d8519b302a14080f5b72ddf1c73e0d9a7 (diff)
parent42a2bcb1325bd5763a6402d5c2d6634053da908b (diff)
downloadtangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar.gz
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar.bz2
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar.lz
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar.xz
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.tar.zst
tangerine-wallet-browser-8b5b2d832995ca4b928c47abebd7e5476ac71e6a.zip
Merge pull request #1663 from MetaMask/infura-status
Add Infura Status Information to UI State
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/infura.js42
-rw-r--r--app/scripts/metamask-controller.js15
2 files changed, 56 insertions, 1 deletions
diff --git a/app/scripts/controllers/infura.js b/app/scripts/controllers/infura.js
new file mode 100644
index 000000000..98375b446
--- /dev/null
+++ b/app/scripts/controllers/infura.js
@@ -0,0 +1,42 @@
+const ObservableStore = require('obs-store')
+const extend = require('xtend')
+
+// every ten minutes
+const POLLING_INTERVAL = 300000
+
+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.
+ checkInfuraNetworkStatus () {
+ return fetch('https://api.infura.io/v1/status/metamask')
+ .then(response => response.json())
+ .then((parsedResponse) => {
+ this.store.updateState({
+ infuraNetworkStatus: parsedResponse,
+ })
+ })
+ }
+
+ scheduleInfuraNetworkCheck () {
+ if (this.conversionInterval) {
+ clearInterval(this.conversionInterval)
+ }
+ this.conversionInterval = setInterval(() => {
+ this.checkInfuraNetworkStatus()
+ }, POLLING_INTERVAL)
+ }
+}
+
+module.exports = InfuraController
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index f33da5213..1a83c70f5 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -15,6 +15,7 @@ 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 MessageManager = require('./lib/message-manager')
const PersonalMessageManager = require('./lib/personal-message-manager')
const TransactionController = require('./controllers/transactions')
@@ -44,8 +45,8 @@ module.exports = class MetamaskController extends EventEmitter {
this.store = new ObservableStore(initState)
// network store
-
this.networkController = new NetworkController(initState.NetworkController)
+
// config manager
this.configManager = new ConfigManager({
store: this.store,
@@ -63,6 +64,13 @@ module.exports = class MetamaskController extends EventEmitter {
this.currencyController.updateConversionRate()
this.currencyController.scheduleConversionInterval()
+ // infura controller
+ this.infuraController = new InfuraController({
+ initState: initState.InfuraController,
+ })
+ this.infuraController.scheduleInfuraNetworkCheck()
+
+
// rpc provider
this.provider = this.initializeProvider()
@@ -147,6 +155,9 @@ module.exports = class MetamaskController extends EventEmitter {
this.networkController.store.subscribe((state) => {
this.store.updateState({ NetworkController: state })
})
+ this.infuraController.store.subscribe((state) => {
+ this.store.updateState({ InfuraController: state })
+ })
// manual mem state subscriptions
this.networkController.store.subscribe(this.sendUpdate.bind(this))
@@ -160,6 +171,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.currencyController.store.subscribe(this.sendUpdate.bind(this))
this.noticeController.memStore.subscribe(this.sendUpdate.bind(this))
this.shapeshiftController.store.subscribe(this.sendUpdate.bind(this))
+ this.infuraController.store.subscribe(this.sendUpdate.bind(this))
}
//
@@ -237,6 +249,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.addressBookController.store.getState(),
this.currencyController.store.getState(),
this.noticeController.memStore.getState(),
+ this.infuraController.store.getState(),
// config manager
this.configManager.getConfig(),
this.shapeshiftController.store.getState(),