From 38876dc4505fc70081b7bf9448498a996df4443d Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Wed, 6 Sep 2023 15:02:22 +0100 Subject: [PATCH 01/59] fix(20316): enrich error message for fetch-with-cache (#20742) --- app/scripts/controllers/swaps.js | 11 +-- shared/lib/fetch-with-cache.test.js | 78 +++++++++++-------- ...etch-with-cache.js => fetch-with-cache.ts} | 14 +++- shared/lib/swaps-utils.js | 11 +-- .../transaction-decoding.component.js | 12 ++- .../ui/new-network-info/new-network-info.js | 7 +- .../new-network-info/new-network-info.test.js | 50 ++++++------ ui/helpers/utils/transactions.util.js | 9 ++- .../templates/add-ethereum-chain.js | 5 +- .../networks-form/networks-form.js | 5 +- ui/pages/swaps/swaps.util.ts | 77 +++++++++--------- 11 files changed, 164 insertions(+), 115 deletions(-) rename shared/lib/{fetch-with-cache.js => fetch-with-cache.ts} (80%) diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index 2d35c97f1327..1e9fe2c44eb6 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -172,11 +172,12 @@ export default class SwapsController { } async fetchSwapsNetworkConfig(chainId) { - const response = await fetchWithCache( - getBaseApi('network', chainId), - { method: 'GET' }, - { cacheRefreshTime: 600000 }, - ); + const response = await fetchWithCache({ + url: getBaseApi('network', chainId), + fetchOptions: { method: 'GET' }, + cacheOptions: { cacheRefreshTime: 600000 }, + functionName: 'fetchSwapsNetworkConfig', + }); const { refreshRates, parameters = {} } = response || {}; if ( !refreshRates || diff --git a/shared/lib/fetch-with-cache.test.js b/shared/lib/fetch-with-cache.test.js index 0b6f3f933d01..17285aaa12bf 100644 --- a/shared/lib/fetch-with-cache.test.js +++ b/shared/lib/fetch-with-cache.test.js @@ -21,9 +21,11 @@ describe('Fetch with cache', () => { .get('/price') .reply(200, '{"average": 1}'); - const response = await fetchWithCache( - 'https://fetchwithcache.metamask.io/price', - ); + const response = await fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + functionName: 'fetchPrice', + }); + expect(response).toStrictEqual({ average: 1, }); @@ -39,9 +41,10 @@ describe('Fetch with cache', () => { cachedTime: Date.now(), }); - const response = await fetchWithCache( - 'https://fetchwithcache.metamask.io/price', - ); + const response = await fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + functionName: 'fetchPrice', + }); expect(response).toStrictEqual({ average: 1, }); @@ -57,11 +60,11 @@ describe('Fetch with cache', () => { cachedTime: Date.now() - 1000, }); - const response = await fetchWithCache( - 'https://fetchwithcache.metamask.io/price', - {}, - { cacheRefreshTime: 123 }, - ); + const response = await fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + cacheOptions: { cacheRefreshTime: 123 }, + functionName: 'fetchPrice', + }); expect(response).toStrictEqual({ average: 3, }); @@ -74,11 +77,11 @@ describe('Fetch with cache', () => { .reply(200, '{"average": 4}'); await expect(() => - fetchWithCache( - 'https://fetchwithcache.metamask.io/price', - {}, - { timeout: 20 }, - ), + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + cacheOptions: { timeout: 20 }, + functionName: 'fetchPrice', + }), ).rejects.toThrow({ name: 'AbortError', message: 'The user aborted a request.', @@ -91,7 +94,10 @@ describe('Fetch with cache', () => { .reply(500, '{"average": 6}'); await expect(() => - fetchWithCache('https://fetchwithcache.metamask.io/price'), + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + functionName: 'fetchPrice', + }), ).rejects.toThrow(''); }); @@ -101,8 +107,10 @@ describe('Fetch with cache', () => { .reply(200, '{"average": 7}'); await expect(() => - fetchWithCache('https://fetchwithcache.metamask.io/price', { - method: 'POST', + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + fetchOptions: { method: 'POST' }, + functionName: 'fetchPrice', }), ).rejects.toThrow(''); }); @@ -113,7 +121,11 @@ describe('Fetch with cache', () => { .reply(200, '{"average": 8}'); await expect(() => - fetchWithCache('https://fetchwithcache.metamask.io/price', { body: 1 }), + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + fetchOptions: { body: 1 }, + functionName: 'fetchPrice', + }), ).rejects.toThrow(''); }); @@ -123,8 +135,10 @@ describe('Fetch with cache', () => { .reply(200, '{"average": 9}'); await expect(() => - fetchWithCache('https://fetchwithcache.metamask.io/price', { - headers: { 'Content-Type': 'text/plain' }, + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/price', + fetchOptions: { headers: { 'Content-Type': 'text/plain' } }, + functionName: 'fetchPrice', }), ).rejects.toThrow({ message: 'fetchWithCache only supports JSON responses', @@ -147,16 +161,16 @@ describe('Fetch with cache', () => { }); await Promise.all([ - fetchWithCache( - 'https://fetchwithcache.metamask.io/foo', - {}, - { cacheRefreshTime: 123 }, - ), - fetchWithCache( - 'https://fetchwithcache.metamask.io/bar', - {}, - { cacheRefreshTime: 123 }, - ), + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/foo', + cacheOptions: { cacheRefreshTime: 123 }, + functionName: 'fetchFoo', + }), + fetchWithCache({ + url: 'https://fetchwithcache.metamask.io/bar', + cacheOptions: { cacheRefreshTime: 123 }, + functionName: 'fetchFoo', + }), ]); expect( diff --git a/shared/lib/fetch-with-cache.js b/shared/lib/fetch-with-cache.ts similarity index 80% rename from shared/lib/fetch-with-cache.js rename to shared/lib/fetch-with-cache.ts index a92f4fb2e8b2..8a84ad76f8c4 100644 --- a/shared/lib/fetch-with-cache.js +++ b/shared/lib/fetch-with-cache.ts @@ -2,11 +2,17 @@ import { MINUTE, SECOND } from '../constants/time'; import getFetchWithTimeout from '../modules/fetch-with-timeout'; import { getStorageItem, setStorageItem } from './storage-helpers'; -const fetchWithCache = async ( +const fetchWithCache = async ({ url, fetchOptions = {}, - { cacheRefreshTime = MINUTE * 6, timeout = SECOND * 30 } = {}, -) => { + cacheOptions: { cacheRefreshTime = MINUTE * 6, timeout = SECOND * 30 } = {}, + functionName = '', +}: { + url: string; + fetchOptions?: Record; + cacheOptions?: Record; + functionName: string; +}) => { if ( fetchOptions.body || (fetchOptions.method && fetchOptions.method !== 'GET') @@ -40,7 +46,7 @@ const fetchWithCache = async ( }); if (!response.ok) { throw new Error( - `Fetch failed with status '${response.status}': '${response.statusText}'`, + `Fetch with cache failed within function ${functionName} with status'${response.status}': '${response.statusText}'`, ); } const responseJson = await response.json(); diff --git a/shared/lib/swaps-utils.js b/shared/lib/swaps-utils.js index c58557bca748..1d48bf5d479e 100644 --- a/shared/lib/swaps-utils.js +++ b/shared/lib/swaps-utils.js @@ -274,11 +274,12 @@ export async function fetchTradesInfo( const queryString = new URLSearchParams(urlParams).toString(); const tradeURL = `${getBaseApi('trade', chainId)}${queryString}`; - const tradesResponse = await fetchWithCache( - tradeURL, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: 0, timeout: SECOND * 15 }, - ); + const tradesResponse = await fetchWithCache({ + url: tradeURL, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: 0, timeout: SECOND * 15 }, + functionName: 'fetchTradesInfo', + }); const newQuotes = tradesResponse.reduce((aggIdTradeMap, quote) => { if ( quote.trade && diff --git a/ui/components/app/transaction-decoding/transaction-decoding.component.js b/ui/components/app/transaction-decoding/transaction-decoding.component.js index f68dd6a77ba3..dc96dd1425ab 100644 --- a/ui/components/app/transaction-decoding/transaction-decoding.component.js +++ b/ui/components/app/transaction-decoding/transaction-decoding.component.js @@ -38,8 +38,10 @@ export default function TransactionDecoding({ to = '', inputData: data = '' }) { (async () => { setLoading(true); try { - const networks = await fetchWithCache(FETCH_SUPPORTED_NETWORKS_URI, { - method: 'GET', + const networks = await fetchWithCache({ + url: FETCH_SUPPORTED_NETWORKS_URI, + fetchOptions: { method: 'GET' }, + functionName: 'fetchSupportedNetworks', }); if ( @@ -57,7 +59,11 @@ export default function TransactionDecoding({ to = '', inputData: data = '' }) { 'network-id': network, })}`; - const response = await fetchWithCache(requestUrl, { method: 'GET' }); + const response = await fetchWithCache({ + url: requestUrl, + fetchOptions: { method: 'GET' }, + functionName: 'fetchProject', + }); const { info: projectInfo, fetchedVia, address } = response; diff --git a/ui/components/ui/new-network-info/new-network-info.js b/ui/components/ui/new-network-info/new-network-info.js index 0d449c443855..e67fad5d2b90 100644 --- a/ui/components/ui/new-network-info/new-network-info.js +++ b/ui/components/ui/new-network-info/new-network-info.js @@ -49,9 +49,10 @@ const NewNetworkInfo = () => { }; const getIsTokenDetectionSupported = async () => { - const fetchedTokenData = await fetchWithCache( - `${TOKEN_API_METASWAP_CODEFI_URL}${providerConfig.chainId}`, - ); + const fetchedTokenData = await fetchWithCache({ + url: `${TOKEN_API_METASWAP_CODEFI_URL}${providerConfig.chainId}`, + functionName: 'getIsTokenDetectionSupported', + }); return !fetchedTokenData.error; }; diff --git a/ui/components/ui/new-network-info/new-network-info.test.js b/ui/components/ui/new-network-info/new-network-info.test.js index fc80c757380a..0f4f52c628a6 100644 --- a/ui/components/ui/new-network-info/new-network-info.test.js +++ b/ui/components/ui/new-network-info/new-network-info.test.js @@ -33,9 +33,10 @@ describe('NewNetworkInfo', () => { '[{"address":"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f","symbol":"SNX","decimals":18,"name":"Synthetix Network Token","iconUrl":"https://assets.coingecko.com/coins/images/3406/large/SNX.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","synthetix","zapper","zerion","zeroEx"],"occurrences":12},{"address":"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984","symbol":"UNI","decimals":18,"name":"Uniswap","iconUrl":"https://images.prismic.io/token-price-prod/d0352dd9-5de8-4633-839d-bc3422c44d9c_UNI%404x.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","zapper","zerion","zeroEx"],"occurrences":11}]', ); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x1', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x1', + functionName: 'getTokenDetectionSupportStatus', + }); const store = configureMockStore()( state, @@ -54,9 +55,10 @@ describe('NewNetworkInfo', () => { '[{"address":"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f","symbol":"SNX","decimals":18,"name":"Synthetix Network Token","iconUrl":"https://assets.coingecko.com/coins/images/3406/large/SNX.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","synthetix","zapper","zerion","zeroEx"],"occurrences":12},{"address":"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984","symbol":"UNI","decimals":18,"name":"Uniswap","iconUrl":"https://images.prismic.io/token-price-prod/d0352dd9-5de8-4633-839d-bc3422c44d9c_UNI%404x.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","zapper","zerion","zeroEx"],"occurrences":11}]', ); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x1', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x1', + functionName: 'getTokenDetectionSupportStatus', + }); state.metamask.nativeCurrency = ''; @@ -77,10 +79,10 @@ describe('NewNetworkInfo', () => { 200, '[{"address":"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f","symbol":"SNX","decimals":18,"name":"Synthetix Network Token","iconUrl":"https://assets.coingecko.com/coins/images/3406/large/SNX.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","synthetix","zapper","zerion","zeroEx"],"occurrences":12},{"address":"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984","symbol":"UNI","decimals":18,"name":"Uniswap","iconUrl":"https://images.prismic.io/token-price-prod/d0352dd9-5de8-4633-839d-bc3422c44d9c_UNI%404x.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","zapper","zerion","zeroEx"],"occurrences":11}]', ); - - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x1', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x1', + functionName: 'getTokenDetectionSupportStatus', + }); const store = configureMockStore()( state, @@ -99,9 +101,10 @@ describe('NewNetworkInfo', () => { '[{"address":"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f","symbol":"SNX","decimals":18,"name":"Synthetix Network Token","iconUrl":"https://assets.coingecko.com/coins/images/3406/large/SNX.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","synthetix","zapper","zerion","zeroEx"],"occurrences":12},{"address":"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984","symbol":"UNI","decimals":18,"name":"Uniswap","iconUrl":"https://images.prismic.io/token-price-prod/d0352dd9-5de8-4633-839d-bc3422c44d9c_UNI%404x.png","aggregators":["aave","bancor","cmc","cryptocom","coinGecko","oneInch","paraswap","pmm","zapper","zerion","zeroEx"],"occurrences":11}]', ); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x1', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x1', + functionName: 'getTokenDetectionSupportStatus', + }); const store = configureMockStore()( state, @@ -117,9 +120,10 @@ describe('NewNetworkInfo', () => { .get('/tokens/0x3') .reply(200, '{"error":"ChainId 0x3 is not supported"}'); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x3', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x3', + functionName: 'getTokenDetectionSupportStatus', + }); const store = configureMockStore()( state, @@ -135,9 +139,10 @@ describe('NewNetworkInfo', () => { .get('/tokens/0x3') .reply(200, '{"error":"ChainId 0x3 is not supported"}'); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x3', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x3', + functionName: 'getTokenDetectionSupportStatus', + }); state.metamask.providerConfig.ticker = null; @@ -156,9 +161,10 @@ describe('NewNetworkInfo', () => { .get('/tokens/0x3') .reply(200, '{"error":"ChainId 0x3 is not supported"}'); - const updateTokenDetectionSupportStatus = await fetchWithCache( - 'https://token-api.metaswap.codefi.network/tokens/0x3', - ); + const updateTokenDetectionSupportStatus = await fetchWithCache({ + url: 'https://token-api.metaswap.codefi.network/tokens/0x3', + functionName: 'getTokenDetectionSupportStatus', + }); const store = configureMockStore()( state, diff --git a/ui/helpers/utils/transactions.util.js b/ui/helpers/utils/transactions.util.js index cb9d98fe9596..8438fceccf1e 100644 --- a/ui/helpers/utils/transactions.util.js +++ b/ui/helpers/utils/transactions.util.js @@ -26,15 +26,16 @@ import fetchWithCache from '../../../shared/lib/fetch-with-cache'; */ async function getMethodFrom4Byte(fourBytePrefix) { - const fourByteResponse = await fetchWithCache( - `https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, - { + const fourByteResponse = await fetchWithCache({ + url: `https://www.4byte.directory/api/v1/signatures/?hex_signature=${fourBytePrefix}`, + fetchOptions: { referrerPolicy: 'no-referrer-when-downgrade', body: null, method: 'GET', mode: 'cors', }, - ); + functionName: 'getMethodFrom4Byte', + }); fourByteResponse.results.sort((a, b) => { return new Date(a.created_at).getTime() < new Date(b.created_at).getTime() ? -1 diff --git a/ui/pages/confirmation/templates/add-ethereum-chain.js b/ui/pages/confirmation/templates/add-ethereum-chain.js index 6bf2d3cd9d98..ccc5d66e12e1 100644 --- a/ui/pages/confirmation/templates/add-ethereum-chain.js +++ b/ui/pages/confirmation/templates/add-ethereum-chain.js @@ -134,7 +134,10 @@ const ERROR_CONNECTING_TO_RPC = { async function getAlerts(pendingApproval) { const alerts = []; const safeChainsList = - (await fetchWithCache('https://chainid.network/chains.json')) || []; + (await fetchWithCache({ + url: 'https://chainid.network/chains.json', + functionName: 'getSafeChainsList', + })) || []; const matchedChain = safeChainsList.find( (chain) => chain.chainId === parseInt(pendingApproval.requestData.chainId, 16), diff --git a/ui/pages/settings/networks-tab/networks-form/networks-form.js b/ui/pages/settings/networks-tab/networks-form/networks-form.js index 9d9a2e1ee3fa..b885e21f0279 100644 --- a/ui/pages/settings/networks-tab/networks-form/networks-form.js +++ b/ui/pages/settings/networks-tab/networks-form/networks-form.js @@ -356,7 +356,10 @@ const NetworksForm = ({ try { safeChainsList = - (await fetchWithCache('https://chainid.network/chains.json')) || []; + (await fetchWithCache({ + url: 'https://chainid.network/chains.json', + functionName: 'getSafeChainsList', + })) || []; } catch (err) { log.warn('Failed to fetch the chainList from chainid.network', err); providerError = err; diff --git a/ui/pages/swaps/swaps.util.ts b/ui/pages/swaps/swaps.util.ts index 7782f0df8512..72add871a960 100644 --- a/ui/pages/swaps/swaps.util.ts +++ b/ui/pages/swaps/swaps.util.ts @@ -117,11 +117,12 @@ export async function fetchToken( chainId: any, ): Promise { const tokenUrl = getBaseApi('token', chainId); - return await fetchWithCache( - `${tokenUrl}?address=${contractAddress}`, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, - ); + return await fetchWithCache({ + url: `${tokenUrl}?address=${contractAddress}`, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, + functionName: 'fetchToken', + }); } type Token = { symbol: string; address: string }; @@ -129,11 +130,12 @@ export async function fetchTokens( chainId: keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP, ): Promise { const tokensUrl = getBaseApi('tokens', chainId); - const tokens = await fetchWithCache( - tokensUrl, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, - ); + const tokens = await fetchWithCache({ + url: tokensUrl, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, + functionName: 'fetchTokens', + }); const logError = false; const tokenObject = SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId] || null; return [ @@ -152,11 +154,12 @@ export async function fetchTokens( export async function fetchAggregatorMetadata(chainId: any): Promise { const aggregatorMetadataUrl = getBaseApi('aggregatorMetadata', chainId); - const aggregators = await fetchWithCache( - aggregatorMetadataUrl, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, - ); + const aggregators = await fetchWithCache({ + url: aggregatorMetadataUrl, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, + functionName: 'fetchAggregatorMetadata', + }); const filteredAggregators = {} as any; for (const aggKey in aggregators) { if ( @@ -175,11 +178,12 @@ export async function fetchAggregatorMetadata(chainId: any): Promise { export async function fetchTopAssets(chainId: any): Promise { const topAssetsUrl = getBaseApi('topAssets', chainId); const response = - (await fetchWithCache( - topAssetsUrl, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, - )) || []; + (await fetchWithCache({ + url: topAssetsUrl, + functionName: 'fetchTopAssets', + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES }, + })) || []; const topAssetsMap = response.reduce( (_topAssetsMap: any, asset: { address: string }, index: number) => { if (validateData(TOP_ASSET_VALIDATORS, asset, topAssetsUrl)) { @@ -196,21 +200,23 @@ export async function fetchSwapsFeatureFlags(): Promise { const v2ApiBaseUrl = process.env.SWAPS_USE_DEV_APIS ? SWAPS_DEV_API_V2_BASE_URL : SWAPS_API_V2_BASE_URL; - return await fetchWithCache( - `${v2ApiBaseUrl}/featureFlags`, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: 600000 }, - ); + return await fetchWithCache({ + url: `${v2ApiBaseUrl}/featureFlags`, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: 600000 }, + functionName: 'fetchSwapsFeatureFlags', + }); } export async function fetchTokenPrice(address: string): Promise { const query = `contract_addresses=${address}&vs_currencies=eth`; - const prices = await fetchWithCache( - `https://api.coingecko.com/api/v3/simple/token_price/ethereum?${query}`, - { method: 'GET' }, - { cacheRefreshTime: 60000 }, - ); + const prices = await fetchWithCache({ + url: `https://api.coingecko.com/api/v3/simple/token_price/ethereum?${query}`, + fetchOptions: { method: 'GET' }, + cacheOptions: { cacheRefreshTime: 60000 }, + functionName: 'fetchTokenPrice', + }); return prices?.[address]?.eth; } @@ -223,11 +229,12 @@ export async function fetchSwapsGasPrices(chainId: any): Promise< } > { const gasPricesUrl = getBaseApi('gasPrices', chainId); - const response = await fetchWithCache( - gasPricesUrl, - { method: 'GET', headers: clientIdHeader }, - { cacheRefreshTime: 30000 }, - ); + const response = await fetchWithCache({ + url: gasPricesUrl, + fetchOptions: { method: 'GET', headers: clientIdHeader }, + cacheOptions: { cacheRefreshTime: 30000 }, + functionName: 'fetchSwapsGasPrices', + }); const responseIsValid = validateData( SWAP_GAS_PRICE_VALIDATOR, response, From 6c5f24aa66ab26539a44b56497eb8adc38bbe9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Oliv=C3=A9?= Date: Wed, 6 Sep 2023 16:18:07 +0200 Subject: [PATCH 02/59] =?UTF-8?q?[MMI]=C2=A0Added=20code=20fences=20to=20h?= =?UTF-8?q?ide=20emojis=20just=20for=20MMI=20build=20(#20754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added code fences to hide emojis just for MMI build * Added missing code fences * Added missing code fences --- .../edit-gas-fee-button.js | 23 ++++++++--- .../edit-gas-item/edit-gas-item.js | 40 ++++++++++++++----- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js b/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js index 70fb157e1bf4..7987ae770605 100644 --- a/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js +++ b/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.js @@ -7,7 +7,9 @@ import { TextColor, TextVariant, } from '../../../helpers/constants/design-system'; +///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas'; +///: END:ONLY_INCLUDE_IN import { useGasFeeContext } from '../../../contexts/gasFee'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { useTransactionEventFragment } from '../../../hooks/useTransactionEventFragment'; @@ -35,17 +37,22 @@ export default function EditGasFeeButton({ userAcknowledgedGasMissing }) { if (!supportsEIP1559 || !estimateUsed || !editEnabled) { return null; } - + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) let icon = estimateUsed; + ///: END:ONLY_INCLUDE_IN let title = estimateUsed; if ( estimateUsed === PriorityLevels.high && editGasMode === EditGasModes.swaps ) { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) icon = 'swapSuggested'; + ///: END:ONLY_INCLUDE_IN title = 'swapSuggested'; } else if (estimateUsed === PriorityLevels.tenPercentIncreased) { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) icon = undefined; + ///: END:ONLY_INCLUDE_IN title = 'tenPercentIncreased'; } @@ -66,11 +73,15 @@ export default function EditGasFeeButton({ userAcknowledgedGasMissing }) { return (
+ {shouldInjectMetametricsIframe ? ( +