import { useConnectModal } from '@rainbow-me/rainbowkit' import { Button } from 'components/primitives' import { ToastContext } from 'context/ToastContextProvider' import { useMarketplaceChain } from 'hooks' import { cloneElement, ComponentProps, FC, ReactNode, useContext } from 'react' import { useAccount, useWalletClient } from 'wagmi' import { CSS } from '@stitches/react' import { SWRResponse } from 'swr' import { EditListingModal, EditListingStep, } from '@reservoir0x/reservoir-kit-ui' type Props = { listingId?: string tokenId?: string collectionId?: string disabled?: boolean openState?: [boolean, React.Dispatch>] buttonCss?: CSS buttonProps?: ComponentProps buttonChildren?: ReactNode mutate?: SWRResponse['mutate'] } const EditListing: FC = ({ listingId, tokenId, collectionId, disabled, openState, buttonCss, buttonProps, buttonChildren, mutate, }) => { const { isDisconnected } = useAccount() const { openConnectModal } = useConnectModal() const { addToast } = useContext(ToastContext) const marketplaceChain = useMarketplaceChain() const { data: signer } = useWalletClient() const trigger = ( ) if (isDisconnected) { return cloneElement(trigger, { onClick: async () => { if (!signer) { openConnectModal?.() } }, }) } else return ( { if (mutate && currentStep == EditListingStep.Complete) mutate() }} onEditListingError={(error: any) => { if (error?.code === 4001) { addToast?.({ title: 'User canceled transaction', description: 'You have canceled the transaction.', }) return } addToast?.({ title: 'Could not edit listing', description: 'The transaction was not completed.', }) }} /> ) } export default EditListing