Skip to content

Commit

Permalink
fix: allow starknet.js in service workers
Browse files Browse the repository at this point in the history
axios (which uses the `XMLHttpRequest` interface) isn't supported in service workers.
instead, we can use `cross-fetch` which supports single js code for node, browser and react-native
  • Loading branch information
avimak committed May 29, 2022
1 parent 4fa8208 commit 7a500d1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 133 deletions.
27 changes: 23 additions & 4 deletions __tests__/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import axios from 'axios';
import * as AxiosLogger from 'axios-logger';
/* eslint-disable no-console */
import { register } from 'fetch-intercept';

jest.setTimeout(50 * 60 * 1000);

if (process.env.DEBUG === 'true') {
axios.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger);
axios.interceptors.response.use(AxiosLogger.responseLogger, AxiosLogger.errorLogger);
register({
request(url, config) {
console.log('[fetch.request]', [url, config]);
return [url, config];
},

requestError(error) {
console.log('[fetch.requestError]', error);
return Promise.reject(error);
},

response(response) {
console.log('[fetch.response]', response);
return response;
},

responseError(error) {
console.log('[fetch.responseError]', error);
return Promise.reject(error);
},
});
}
143 changes: 46 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@types/url-join": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"axios-logger": "^2.6.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^14.0.1",
Expand All @@ -58,14 +57,16 @@
"prettier": "^2.4.1",
"prettier-plugin-import-sort": "^0.0.7",
"typedoc": "^0.22.6",
"typescript": "^4.4.4"
"typescript": "^4.4.4",
"whatwg-fetch": "^3.6.2"
},
"dependencies": {
"@ethersproject/bytes": "^5.6.1",
"axios": "^0.23.0",
"bn.js": "^5.2.0",
"cross-fetch": "^3.1.5",
"elliptic": "^6.5.4",
"ethereum-cryptography": "^0.2.0",
"fetch-intercept": "^2.4.0",
"hash.js": "^1.1.7",
"json-bigint": "^1.0.0",
"minimalistic-assert": "^1.0.1",
Expand Down
Loading

0 comments on commit 7a500d1

Please sign in to comment.