mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add client id header for Swaps Apis (#12137)
This commit is contained in:
parent
6b7444c257
commit
3ca6202282
@ -53,6 +53,8 @@ const TOKEN_TRANSFER_LOG_TOPIC_HASH =
|
||||
|
||||
const CACHE_REFRESH_FIVE_MINUTES = 300000;
|
||||
|
||||
const clientIdHeader = { 'X-Client-Id': 'extension' };
|
||||
|
||||
/**
|
||||
* @param {string} type Type of an API call, e.g. "tokens"
|
||||
* @param {string} chainId
|
||||
@ -316,7 +318,7 @@ export async function fetchTradesInfo(
|
||||
)}${queryString}`;
|
||||
const tradesResponse = await fetchWithCache(
|
||||
tradeURL,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: 0, timeout: SECOND * 15 },
|
||||
);
|
||||
const newQuotes = tradesResponse.reduce((aggIdTradeMap, quote) => {
|
||||
@ -361,7 +363,7 @@ export async function fetchToken(contractAddress, chainId, useNewSwapsApi) {
|
||||
const tokenUrl = getBaseApi('token', chainId, useNewSwapsApi);
|
||||
const token = await fetchWithCache(
|
||||
`${tokenUrl}?address=${contractAddress}`,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||
);
|
||||
return token;
|
||||
@ -371,7 +373,7 @@ export async function fetchTokens(chainId, useNewSwapsApi) {
|
||||
const tokensUrl = getBaseApi('tokens', chainId, useNewSwapsApi);
|
||||
const tokens = await fetchWithCache(
|
||||
tokensUrl,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||
);
|
||||
const filteredTokens = [
|
||||
@ -397,7 +399,7 @@ export async function fetchAggregatorMetadata(chainId, useNewSwapsApi) {
|
||||
);
|
||||
const aggregators = await fetchWithCache(
|
||||
aggregatorMetadataUrl,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||
);
|
||||
const filteredAggregators = {};
|
||||
@ -419,7 +421,7 @@ export async function fetchTopAssets(chainId, useNewSwapsApi) {
|
||||
const topAssetsUrl = getBaseApi('topAssets', chainId, useNewSwapsApi);
|
||||
const response = await fetchWithCache(
|
||||
topAssetsUrl,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||
);
|
||||
const topAssetsMap = response.reduce((_topAssetsMap, asset, index) => {
|
||||
@ -437,7 +439,7 @@ export async function fetchSwapsFeatureFlags() {
|
||||
: SWAPS_API_V2_BASE_URL;
|
||||
const response = await fetchWithCache(
|
||||
`${v2ApiBaseUrl}/featureFlags`,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: 600000 },
|
||||
);
|
||||
return response;
|
||||
@ -467,7 +469,7 @@ export async function fetchSwapsGasPrices(chainId, useNewSwapsApi) {
|
||||
const gasPricesUrl = getBaseApi('gasPrices', chainId, useNewSwapsApi);
|
||||
const response = await fetchWithCache(
|
||||
gasPricesUrl,
|
||||
{ method: 'GET' },
|
||||
{ method: 'GET', headers: clientIdHeader },
|
||||
{ cacheRefreshTime: 30000 },
|
||||
);
|
||||
const responseIsValid = validateData(
|
||||
|
Loading…
Reference in New Issue
Block a user