diff --git a/src/fetchers/opensea.js b/src/fetchers/opensea.js index 7080664..b8ebe17 100644 --- a/src/fetchers/opensea.js +++ b/src/fetchers/opensea.js @@ -13,6 +13,8 @@ const apiKey = process.env.OPENSEA_COLLECTION_API_KEY ? process.env.OPENSEA_COLLECTION_API_KEY.trim() : process.env.OPENSEA_API_KEY.trim(); +const osTestnetsChainIds = [4, 5, 11155111, 80001, 84531, 999]; + const getOSNetworkName = (chainId) => { switch (chainId) { case 1: @@ -50,13 +52,9 @@ const getOSNetworkName = (chainId) => { } }; -const getOSTestNetsChainIds = () => { - return [4, 5, 11155111, 80001, 84531, 999]; -}; - const getUrlForApi = (api, chainId, contract, tokenId, network, slug) => { const baseUrl = `${ - !getOSTestNetsChainIds().includes(chainId) + !osTestnetsChainIds.includes(chainId) ? "https://api.opensea.io" : "https://testnets-api.opensea.io" }`; @@ -80,7 +78,8 @@ const getUrlForApi = (api, chainId, contract, tokenId, network, slug) => { const getOSData = async (api, chainId, contract, tokenId, slug) => { const network = getOSNetworkName(chainId); const url = getUrlForApi(api, chainId, contract, tokenId, network, slug); - const headers = !getOSTestNetsChainIds().includes(chainId) + + const headers = !osTestnetsChainIds.includes(chainId) ? { url, "X-API-KEY": apiKey, @@ -92,7 +91,7 @@ const getOSData = async (api, chainId, contract, tokenId, slug) => { try { const osResponse = await axios.get( - !getOSTestNetsChainIds().includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url, + !osTestnetsChainIds.includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url, { headers } ); @@ -305,12 +304,12 @@ export const fetchTokens = async (chainId, tokens) => { } const url = `${ - ![4, 5].includes(chainId) ? "https://api.opensea.io" : "https://testnets-api.opensea.io" + !osTestnetsChainIds.includes(chainId) ? "https://api.opensea.io" : "https://testnets-api.opensea.io" }/api/v1/assets?${searchParams.toString()}`; const data = await axios - .get(![4, 5].includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url, { - headers: ![4, 5].includes(chainId) + .get(!osTestnetsChainIds.includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url, { + headers: !osTestnetsChainIds.includes(chainId) ? { url, "X-API-KEY": process.env.OPENSEA_API_KEY.trim(), diff --git a/src/shared/utils.js b/src/shared/utils.js index 186c948..607d0ef 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -38,7 +38,7 @@ export const normalizeMetadata = (collection) => { key: "twitterUsername", normalize: (value) => { // if the value is a url, return the username - if (value.includes("twitter.com")) { + if (value?.includes("twitter.com")) { return value.split("/")[3]; } @@ -48,7 +48,7 @@ export const normalizeMetadata = (collection) => { twitter: { key: "twitterUrl", normalize: (value) => { - if (value.includes("twitter.com")) { + if (value?.includes("twitter.com")) { return value; } // if the value is a username, return the url @@ -58,7 +58,7 @@ export const normalizeMetadata = (collection) => { telegram: { key: "telegramUrl", normalize: (value) => { - if (value.includes("t.me")) { + if (value?.includes("t.me")) { return value; } @@ -68,7 +68,7 @@ export const normalizeMetadata = (collection) => { instagram: { key: "instagramUrl", normalize: (value) => { - if (value.includes("instagram.com")) { + if (value?.includes("instagram.com")) { return value; } },