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 CACHE_REFRESH_FIVE_MINUTES = 300000;
|
||||||
|
|
||||||
|
const clientIdHeader = { 'X-Client-Id': 'extension' };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} type Type of an API call, e.g. "tokens"
|
* @param {string} type Type of an API call, e.g. "tokens"
|
||||||
* @param {string} chainId
|
* @param {string} chainId
|
||||||
@ -316,7 +318,7 @@ export async function fetchTradesInfo(
|
|||||||
)}${queryString}`;
|
)}${queryString}`;
|
||||||
const tradesResponse = await fetchWithCache(
|
const tradesResponse = await fetchWithCache(
|
||||||
tradeURL,
|
tradeURL,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: 0, timeout: SECOND * 15 },
|
{ cacheRefreshTime: 0, timeout: SECOND * 15 },
|
||||||
);
|
);
|
||||||
const newQuotes = tradesResponse.reduce((aggIdTradeMap, quote) => {
|
const newQuotes = tradesResponse.reduce((aggIdTradeMap, quote) => {
|
||||||
@ -361,7 +363,7 @@ export async function fetchToken(contractAddress, chainId, useNewSwapsApi) {
|
|||||||
const tokenUrl = getBaseApi('token', chainId, useNewSwapsApi);
|
const tokenUrl = getBaseApi('token', chainId, useNewSwapsApi);
|
||||||
const token = await fetchWithCache(
|
const token = await fetchWithCache(
|
||||||
`${tokenUrl}?address=${contractAddress}`,
|
`${tokenUrl}?address=${contractAddress}`,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
return token;
|
return token;
|
||||||
@ -371,7 +373,7 @@ export async function fetchTokens(chainId, useNewSwapsApi) {
|
|||||||
const tokensUrl = getBaseApi('tokens', chainId, useNewSwapsApi);
|
const tokensUrl = getBaseApi('tokens', chainId, useNewSwapsApi);
|
||||||
const tokens = await fetchWithCache(
|
const tokens = await fetchWithCache(
|
||||||
tokensUrl,
|
tokensUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const filteredTokens = [
|
const filteredTokens = [
|
||||||
@ -397,7 +399,7 @@ export async function fetchAggregatorMetadata(chainId, useNewSwapsApi) {
|
|||||||
);
|
);
|
||||||
const aggregators = await fetchWithCache(
|
const aggregators = await fetchWithCache(
|
||||||
aggregatorMetadataUrl,
|
aggregatorMetadataUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const filteredAggregators = {};
|
const filteredAggregators = {};
|
||||||
@ -419,7 +421,7 @@ export async function fetchTopAssets(chainId, useNewSwapsApi) {
|
|||||||
const topAssetsUrl = getBaseApi('topAssets', chainId, useNewSwapsApi);
|
const topAssetsUrl = getBaseApi('topAssets', chainId, useNewSwapsApi);
|
||||||
const response = await fetchWithCache(
|
const response = await fetchWithCache(
|
||||||
topAssetsUrl,
|
topAssetsUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const topAssetsMap = response.reduce((_topAssetsMap, asset, index) => {
|
const topAssetsMap = response.reduce((_topAssetsMap, asset, index) => {
|
||||||
@ -437,7 +439,7 @@ export async function fetchSwapsFeatureFlags() {
|
|||||||
: SWAPS_API_V2_BASE_URL;
|
: SWAPS_API_V2_BASE_URL;
|
||||||
const response = await fetchWithCache(
|
const response = await fetchWithCache(
|
||||||
`${v2ApiBaseUrl}/featureFlags`,
|
`${v2ApiBaseUrl}/featureFlags`,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: 600000 },
|
{ cacheRefreshTime: 600000 },
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
@ -467,7 +469,7 @@ export async function fetchSwapsGasPrices(chainId, useNewSwapsApi) {
|
|||||||
const gasPricesUrl = getBaseApi('gasPrices', chainId, useNewSwapsApi);
|
const gasPricesUrl = getBaseApi('gasPrices', chainId, useNewSwapsApi);
|
||||||
const response = await fetchWithCache(
|
const response = await fetchWithCache(
|
||||||
gasPricesUrl,
|
gasPricesUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET', headers: clientIdHeader },
|
||||||
{ cacheRefreshTime: 30000 },
|
{ cacheRefreshTime: 30000 },
|
||||||
);
|
);
|
||||||
const responseIsValid = validateData(
|
const responseIsValid = validateData(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user