2022-09-23 08:37:55 +00:00
|
|
|
import { Alert } from 'components/Alert'
|
2022-09-23 12:27:24 +00:00
|
|
|
import { Anchor } from 'components/Anchor'
|
|
|
|
import { Button } from 'components/Button'
|
2022-09-23 08:37:55 +00:00
|
|
|
import { Conditional } from 'components/Conditional'
|
|
|
|
import { ContractPageHeader } from 'components/ContractPageHeader'
|
|
|
|
import { useWallet } from 'contexts/wallet'
|
|
|
|
import type { NextPage } from 'next'
|
|
|
|
import { NextSeo } from 'next-seo'
|
2022-09-23 12:27:24 +00:00
|
|
|
import { useCallback, useState } from 'react'
|
|
|
|
import { FaRocket, FaSlidersH } from 'react-icons/fa'
|
|
|
|
import { STARGAZE_URL } from 'utils/constants'
|
2022-09-23 08:37:55 +00:00
|
|
|
import { withMetadata } from 'utils/layout'
|
|
|
|
import { links } from 'utils/links'
|
|
|
|
|
2022-09-23 12:27:24 +00:00
|
|
|
import type { CollectionData } from './create'
|
|
|
|
|
2022-09-23 08:37:55 +00:00
|
|
|
const CollectionList: NextPage = () => {
|
|
|
|
const wallet = useWallet()
|
2022-09-23 12:27:24 +00:00
|
|
|
const [clearFlag, setClearFlag] = useState(false)
|
|
|
|
let allCollections: Record<string, CollectionData[]>[] = []
|
|
|
|
let myCollections: Record<string, CollectionData[]> | undefined
|
|
|
|
let myCollectionList: CollectionData[] = []
|
|
|
|
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
allCollections = localStorage['collections'] ? JSON.parse(localStorage['collections']) : []
|
|
|
|
myCollections = allCollections.find((c) => Object.keys(c)[0] === wallet.address)
|
|
|
|
myCollectionList = myCollections ? Object.values(myCollections)[0] : []
|
|
|
|
console.log(localStorage['collections'])
|
|
|
|
}
|
2022-09-23 08:37:55 +00:00
|
|
|
|
2022-09-23 12:27:24 +00:00
|
|
|
const renderTable = useCallback(() => {
|
2022-09-23 08:37:55 +00:00
|
|
|
return (
|
|
|
|
<div className="overflow-x-auto w-full">
|
2022-09-23 12:27:24 +00:00
|
|
|
{myCollectionList.length > 0 && (
|
|
|
|
<table className="table w-full">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="pl-20 text-lg font-bold text-left bg-black">Collection Name</th>
|
|
|
|
<th className="text-lg font-bold bg-black">Contract Address</th>
|
|
|
|
<th className="text-lg font-bold bg-black">Creation Time</th>
|
|
|
|
<th className="bg-black" />
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{myCollectionList.map((collection, index) => {
|
|
|
|
return (
|
|
|
|
<tr key={index}>
|
|
|
|
<td className="bg-black">
|
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
<div className="avatar">
|
|
|
|
<div className="w-12 h-12 mask mask-squircle">
|
|
|
|
<img alt="Cover" src={collection.imageURL} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="ml-2 font-bold">{collection.name}</div>
|
|
|
|
<div className="text-sm opacity-50" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td className="bg-black">
|
|
|
|
{collection.address}
|
|
|
|
{/* <br /> */}
|
|
|
|
{/* <span className="badge badge-ghost badge-sm"></span> */}
|
|
|
|
</td>
|
|
|
|
<td className="bg-black">{new Date(collection.time).toDateString()}</td>
|
|
|
|
<th className="bg-black">
|
|
|
|
<div className="flex items-center space-x-8">
|
|
|
|
<Anchor
|
|
|
|
className="text-xl text-plumbus"
|
|
|
|
external
|
|
|
|
href={`/collections/actions?sg721ContractAddress=${collection.address}&minterContractAddress=${collection.minter}`}
|
|
|
|
>
|
|
|
|
<FaSlidersH />
|
|
|
|
</Anchor>
|
|
|
|
|
|
|
|
<Anchor
|
|
|
|
className="text-xl text-plumbus"
|
|
|
|
external
|
|
|
|
href={`${STARGAZE_URL}/launchpad/${collection.minter}`}
|
|
|
|
>
|
|
|
|
<FaRocket />
|
|
|
|
</Anchor>
|
|
|
|
</div>
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
)}
|
2022-09-23 08:37:55 +00:00
|
|
|
</div>
|
|
|
|
)
|
2022-09-23 12:27:24 +00:00
|
|
|
}, [clearFlag, wallet.address])
|
|
|
|
|
|
|
|
const clearMyCollections = () => {
|
|
|
|
console.log('Cleared!')
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage['collections'] = JSON.stringify(allCollections.filter((c) => Object.keys(c)[0] !== wallet.address))
|
|
|
|
myCollectionList = []
|
|
|
|
setClearFlag(!clearFlag)
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 08:37:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="py-6 px-12 space-y-4">
|
|
|
|
<NextSeo title="My Collections" />
|
|
|
|
<ContractPageHeader description="A list of your collections." link={links.Documentation} title="My Collections" />
|
|
|
|
<hr />
|
2022-09-23 12:27:24 +00:00
|
|
|
<div>{renderTable()}</div>
|
2022-09-23 08:37:55 +00:00
|
|
|
<br />
|
2022-09-23 12:27:24 +00:00
|
|
|
{myCollectionList.length > 0 && <Button onClick={clearMyCollections}>Clear Collection List</Button>}
|
|
|
|
<Conditional test={myCollectionList.length === 0}>
|
2022-09-23 08:37:55 +00:00
|
|
|
<Alert type="info">You haven't created any collections so far.</Alert>
|
|
|
|
</Conditional>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default withMetadata(CollectionList, { center: false })
|