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

Commit

Permalink
Merge branch 'ofir/platf-2150-missing-os-offers-on-sepolia' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
nofir committed Sep 1, 2023
2 parents aaac437 + 4741f0b commit 279cc96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
48 changes: 19 additions & 29 deletions src/fetchers/opensea.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@ 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";
case 324:
return "zksync";
}
};

const getOSTestNetsChainIds = () => {
return [4, 5, 11155111, 80001, 84531, 999];
};

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

switch (api) {
Expand All @@ -64,7 +80,7 @@ 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 = !getOSTestNetsChainIds().includes(chainId)
? {
url,
"X-API-KEY": apiKey,
Expand All @@ -76,7 +92,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,
!getOSTestNetsChainIds().includes(chainId) ? process.env.OPENSEA_BASE_URL_ALT || url : url,
{ headers }
);

Expand Down Expand Up @@ -148,19 +164,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 +188,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
2 changes: 0 additions & 2 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export const normalizeMetadata = (collection) => {
let metadata = {};
if (collection?.social_urls) {
Object.keys(collection.social_urls).forEach((key) => {
console.log(key, map);
if (key in map) {
if (map[key].normalize) {
metadata[map[key].key] = map[key].normalize(collection.social_urls[key]);
Expand All @@ -134,7 +133,6 @@ export const normalizeMetadata = (collection) => {

// do the above via the map
Object.keys(map).forEach((key) => {
console.log(key, map, collection);
if (key in collection) {
if (map[key].normalize) {
metadata[map[key].key] = map[key].normalize(collection[key]);
Expand Down

0 comments on commit 279cc96

Please sign in to comment.