1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 09:23:21 +01:00

Set default getFetchWithTimeout default timeout value (#14218)

This commit is contained in:
David Walsh 2022-07-19 11:13:45 -05:00 committed by GitHub
parent 7d321c48e0
commit 95adbc245c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10 additions and 22 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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.

View File

@ -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'];

View File

@ -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;

View File

@ -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.');
}

View File

@ -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.',
);

View File

@ -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.

View File

@ -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 = {};