diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2017-06-27 03:06:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-27 03:06:23 +0800 |
commit | 8b5b2d832995ca4b928c47abebd7e5476ac71e6a (patch) | |
tree | e008ea15657ec0019caa119c6af6ef6e0b1f4fad /app/scripts/controllers | |
parent | 27a0694d8519b302a14080f5b72ddf1c73e0d9a7 (diff) | |
parent | 42a2bcb1325bd5763a6402d5c2d6634053da908b (diff) | |
download | tangerine-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/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/infura.js | 42 |
1 files changed, 42 insertions, 0 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 |