From 95adbc245c1d00125e6c8a54788d1374503e296d Mon Sep 17 00:00:00 2001 From: David Walsh Date: Tue, 19 Jul 2022 11:13:45 -0500 Subject: [PATCH] Set default getFetchWithTimeout default timeout value (#14218) --- app/scripts/controllers/incoming-transactions.js | 3 +-- app/scripts/controllers/network/network.js | 3 +-- app/scripts/lib/buy-url.js | 3 +-- app/scripts/lib/ens-ipfs/setup.js | 3 +-- app/scripts/lib/network-store.js | 3 +-- shared/modules/fetch-with-timeout.js | 3 ++- shared/modules/fetch-with-timeout.test.js | 8 +------- shared/modules/rpc.utils.js | 3 +-- ui/helpers/utils/i18n-helper.js | 3 +-- 9 files changed, 10 insertions(+), 22 deletions(-) diff --git a/app/scripts/controllers/incoming-transactions.js b/app/scripts/controllers/incoming-transactions.js index c56509314..9577632c5 100644 --- a/app/scripts/controllers/incoming-transactions.js +++ b/app/scripts/controllers/incoming-transactions.js @@ -18,9 +18,8 @@ import { RINKEBY_CHAIN_ID, ROPSTEN_CHAIN_ID, } 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 diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js index 3437398f5..2969041aa 100644 --- a/app/scripts/controllers/network/network.js +++ b/app/scripts/controllers/network/network.js @@ -20,7 +20,6 @@ import { INFURA_BLOCKED_KEY, TEST_NETWORK_TICKER_MAP, } from '../../../../shared/constants/network'; -import { SECOND } from '../../../../shared/constants/time'; import { isPrefixedFormattedHexString, isSafeChainId, @@ -31,7 +30,7 @@ import createInfuraClient from './createInfuraClient'; import createJsonRpcClient from './createJsonRpcClient'; const env = process.env.METAMASK_ENV; -const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); +const fetchWithTimeout = getFetchWithTimeout(); let defaultProviderConfigOpts; if (process.env.IN_TEST) { diff --git a/app/scripts/lib/buy-url.js b/app/scripts/lib/buy-url.js index eed5ff82d..eb8e22cf4 100644 --- a/app/scripts/lib/buy-url.js +++ b/app/scripts/lib/buy-url.js @@ -9,7 +9,6 @@ import { ROPSTEN_CHAIN_ID, BUYABLE_CHAINS_MAP, } from '../../../shared/constants/network'; -import { SECOND } from '../../../shared/constants/time'; import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout'; import { TRANSAK_API_KEY, @@ -17,7 +16,7 @@ import { COINBASEPAY_API_KEY, } from '../constants/on-ramp'; -const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); +const fetchWithTimeout = getFetchWithTimeout(); /** * Create a Wyre purchase URL. diff --git a/app/scripts/lib/ens-ipfs/setup.js b/app/scripts/lib/ens-ipfs/setup.js index 2d19811c3..942b888cc 100644 --- a/app/scripts/lib/ens-ipfs/setup.js +++ b/app/scripts/lib/ens-ipfs/setup.js @@ -2,11 +2,10 @@ import base32Encode from 'base32-encode'; import base64 from 'base64-js'; import browser from 'webextension-polyfill'; -import { SECOND } from '../../../../shared/constants/time'; import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout'; import resolveEnsToIpfsContentId from './resolver'; -const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); +const fetchWithTimeout = getFetchWithTimeout(); const supportedTopLevelDomains = ['eth']; diff --git a/app/scripts/lib/network-store.js b/app/scripts/lib/network-store.js index ca5f4c843..f4e5997bf 100644 --- a/app/scripts/lib/network-store.js +++ b/app/scripts/lib/network-store.js @@ -1,8 +1,7 @@ import log from 'loglevel'; -import { SECOND } from '../../../shared/constants/time'; import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout'; -const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); +const fetchWithTimeout = getFetchWithTimeout(); const FIXTURE_SERVER_HOST = 'localhost'; const FIXTURE_SERVER_PORT = 12345; diff --git a/shared/modules/fetch-with-timeout.js b/shared/modules/fetch-with-timeout.js index b12e8cba5..791470d77 100644 --- a/shared/modules/fetch-with-timeout.js +++ b/shared/modules/fetch-with-timeout.js @@ -1,6 +1,7 @@ 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) { throw new Error('Must specify positive integer timeout.'); } diff --git a/shared/modules/fetch-with-timeout.test.js b/shared/modules/fetch-with-timeout.test.js index 8d7ae5785..2129db1c3 100644 --- a/shared/modules/fetch-with-timeout.test.js +++ b/shared/modules/fetch-with-timeout.test.js @@ -6,7 +6,7 @@ describe('getFetchWithTimeout', () => { it('fetches a url', async () => { nock('https://api.infura.io').get('/money').reply(200, '{"hodl": false}'); - const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); + const fetchWithTimeout = getFetchWithTimeout(); const response = await ( await fetchWithTimeout('https://api.infura.io/money') ).json(); @@ -46,15 +46,9 @@ describe('getFetchWithTimeout', () => { }); it('throws on invalid timeout', async () => { - await expect(() => getFetchWithTimeout()).toThrow( - 'Must specify positive integer timeout.', - ); await expect(() => getFetchWithTimeout(-1)).toThrow( 'Must specify positive integer timeout.', ); - await expect(() => getFetchWithTimeout({})).toThrow( - 'Must specify positive integer timeout.', - ); await expect(() => getFetchWithTimeout(true)).toThrow( 'Must specify positive integer timeout.', ); diff --git a/shared/modules/rpc.utils.js b/shared/modules/rpc.utils.js index ab0c006b6..341ef1d97 100644 --- a/shared/modules/rpc.utils.js +++ b/shared/modules/rpc.utils.js @@ -1,7 +1,6 @@ -import { SECOND } from '../constants/time'; 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. diff --git a/ui/helpers/utils/i18n-helper.js b/ui/helpers/utils/i18n-helper.js index f5a2aac22..c18e7df83 100644 --- a/ui/helpers/utils/i18n-helper.js +++ b/ui/helpers/utils/i18n-helper.js @@ -3,10 +3,9 @@ import React from 'react'; import log from 'loglevel'; import * as Sentry from '@sentry/browser'; -import { SECOND } from '../../../shared/constants/time'; import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout'; -const fetchWithTimeout = getFetchWithTimeout(SECOND * 30); +const fetchWithTimeout = getFetchWithTimeout(); const warned = {}; const missingMessageErrors = {};