import { ZORA_API_KEY } from "@hey/data/constants"; import type { AccountFragment } from "@hey/indexer"; import { useQuery } from "@tanstack/react-query"; import { type GetCoinResponse, getCoin, setApiKey } from "@zoralabs/coins-sdk"; import { useState } from "react"; import type { Address } from "viem"; import { base } from "viem/chains"; import getAccountAttribute from "@/helpers/getAccountAttribute"; import { Image, Modal } from "../../Shared/UI"; import MetaDetails from "../MetaDetails"; import CreatorCoinDetails from "./CreatorCoinDetails"; setApiKey(ZORA_API_KEY); interface CreatorCoinProps { account: AccountFragment; } const CreatorCoin = ({ account }: CreatorCoinProps) => { const [showModal, setShowModal] = useState(false); const creatorCoinAddress = getAccountAttribute( "creatorCoinAddress", account?.metadata?.attributes ); const { data: coin } = useQuery({ enabled: !!creatorCoinAddress, queryFn: async () => { const coin = await getCoin({ address: creatorCoinAddress, chain: base.id }); return coin.data?.zora20Token ?? null; }, queryKey: ["coin", creatorCoinAddress] }); if (!coin) { return null; } return ( <> setShowModal(false)} show={showModal} title="Creator Coin" > ); }; export default CreatorCoin;