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

migrate markets from nftobject #155

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
2 changes: 1 addition & 1 deletion @market/modules/V3Ask/create/V3AskCreateSuccess.tsx
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ export function V3AskCreateSuccess({
onNext,
...props
}: V3AskCreateSuccessProps) {
const askURL = `https://noun.market/collections/${contractAddress}/${tokenId}`
const askURL = `https://noun.market/daos/${contractAddress}/${tokenId}`
const [_, copied, copy] = useCopyToClipboard(askURL)
const { toastDispatch } = useToast()
const { state } = useV3AskStateContext()
4 changes: 2 additions & 2 deletions @media/NFTCard/NFTCard.tsx
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ export function NFTCardComponent({

return (
<Stack w="100%" position="relative" overflow="hidden" className={cardWrapper}>
<Link href={`/collections/${collectionAddress}/${tokenId}`}>
<Link href={`/daos/${collectionAddress}/${tokenId}`}>
<Box w="100%" className={cardImageWrapper} backgroundColor="background2">
{collectionAddress && tokenId && <ImageWithNounFallback token={token} />}
</Box>
@@ -96,7 +96,7 @@ export function NFTCardComponent({
</Heading>
</Flex>
<Flex align="center" gap="x2" justify="space-between">
<Link href={`/collections/${collectionAddress}`}>
<Link href={`/daos/${collectionAddress}`}>
<Flex align="center" gap="x2">
<CollectionThumbnail
collectionAddress={collectionAddress}
6 changes: 3 additions & 3 deletions @noun-auction/components/ActiveAuction/RPCTokenInfo.tsx
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ export function RPCTokenInfo({
}: RPCTokenInfoProps) {
return (
<Flex className={['nounish-auction__token-info', styles.tokenInfoWrapper]} {...props}>
<NextLink href={`/collections/${collectionAddress}/${tokenId}`} passHref>
<NextLink href={`/daos/${collectionAddress}/${tokenId}`} passHref>
<Button as="a" variant="unset" className={styles.thumbnailLink}>
{!!tokenId && !!collectionAddress && (
<NounishThumbnail
@@ -40,13 +40,13 @@ export function RPCTokenInfo({
<Stack justify="space-around">
<Box>
<Box className={styles.rowCollectionName}>
<Link href={`/collections/${collectionAddress}`} passHref>
<Link href={`/daos/${collectionAddress}`} passHref>
{tokenName ?? '...'}
</Link>
</Box>
<Box mt="x1">
<Label as="a" color="tertiary" className={[lightFont]}>
<Link href={`/collections/${collectionAddress}`} passHref>
<Link href={`/daos/${collectionAddress}`} passHref>
{collectionName ?? '...'}
</Link>
</Label>
2 changes: 1 addition & 1 deletion @noun-auction/components/ActiveAuctionCard.tsx
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ export function ActiveAuctionCardComponent({
className={cardWrapper}
style={{ maxWidth: '500px' }}
>
<Link href={`/collections/${collectionAddress}/${tokenId}`}>
<Link href={`/daos/${collectionAddress}/${tokenId}`}>
<Box w="100%" className={cardImageWrapper} backgroundColor="tertiary">
<ImageWithNounFallback token={token} />
</Box>
2 changes: 1 addition & 1 deletion @shared/components/CollectionLink.tsx
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ export function CollectionLink({
...props
}: CollectionLinkProps) {
return (
<NextLink passHref href={`/collections/${contractAddress}`}>
<NextLink passHref href={`/daos/${contractAddress}`}>
<Button as="a" {...props}>
{children}
</Button>
4 changes: 2 additions & 2 deletions @shared/hooks/useTokenHelper.ts
Original file line number Diff line number Diff line change
@@ -33,12 +33,12 @@ export function useTokenHelper(nftObj: NFTObject) {
}, [nftCount, tokenID, isFirstTokenIDZero])

const handlePrev = useCallback(() => {
tokenID && router.push(`/collections/${nft?.contract.address}/${tokenID - 1}`)
tokenID && router.push(`/daos/${nft?.contract.address}/${tokenID - 1}`)
}, [nft?.contract.address, tokenID, router])

const handleNext = useCallback(() => {
if (hasNextNFT) {
tokenID && router.push(`/collections/${nft?.contract.address}/${tokenID + 1}`)
tokenID && router.push(`/daos/${nft?.contract.address}/${tokenID + 1}`)
}
}, [hasNextNFT, tokenID, router, nft?.contract.address])

2 changes: 1 addition & 1 deletion components/HomepageExplore.tsx
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { Link } from './Link'
export function HomepageExplore() {
return (
<Flex w="100%" justify="center">
<Link href="/collections">
<Link href="/daos">
<Flex
align="center"
borderRadius="curved"
2 changes: 1 addition & 1 deletion compositions/CollectionMenu/CollectionLink.tsx
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export function CollectionLink({ collection }: { collection: TypeSafeDao }) {
const { isSmall } = useWindowWidth()

return (
<Link href={`/collections/${collection.collectionAddress}`} passHref>
<Link href={`/daos/${collection.collectionAddress}`} passHref>
<Flex align="center" justify="space-between" gap="x4" onClick={requestClose}>
<Flex align="center" gap="x4">
<CollectionThumbnail
2 changes: 1 addition & 1 deletion compositions/CollectionRanking/RankingRow.tsx
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ export function RankingRow({ collection, ...props }: RankingRowProps) {

return (
<Stack {...props}>
<Link href={`/collections/${collection.address}`} passHref>
<Link href={`/daos/${collection.address}`} passHref>
<Grid className={[rankingRow]}>
<Flex className={[rankingRowInfo, 'collection-row__collection-info']}>
<CollectionThumbnail
4 changes: 2 additions & 2 deletions compositions/Daos/DaoRow.tsx
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ export const DaoRowComponent = ({
cursor="pointer"
/>
<Box>
<Link href={`/collections/${collectionAddress}`} passHref>
<Link href={`/daos/${collectionAddress}`} passHref>
<Button variant="secondary" as="a">
View
</Button>
@@ -160,7 +160,7 @@ export const DaoRowComponent = ({
<EthAmount ethAmount={highestBid} />
</Box>
</Box>
<Link href={`/collections/${contractAddress}`} passHref>
<Link href={`/daos/${contractAddress}`} passHref>
<Button variant="secondary" as="a">
View
</Button>
2 changes: 1 addition & 1 deletion compositions/NFTPage/NFTSidebar.tsx
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ export function NFTSidebarComponent({
{...props}
>
<Flex>
<Link href={`/collections/${token.collectionAddress}`}>
<Link href={`/daos/${token.collectionAddress}`}>
<CollectionThumbnail
collectionAddress={token.collectionAddress}
showTitle
15 changes: 15 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,21 @@ const nextConfig = {
// esmExternals: false,
// },

async redirects() {
return [
{
source: '/collections',
destination: '/',
permanent: true,
},
{
source: '/collections/:address*',
destination: '/daos/:address*',
permanent: true,
},
]
},

images: {
domains: [
// For debugging images
93 changes: 0 additions & 93 deletions pages/collections/[address]/index.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions pages/collections/index.tsx

This file was deleted.

File renamed without changes.
69 changes: 69 additions & 0 deletions pages/daos/[address]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Seo } from 'components'
import { PageWrapper } from 'components/PageWrapper'
import {
ActiveCollectionPageView,
CollectionAbout,
CollectionHeader,
} from 'compositions/Collections'
import { ALL_COLLECTION_VIEWS, CollectionNav } from 'compositions/Collections'
import { CollectionNFTs } from 'compositions/Collections/CollectionNFTs'
import { useRouter } from 'next/router'
import { useCollectionsContext } from 'providers/CollectionsProvider'
import { CollectionServiceProps, collectionService } from 'services/collectionService'

import { useAggregate } from 'hooks'

import React, { useEffect, useState } from 'react'

import { Stack } from '@zoralabs/zord'

const Collection = ({ fallback }: { fallback: CollectionServiceProps }) => {
const { setCurrentCollection, setCurrentCollectionCount } = useCollectionsContext()
const { contractAddress: collectionAddress, collection, seo } = fallback
const [activeView, setActiveView] = useState<ActiveCollectionPageView>('nfts')
const { nftCount } = useAggregate(collectionAddress)
const { asPath } = useRouter()
const router = useRouter()

useEffect(() => {
const urlHash = asPath.split('#')[1] as ActiveCollectionPageView
const isValidHash = ALL_COLLECTION_VIEWS && ALL_COLLECTION_VIEWS.includes(urlHash)
const activeView = isValidHash ? urlHash : 'nfts'
setActiveView(activeView)
router.push(`/daos/${collectionAddress}/#${activeView}`)
// No deps, should only run on first load:
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
if (collection?.name) {
setCurrentCollection(collection.name)
setCurrentCollectionCount(nftCount ? `${nftCount} NFTs` : '... NFTs')
}
return () => {
setCurrentCollection('Explore...')
setCurrentCollectionCount(undefined)
}
}, [nftCount, collection, setCurrentCollection, setCurrentCollectionCount])

return (
<PageWrapper direction="column" gap="x13">
<Seo title={seo.title} description={seo.description} />
<CollectionHeader collection={collection} />
<Stack gap="x8">
<CollectionNav
nftCount={nftCount}
collectionAddress={collectionAddress}
setActiveView={setActiveView}
/>
{activeView === 'about' && <CollectionAbout collection={collection} />}
{activeView === 'nfts' && <CollectionNFTs fallback={fallback} />}
{/* {activeView === 'about' && <CollectionActivity collection={collection} />} */}
</Stack>
</PageWrapper>
)
}

export const getServerSideProps = collectionService

export default Collection
90 changes: 0 additions & 90 deletions pages/docs/index.tsx

This file was deleted.

127 changes: 0 additions & 127 deletions pages/docs/nounish-auction-component.tsx

This file was deleted.

819 changes: 0 additions & 819 deletions pages/docs/zord-components.tsx

This file was deleted.

85 changes: 85 additions & 0 deletions services/collectionService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { NetworkInput } from 'utils/network'
import { SeoProps, buildCollectionSEO } from 'utils/seo'

import { GetServerSideProps } from 'next'

import * as Sentry from '@sentry/react'
import { GetNFTReturnType, zdk } from '@shared'
import {
Collection,
CollectionStatsAggregateQuery,
} from '@zoralabs/zdk/dist/queries/queries-sdk'

export type CollectionServiceProps = {
initialPage: GetNFTReturnType
contractAddress: string
aggregateStats: CollectionStatsAggregateQuery
collection: Collection // SSR data
seo: SeoProps
}

type CollectionProps = {
address: string
}

interface CollectionParamsProps extends GetServerSideProps {
params?: CollectionProps
}

export async function collectionService({ params }: CollectionParamsProps) {
const tokenAddress = params
? params.address.toLowerCase()
: process.env.NEXT_PUBLIC_DEFAULT_CONTRACT

if (!tokenAddress) return false

// FIXME: dynamic list of daos here
// if (tokenAddress && !allAddresses.includes(tokenAddress)) {
// return {
// notFound: true,
// }
// }

try {
const collection = await zdk.collection({
address: tokenAddress,
network: NetworkInput,
includeFullDetails: false,
})

if (!collection) {
return {
notFound: true,
revalidate: 600,
}
}

const { name, symbol } = collection
const seo = buildCollectionSEO(name, symbol)

return {
props: {
fallback: {
contractAddress: tokenAddress,
collection,
// todo: add initialPage of tokens() from tokens query
// replace ZDK on collections page with a direct GraphQL query
seo,
},
},
}
} catch (err) {
Sentry.captureException(err)

if (err instanceof Error) {
if (err?.message.includes('404')) {
return {
notFound: true,
revalidate: 60,
}
}
console.warn(err.message)
}
throw err
}
}