/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ import { toUtf8 } from '@cosmjs/encoding' import axios from 'axios' import { Alert } from 'components/Alert' import { Anchor } from 'components/Anchor' import { Conditional } from 'components/Conditional' import { ContractPageHeader } from 'components/ContractPageHeader' import { Tooltip } from 'components/Tooltip' import { useWallet } from 'contexts/wallet' import type { NextPage } from 'next' import { NextSeo } from 'next-seo' import { useCallback, useEffect, useState } from 'react' import { FaCopy, FaRocket, FaSlidersH, FaStore } from 'react-icons/fa' import { copy } from 'utils/clipboard' import { API_URL, STARGAZE_URL } from 'utils/constants' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' import { truncateMiddle } from 'utils/text' const CollectionList: NextPage = () => { const wallet = useWallet() const [myCollections, setMyCollections] = useState([]) const [myOneOfOneCollections, setMyOneOfOneCollections] = useState([]) const [myStandardCollections, setMyStandardCollections] = useState([]) async function getMinterContractType(minterContractAddress: string) { if (wallet.client && minterContractAddress.length > 0) { const client = wallet.client const data = await client.queryContractRaw( minterContractAddress, toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()), ) const contractType: string = JSON.parse(new TextDecoder().decode(data as Uint8Array)).contract return contractType } } const filterMyCollections = () => { setMyOneOfOneCollections([]) setMyStandardCollections([]) if (myCollections.length > 0) { myCollections.map(async (collection: any) => { await getMinterContractType(collection.minter) .then((contractType) => { if (contractType?.includes('sg-base-minter')) { setMyOneOfOneCollections((prevState) => [...prevState, collection]) } else if (contractType?.includes('sg-minter') || contractType?.includes('flex')) { setMyStandardCollections((prevState) => [...prevState, collection]) } }) .catch((err) => { console.log(err) console.log('Unable to retrieve contract type') }) }) } } 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]) useEffect(() => { filterMyCollections() }, [myCollections]) const renderTable = useCallback(() => { return (
{myCollections.length > 0 && (
{myStandardCollections.length > 0 && (
Standard Collections {myStandardCollections.map((collection: any, index: any) => { return ( ) })}
Collection Name Contract Address
Cover

{collection.name}

{collection.description}

Minter:
SG721:
)} {myOneOfOneCollections.length > 0 && (
1/1 Collections {myOneOfOneCollections.map((collection: any, index: any) => { return ( ) })}
Collection Name Contract Address
Cover

{collection.name}

{collection.description}

Minter:
SG721:
)}
)}
) }, [myCollections, myStandardCollections, myOneOfOneCollections, wallet.address]) return (

{renderTable()}

You haven't created any collections so far.
) } export default withMetadata(CollectionList, { center: false })