aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-13 18:42:01 +0800
committerFabio Berger <me@fabioberger.com>2018-07-13 18:42:01 +0800
commit2e5ff53d7271509accc226e83d76d1785350b1d2 (patch)
tree020bbe96131fcd173d7902b4c86e2b4141183f30 /packages/utils/src
parent1229c61ba420b280708b39c04cc21f31e43ed3cf (diff)
downloaddexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar.gz
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar.bz2
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar.lz
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar.xz
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.tar.zst
dexon-sol-tools-2e5ff53d7271509accc226e83d76d1785350b1d2.zip
-fetch';
Diffstat (limited to 'packages/utils/src')
-rw-r--r--packages/utils/src/fetchAsync.ts16
-rw-r--r--packages/utils/src/index.ts1
2 files changed, 9 insertions, 8 deletions
diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetchAsync.ts
index 7cb2c1759..a009f0c86 100644
--- a/packages/utils/src/fetchAsync.ts
+++ b/packages/utils/src/fetchAsync.ts
@@ -1,29 +1,31 @@
-import { FetchRequest } from '@0xproject/types';
import 'isomorphic-fetch';
export const fetchAsync = async (
endpoint: string,
- options: FetchRequest,
+ options: RequestInit = {},
timeoutMs: number = 20000,
): Promise<Response> => {
- let finalOptions;
+ let optionsWithAbortParam;
if ((process as any).browser === true) {
const controller = new AbortController();
const signal = controller.signal;
setTimeout(() => {
controller.abort();
}, timeoutMs);
- finalOptions = {
+ optionsWithAbortParam = {
signal,
...options,
};
} else {
- finalOptions = {
+ // HACK: the `timeout` param only exists in `node-fetch`, and not on the `isomorphic-fetch`
+ // `RequestInit` type. Since `isomorphic-fetch` conditionally wraps `node-fetch` when the
+ // execution environment is `Node.js`, we need to cast it to `any` in that scenario.
+ optionsWithAbortParam = {
timeout: timeoutMs,
...options,
- };
+ } as any;
}
- const response = await fetch(endpoint, finalOptions);
+ const response = await fetch(endpoint, optionsWithAbortParam);
return response;
};
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index 48fd6152e..b8e0b1775 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -9,4 +9,3 @@ export { abiUtils } from './abi_utils';
export { NULL_BYTES } from './constants';
export { errorUtils } from './error_utils';
export { fetchAsync } from './fetchAsync';
-export { FetchRequest } from '@0xproject/types';