Skip to content

Commit

Permalink
stream-metadata: fix opensea invalidation url
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-nascimento committed Sep 9, 2024
1 parent 0bc97f9 commit 7d50084
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/stream-metadata/src/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { FastifyBaseLogger } from 'fastify'
import { config } from './environment'
import { spaceDapp } from './contract-utils'

const getOpenSeaAPIUrl = (space: SpaceInfo) => {
const getOpenSeaAPIUrl = (logger: FastifyBaseLogger, space: SpaceInfo) => {
const spaceOwnerAddress = config.web3Config.base.addresses.spaceOwner
const chainId = config.web3Config.base.chainId
const tokenId = BigNumber.from(space.tokenId).toString()

if (space.networkId === String(BASE_MAINNET)) {
if (chainId === BASE_MAINNET) {
return `https://api.opensea.io/api/v2/chain/base/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh`
} else if (space.networkId === String(BASE_SEPOLIA)) {
} else if (chainId === BASE_SEPOLIA) {
return `https://testnets-api.opensea.io/api/v2/chain/base_sepolia/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh`
} else if (chainId === 31337) {
return `https://testnets-api.opensea.io/api/v2/chain/base_sepolia/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh`
} else {
throw new Error('Unsupported network')
logger.error({ chainId }, 'Unsupported network')
throw new Error(`Unsupported network ${chainId}`)
}
}

Expand All @@ -40,7 +44,7 @@ export const refreshOpenSea = async ({
throw new Error('Space not found')
}

const url = getOpenSeaAPIUrl(space)
const url = getOpenSeaAPIUrl(logger, space)
logger.info({ url, spaceAddress }, 'refreshing openSea')

const response = await fetch(url, {
Expand Down

0 comments on commit 7d50084

Please sign in to comment.