Skip to content

Commit

Permalink
Use the correct fetch for ServiceWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
Coac committed Jan 14, 2018
1 parent d2013f0 commit 5f8ec94
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

//-----------------------------------------------------------------------------

const isNode = (typeof window === 'undefined')
const isNode = (typeof window === 'undefined') && !(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
, functions = require ('./functions')
, throttle = require ('./throttle')
, fetch = require ('fetch-ponyfill')().fetch
, fetchImplementation = isNode ? require ('fetch-ponyfill')().fetch : fetch
, Market = require ('./Market')

const { deepExtend
Expand Down Expand Up @@ -93,8 +93,6 @@ module.exports = class Exchange {
this.substituteCommonCurrencyCodes = true // reserved
this.parseBalanceFromOpenOrders = false // some exchanges return balance updates from order API endpoints

this.fetchImplementation = fetch

this.timeout = 10000 // milliseconds
this.verbose = false
this.debug = false
Expand Down Expand Up @@ -280,7 +278,7 @@ module.exports = class Exchange {
this.executeRestRequest = function (url, method = 'GET', headers = undefined, body = undefined) {

let promise =
this.fetchImplementation (url, { 'method': method, 'headers': headers, 'body': body, 'agent': this.tunnelAgent || null, timeout: this.timeout})
fetchImplementation (url, { 'method': method, 'headers': headers, 'body': body, 'agent': this.tunnelAgent || null, timeout: this.timeout})
.catch (e => {
if (isNode)
throw new ExchangeNotAvailable ([ this.id, method, url, e.type, e.message ].join (' '))
Expand Down

0 comments on commit 5f8ec94

Please sign in to comment.