Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP test refresh for token and contract #124

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ NEXT_PUBLIC_WEBSITE_URL='http://localhost:3000'
NEXT_PUBLIC_DEFAULT_CONTRACT='0x9C8fF314C9Bc7F6e59A9d9225Fb22946427eDC03'
NEXT_PUBLIC_GALACTUS_BASE_URL='https://api.zora.co/graphql'
NEXT_PUBLIC_NETWORK_URL='https://eth-mainnet.g.alchemy.com/v2/r6KOI4Qt3vcue_YFtajaS9QNFro_vHlc'
NEXT_PUBLIC_GA_TRACKING_ID=
NEXT_PUBLIC_GA_TRACKING_ID=
NEXT_PUBLIC_ZORA_API_KEY='CcwOqrniPUlBEQ9TH_mUiw'
110 changes: 107 additions & 3 deletions pages/collections/[address]/[tokenId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { PageWrapper, Seo } from 'components'
import { NFTAttributes, NFTHistory, NFTPageHero, NFTSidebar } from 'compositions'
import * as styles from 'compositions/NFTPage/NFTPage.css'
import { returnDao } from 'constants/collection-addresses'
import { nftService } from 'services'
import { nftService } from 'services/nftService'

import { useMemo } from 'react'
import { useCallback, useMemo, useState } from 'react'

import { NounishAuctionProvider } from '@noun-auction'
// const NEXT_PUBLIC_REFRESH_METADATA_URL_ROOT = 'http://api.zora.co/refresh-nft-metadata'
import { NFTProvider } from '@shared/providers/NFTProvider'
import { NFTObject } from '@zoralabs/nft-hooks'
import { Grid, Stack } from '@zoralabs/zord'
import { Button, Grid, Stack } from '@zoralabs/zord'

const REFRESH_METADATA_URL_ROOT = 'https://api.zora.co/refresh-nft-metadata'
// const REFRESH_METADATA_URL_ROOT = 'http://api.zora.co'

const NFT = ({
nft,
Expand All @@ -21,7 +25,100 @@ const NFT = ({
tokenId: string
}) => {
const dao = useMemo(() => returnDao(tokenAddress), [tokenAddress])
// headers: {
// 'Content-Type': 'application/json',
// 'X-API-KEY': process.env.NEXT_PUBLIC_ZORA_API_KEY,
// },
const [isUpdatingToken, setIsUpdatingToken] = useState<boolean>(false)
const [isUpdatingContract, setIsUpdatingContract] = useState<boolean>(false)
const handleUpdateTokenMetadata = useCallback(async () => {
setIsUpdatingToken(true)
try {
console.log('TRYING TOKEN REFRESH')

const rawResponse = await fetch(
// `${REFRESH_METADATA_URL_ROOT}/queueMetadataRefreshForToken`,
`${REFRESH_METADATA_URL_ROOT}/${tokenAddress}/${tokenId}`,
{
method: 'POST',
/* @ts-ignore */
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-API-KEY': process.env.NEXT_PUBLIC_ZORA_API_KEY,
},
// body: JSON.stringify({
// nftContractAddress: tokenAddress,
// tokenId: tokenId,
// }),
}
)
const content = await rawResponse.json()

console.log('CONTENT for token update', content)

// const response = await fetch(
// `${REFRESH_METADATA_URL_ROOT}/${tokenAddress}/${tokenId}`,
// {
// method: 'POST',
// payload:
// }
// )

// if (!response.ok) {
// throw new Error(`Error! status: ${response.status}`)
// }
} catch (err: any) {
console.log('CATCHING')
console.error(err.message)
} finally {
setIsUpdatingToken(false)
}
}, [tokenAddress, tokenId])
const handleUpdateContractMetadata = useCallback(async () => {
setIsUpdatingContract(true)
try {
console.log('TRYING CONTRACT REFRESH')

const rawResponse = await fetch(
// `${REFRESH_METADATA_URL_ROOT}/queueMetadataRefreshForContractAddress`,
`${REFRESH_METADATA_URL_ROOT}/${tokenAddress}`,
{
method: 'POST',
/* @ts-ignore */
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-API-KEY': process.env.NEXT_PUBLIC_ZORA_API_KEY,
},
// body: JSON.stringify({
// nftContractAddress: tokenAddress,
// }),
}
)
const content = await rawResponse.json()

console.log('CONTENT for contract update', content)

// const response = await fetch(
// `${REFRESH_METADATA_URL_ROOT}/${tokenAddress}/${tokenId}`,
// {
// method: 'POST',
// payload:
// }
// )

// if (!response.ok) {
// throw new Error(`Error! status: ${response.status}`)
// }
} catch (err: any) {
console.log('CATCHING')
console.error(err.message)
} finally {
setIsUpdatingContract(false)
}
}, [tokenAddress])
console.log(nft)
return (
<PageWrapper direction="column">
<Seo
Expand All @@ -40,6 +137,13 @@ const NFT = ({
<NFTSidebar />
)}
<Stack className={styles.attributesHistoryWrapper}>
<Button onClick={handleUpdateTokenMetadata} loading={isUpdatingToken}>
REFRESH TOKEN
</Button>
<Button onClick={handleUpdateContractMetadata} loading={isUpdatingContract}>
REFRESH CONTRACT
</Button>

<NFTHistory />
<NFTAttributes />
</Stack>
Expand Down