Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #234 from reservoirprotocol/ofir/platf-2150-missin…
Browse files Browse the repository at this point in the history
…g-os-offers-on-sepolia

Ofir/platf 2150 missing os offers on sepolia
  • Loading branch information
nofir authored Sep 1, 2023
2 parents 3ad91c6 + 3141896 commit 28e47d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
63 changes: 31 additions & 32 deletions src/fetchers/opensea.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,36 @@ const getOSNetworkName = (chainId) => {
return "base";
case 7777777:
return "zora";
case 11155111:
return "sepolia";
case 80001:
return "mumbai";
case 84531:
return "base_goerli";
case 999:
return "zora_testnet";
}
};

const isOSTestnet = (chainId) => {
switch (chainId) {
case 4:
case 5:
case 11155111:
case 80001:
case 84531:
case 999:
return true;
}

return false;
};

const getUrlForApi = (api, chainId, contract, tokenId, network, slug) => {
const baseUrl = `${
![4, 5].includes(chainId) ? "https://api.opensea.io" : "https://testnets-api.opensea.io"
!isOSTestnet(chainId)
? "https://api.opensea.io"
: "https://testnets-api.opensea.io"
}`;

switch (api) {
Expand All @@ -64,7 +88,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 = ![4, 5].includes(chainId)

const headers = !isOSTestnet(chainId)
? {
url,
"X-API-KEY": apiKey,
Expand All @@ -76,7 +101,7 @@ const getOSData = async (api, chainId, contract, tokenId, slug) => {

try {
const osResponse = await axios.get(
![4, 5].includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url,
!isOSTestnet(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url,
{ headers }
);

Expand Down Expand Up @@ -148,19 +173,6 @@ export const fetchCollection = async (chainId, { contract, tokenId }) => {
let data;
let creatorAddress;

if (chainId === 43114) {
logger.info(
"opensea-fetcher",
JSON.stringify({
topic: "fetchCollectionDebug",
message: `Collection metadata start. contract=${contract}, tokenId=${tokenId}`,
contract,
tokenId,
data,
})
);
}

if (chainId === 1) {
data = await getOSData("asset", chainId, contract, tokenId);
creatorAddress = data?.creator?.address;
Expand All @@ -185,19 +197,6 @@ export const fetchCollection = async (chainId, { contract, tokenId }) => {
}
}

if (chainId === 43114) {
logger.info(
"opensea-fetcher",
JSON.stringify({
topic: "fetchCollectionDebug",
message: `Collection metadata debug. contract=${contract}, tokenId=${tokenId}`,
contract,
tokenId,
data,
})
);
}

if (!data?.collection) {
throw new Error("Missing collection");
}
Expand Down Expand Up @@ -315,12 +314,12 @@ export const fetchTokens = async (chainId, tokens) => {
}

const url = `${
![4, 5].includes(chainId) ? "https://api.opensea.io" : "https://testnets-api.opensea.io"
!isOSTestnet(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(!isOSTestnet(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url, {
headers: !isOSTestnet(chainId)
? {
url,
"X-API-KEY": process.env.OPENSEA_API_KEY.trim(),
Expand Down
8 changes: 4 additions & 4 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}
},
Expand Down

0 comments on commit 28e47d9

Please sign in to comment.