mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Set default getFetchWithTimeout default timeout value (#14218)
This commit is contained in:
parent
7d321c48e0
commit
95adbc245c
@ -18,9 +18,8 @@ import {
|
|||||||
RINKEBY_CHAIN_ID,
|
RINKEBY_CHAIN_ID,
|
||||||
ROPSTEN_CHAIN_ID,
|
ROPSTEN_CHAIN_ID,
|
||||||
} from '../../../shared/constants/network';
|
} from '../../../shared/constants/network';
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('../../../shared/constants/transaction').TransactionMeta} TransactionMeta
|
* @typedef {import('../../../shared/constants/transaction').TransactionMeta} TransactionMeta
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
INFURA_BLOCKED_KEY,
|
INFURA_BLOCKED_KEY,
|
||||||
TEST_NETWORK_TICKER_MAP,
|
TEST_NETWORK_TICKER_MAP,
|
||||||
} from '../../../../shared/constants/network';
|
} from '../../../../shared/constants/network';
|
||||||
import { SECOND } from '../../../../shared/constants/time';
|
|
||||||
import {
|
import {
|
||||||
isPrefixedFormattedHexString,
|
isPrefixedFormattedHexString,
|
||||||
isSafeChainId,
|
isSafeChainId,
|
||||||
@ -31,7 +30,7 @@ import createInfuraClient from './createInfuraClient';
|
|||||||
import createJsonRpcClient from './createJsonRpcClient';
|
import createJsonRpcClient from './createJsonRpcClient';
|
||||||
|
|
||||||
const env = process.env.METAMASK_ENV;
|
const env = process.env.METAMASK_ENV;
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
let defaultProviderConfigOpts;
|
let defaultProviderConfigOpts;
|
||||||
if (process.env.IN_TEST) {
|
if (process.env.IN_TEST) {
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
ROPSTEN_CHAIN_ID,
|
ROPSTEN_CHAIN_ID,
|
||||||
BUYABLE_CHAINS_MAP,
|
BUYABLE_CHAINS_MAP,
|
||||||
} from '../../../shared/constants/network';
|
} from '../../../shared/constants/network';
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
|
||||||
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
||||||
import {
|
import {
|
||||||
TRANSAK_API_KEY,
|
TRANSAK_API_KEY,
|
||||||
@ -17,7 +16,7 @@ import {
|
|||||||
COINBASEPAY_API_KEY,
|
COINBASEPAY_API_KEY,
|
||||||
} from '../constants/on-ramp';
|
} from '../constants/on-ramp';
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Wyre purchase URL.
|
* Create a Wyre purchase URL.
|
||||||
|
@ -2,11 +2,10 @@ import base32Encode from 'base32-encode';
|
|||||||
import base64 from 'base64-js';
|
import base64 from 'base64-js';
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
|
|
||||||
import { SECOND } from '../../../../shared/constants/time';
|
|
||||||
import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout';
|
import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout';
|
||||||
import resolveEnsToIpfsContentId from './resolver';
|
import resolveEnsToIpfsContentId from './resolver';
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
const supportedTopLevelDomains = ['eth'];
|
const supportedTopLevelDomains = ['eth'];
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
|
||||||
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
const FIXTURE_SERVER_HOST = 'localhost';
|
const FIXTURE_SERVER_HOST = 'localhost';
|
||||||
const FIXTURE_SERVER_PORT = 12345;
|
const FIXTURE_SERVER_PORT = 12345;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { memoize } from 'lodash';
|
import { memoize } from 'lodash';
|
||||||
|
import { SECOND } from '../constants/time';
|
||||||
|
|
||||||
const getFetchWithTimeout = memoize((timeout) => {
|
const getFetchWithTimeout = memoize((timeout = SECOND * 30) => {
|
||||||
if (!Number.isInteger(timeout) || timeout < 1) {
|
if (!Number.isInteger(timeout) || timeout < 1) {
|
||||||
throw new Error('Must specify positive integer timeout.');
|
throw new Error('Must specify positive integer timeout.');
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ describe('getFetchWithTimeout', () => {
|
|||||||
it('fetches a url', async () => {
|
it('fetches a url', async () => {
|
||||||
nock('https://api.infura.io').get('/money').reply(200, '{"hodl": false}');
|
nock('https://api.infura.io').get('/money').reply(200, '{"hodl": false}');
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
const response = await (
|
const response = await (
|
||||||
await fetchWithTimeout('https://api.infura.io/money')
|
await fetchWithTimeout('https://api.infura.io/money')
|
||||||
).json();
|
).json();
|
||||||
@ -46,15 +46,9 @@ describe('getFetchWithTimeout', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws on invalid timeout', async () => {
|
it('throws on invalid timeout', async () => {
|
||||||
await expect(() => getFetchWithTimeout()).toThrow(
|
|
||||||
'Must specify positive integer timeout.',
|
|
||||||
);
|
|
||||||
await expect(() => getFetchWithTimeout(-1)).toThrow(
|
await expect(() => getFetchWithTimeout(-1)).toThrow(
|
||||||
'Must specify positive integer timeout.',
|
'Must specify positive integer timeout.',
|
||||||
);
|
);
|
||||||
await expect(() => getFetchWithTimeout({})).toThrow(
|
|
||||||
'Must specify positive integer timeout.',
|
|
||||||
);
|
|
||||||
await expect(() => getFetchWithTimeout(true)).toThrow(
|
await expect(() => getFetchWithTimeout(true)).toThrow(
|
||||||
'Must specify positive integer timeout.',
|
'Must specify positive integer timeout.',
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { SECOND } from '../constants/time';
|
|
||||||
import getFetchWithTimeout from './fetch-with-timeout';
|
import getFetchWithTimeout from './fetch-with-timeout';
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a JSON RPC request to the given URL, with the given RPC method and params.
|
* Makes a JSON RPC request to the given URL, with the given RPC method and params.
|
||||||
|
@ -3,10 +3,9 @@ import React from 'react';
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import * as Sentry from '@sentry/browser';
|
import * as Sentry from '@sentry/browser';
|
||||||
|
|
||||||
import { SECOND } from '../../../shared/constants/time';
|
|
||||||
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
|
||||||
|
|
||||||
const fetchWithTimeout = getFetchWithTimeout(SECOND * 30);
|
const fetchWithTimeout = getFetchWithTimeout();
|
||||||
|
|
||||||
const warned = {};
|
const warned = {};
|
||||||
const missingMessageErrors = {};
|
const missingMessageErrors = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user