diff options
author | Kevin Serrano <kevin.serrano@consensys.net> | 2017-06-23 03:32:08 +0800 |
---|---|---|
committer | Kevin Serrano <kevin.serrano@consensys.net> | 2017-06-23 03:32:08 +0800 |
commit | b7f8657ab5c01c70eff3e19afd334f07b6415c34 (patch) | |
tree | 84dc7e39c984e5cfe42a63ed798df37fdf3c1876 /app/scripts/controllers | |
parent | 2a429253994a0df2aae27234a7ac11c870bdc713 (diff) | |
download | tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar.gz tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar.bz2 tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar.lz tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar.xz tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.tar.zst tangerine-wallet-browser-b7f8657ab5c01c70eff3e19afd334f07b6415c34.zip |
Add infura network status to our 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..e0dad0bc1 --- /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 |