Skip to content

Commit 60fef47

Browse files
committed
fix(22139): add header to requests going to CoinGecko
1 parent ae1c9eb commit 60fef47

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ packages/*/docs
3131

3232
# typescript
3333
packages/*/*.tsbuildinfo
34+
35+
# editor
36+
.idea

packages/assets-controllers/src/TokenRatesController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface TokenRatesState extends BaseState {
140140

141141
const CoinGeckoApi = {
142142
BASE_URL: 'https://api.coingecko.com/api/v3',
143+
headers: { 'X-Requested-With': 'metamask.dec.jan.2024' },
143144
getTokenPriceURL(chainSlug: string, query: string) {
144145
return `${this.BASE_URL}/simple/token_price/${chainSlug}?${query}`;
145146
},
@@ -380,7 +381,9 @@ export class TokenRatesController extends PollingControllerV1<
380381
): Promise<CoinGeckoResponse> {
381382
const tokenPairs = tokenAddresses.join(',');
382383
const query = `contract_addresses=${tokenPairs}&vs_currencies=${vsCurrency.toLowerCase()}`;
383-
return handleFetch(CoinGeckoApi.getTokenPriceURL(chainSlug, query));
384+
return handleFetch(CoinGeckoApi.getTokenPriceURL(chainSlug, query), {
385+
headers: CoinGeckoApi.headers,
386+
});
384387
}
385388

386389
/**
@@ -399,6 +402,7 @@ export class TokenRatesController extends PollingControllerV1<
399402
if (now - timestamp > threshold) {
400403
const currencies = await handleFetch(
401404
CoinGeckoApi.getSupportedVsCurrencies(),
405+
{ headers: CoinGeckoApi.headers },
402406
);
403407
this.supportedVsCurrencies = {
404408
data: currencies,
@@ -426,7 +430,9 @@ export class TokenRatesController extends PollingControllerV1<
426430
const now = Date.now();
427431

428432
if (now - timestamp > threshold) {
429-
const platforms = await handleFetch(CoinGeckoApi.getPlatformsURL());
433+
const platforms = await handleFetch(CoinGeckoApi.getPlatformsURL(), {
434+
headers: CoinGeckoApi.headers,
435+
});
430436
this.supportedChains = {
431437
data: platforms,
432438
timestamp: Date.now(),

0 commit comments

Comments
 (0)