import { ListModal, ListStep, useTokens } from '@reservoir0x/reservoir-kit-ui' import { Button } from 'components/primitives' import { cloneElement, ComponentProps, ComponentPropsWithoutRef, FC, ReactNode, useContext, } from 'react' import { CSS } from '@stitches/react' import { SWRResponse } from 'swr' import { useAccount, useWalletClient } from 'wagmi' import { useConnectModal } from '@rainbow-me/rainbowkit' import { ToastContext } from 'context/ToastContextProvider' import { useMarketplaceChain } from 'hooks' const orderFee = process.env.NEXT_PUBLIC_MARKETPLACE_FEE type ListingCurrencies = ComponentPropsWithoutRef< typeof ListModal >['currencies'] type Props = { token?: ReturnType['data'][0] buttonCss?: CSS buttonChildren?: ReactNode buttonProps?: ComponentProps mutate?: SWRResponse['mutate'] } const List: FC = ({ token, buttonCss, buttonChildren, buttonProps, mutate, }) => { const { isDisconnected } = useAccount() const { openConnectModal } = useConnectModal() const { addToast } = useContext(ToastContext) const marketplaceChain = useMarketplaceChain() const { data: signer } = useWalletClient() const listingCurrencies: ListingCurrencies = marketplaceChain.listingCurrencies const tokenId = token?.token?.tokenId const contract = token?.token?.contract const trigger = ( ) const orderFees = orderFee ? [orderFee] : [] if (isDisconnected) { return cloneElement(trigger, { onClick: async () => { if (!signer) { openConnectModal?.() } }, }) } else return ( { if (mutate && currentStep == ListStep.Complete) mutate() }} onListingError={(err: any) => { if (err?.code === 4001) { addToast?.({ title: 'User canceled transaction', description: 'You have canceled the transaction.', }) return } addToast?.({ title: 'Could not list token', description: 'The transaction was not completed.', }) }} /> ) } export default List