Skip to content

Commit

Permalink
Add custom coingecko url (#3275)
Browse files Browse the repository at this point in the history
* Add custom coingecko url

* object for coingecko config
  • Loading branch information
valentinoConti authored Feb 13, 2025
1 parent b2ed156 commit 7b53442
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion wormhole-connect/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function buildConfig(
],
Devnet: ['http://localhost:7071'],
}[network],
coinGeckoApiKey: customConfig.coinGeckoApiKey,
coingecko: customConfig.coingecko,

// Callbacks
triggerEvent: wrapEventHandler(customConfig.eventHandler),
Expand Down
10 changes: 8 additions & 2 deletions wormhole-connect/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export interface WormholeConnectConfig {

// External resources
rpcs?: ChainResourceMap;
coinGeckoApiKey?: string;
coingecko?: {
apiKey?: string;
customUrl?: string;
};

// White lists
chains?: Chain[];
Expand Down Expand Up @@ -137,7 +140,10 @@ export interface InternalConfig<N extends Network> {
mayanApi: string;
wormholeApi: string;
wormholeRpcHosts: string[];
coinGeckoApiKey?: string;
coingecko?: {
apiKey?: string;
customUrl?: string;
};

tokens: TokenCache;
tokenWhitelist?: (string | TokenTuple)[];
Expand Down
10 changes: 7 additions & 3 deletions wormhole-connect/src/utils/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ const coingeckoRequest = async (
): Promise<Response> => {
const headers = new Headers({
'Content-Type': 'application/json',
...(config.coinGeckoApiKey
? { 'x-cg-pro-api-key': config.coinGeckoApiKey }
...(config.coingecko?.apiKey
? { 'x-cg-pro-api-key': config.coingecko.apiKey }
: {}),
});

const hostname = config.coinGeckoApiKey ? COINGECKO_URL_PRO : COINGECKO_URL;
const hostname = config.coingecko?.customUrl
? config.coingecko.customUrl
: config.coingecko?.apiKey
? COINGECKO_URL_PRO
: COINGECKO_URL;

return fetch(`${hostname}${path}`, {
signal: params?.abort?.signal,
Expand Down

0 comments on commit 7b53442

Please sign in to comment.