stargaze-studio/pages/collections/myCollections.tsx

124 lines
4.9 KiB
TypeScript
Raw Normal View History

2022-09-23 17:36:34 +00:00
/* eslint-disable eslint-comments/disable-enable-pair */
2023-02-19 07:45:53 +00:00
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
2022-09-23 17:36:34 +00:00
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import axios from 'axios'
2022-09-23 08:37:55 +00:00
import { Alert } from 'components/Alert'
import { Anchor } from 'components/Anchor'
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 17:36:34 +00:00
import { useCallback, useEffect, useState } from 'react'
import { FaRocket, FaSlidersH } from 'react-icons/fa'
2022-09-23 17:36:34 +00:00
import { API_URL, STARGAZE_URL } from 'utils/constants'
2022-09-23 08:37:55 +00:00
import { withMetadata } from 'utils/layout'
import { links } from 'utils/links'
const CollectionList: NextPage = () => {
const wallet = useWallet()
2022-09-23 17:36:34 +00:00
const [myCollections, setMyCollections] = useState<any[]>([])
2022-09-23 17:36:34 +00:00
useEffect(() => {
const fetchCollections = async () => {
await axios
.get(`${API_URL}/api/v1beta/collections/${wallet.address}`)
.then((response) => {
const collectionData = response.data
setMyCollections(collectionData)
})
.catch(console.error)
}
fetchCollections().catch(console.error)
}, [wallet.address])
2022-09-23 08:37:55 +00:00
const renderTable = useCallback(() => {
2022-09-23 08:37:55 +00:00
return (
<div className="overflow-x-auto w-full">
2022-09-23 17:36:34 +00:00
{myCollections.length > 0 && (
<table className="table w-full">
<thead>
<tr>
2022-09-23 17:36:34 +00:00
<th className="pl-36 text-lg font-bold text-left bg-black">Collection Name</th>
<th className="text-lg font-bold bg-black">Contract Address</th>
<th className="bg-black" />
</tr>
</thead>
<tbody>
2022-09-23 17:36:34 +00:00
{myCollections.map((collection: any, index: any) => {
return (
<tr key={index}>
2022-09-23 17:36:34 +00:00
<td className="w-[55%] bg-black">
<div className="flex items-center space-x-3">
<div className="avatar">
2022-09-23 17:36:34 +00:00
<div className="w-28 h-28 mask mask-squircle">
<img
alt="Cover"
2023-02-19 07:45:53 +00:00
src={
(collection?.image as string).startsWith('ipfs')
? `https://ipfs-gw.stargaze-apis.com/ipfs/${(collection?.image as string).substring(
7,
)}`
: collection?.image
}
2022-09-23 17:36:34 +00:00
/>
</div>
</div>
2022-09-23 17:36:34 +00:00
<div className="pl-2">
<p className="overflow-auto max-w-xs font-bold no-scrollbar ">{collection.name}</p>
<p className="max-w-xs text-sm truncate opacity-50">{collection.description}</p>
</div>
</div>
</td>
2022-09-23 17:36:34 +00:00
<td className="w-[35%] bg-black">
{collection.contractAddress}
{/* <br /> */}
{/* <span className="badge badge-ghost badge-sm"></span> */}
</td>
<th className="bg-black">
<div className="flex items-center space-x-8">
<Anchor
className="text-xl text-plumbus"
2022-09-23 17:36:34 +00:00
href={`/collections/actions?sg721ContractAddress=${collection.contractAddress}&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 17:36:34 +00:00
}, [myCollections, wallet.address])
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 />
<div>{renderTable()}</div>
2022-09-23 08:37:55 +00:00
<br />
2022-09-23 17:36:34 +00:00
<Conditional test={myCollections.length === 0}>
2022-09-23 08:37:55 +00:00
<Alert type="info">You haven&apos;t created any collections so far.</Alert>
</Conditional>
</section>
)
}
export default withMetadata(CollectionList, { center: false })