import { ModalProps } from '../../types/modal' import Modal from '../shared/Modal' import { useState, useCallback } from 'react' import Input from '@components/forms/Input' import Label from '@components/forms/Label' import Button, { LinkButton } from '@components/shared/Button' import { MANGO_MINT_DECIMALS } from 'utils/governance/constants' import { Listing, PublicKey, token } from '@metaplex-foundation/js' import metaplexStore from '@store/metaplexStore' import { useAuctionHouse, useBids } from 'hooks/market/useAuctionHouse' import { ImgWithLoader } from '@components/ImgWithLoader' // import { useTranslation } from 'next-i18next' import { toUiDecimals } from '@blockworks-foundation/mango-v4' import Loading from '@components/shared/Loading' import { notify } from 'utils/notifications' type ListingModalProps = { listing?: Listing } & ModalProps const BidNftModal = ({ isOpen, onClose, listing }: ListingModalProps) => { const metaplex = metaplexStore((s) => s.metaplex) const { data: auctionHouse } = useAuctionHouse() const { refetch } = useBids() // const { t } = useTranslation(['nft-market']) const noneListedAssetMode = !listing const [bidPrice, setBidPrice] = useState('') const [assetMint, setAssetMint] = useState('') const [submittingOffer, setSubmittingOffer] = useState(false) const [buying, setBuying] = useState(false) const bid = useCallback(async () => { setSubmittingOffer(true) try { const { response } = await metaplex!.auctionHouse().bid({ auctionHouse: auctionHouse!, price: token(bidPrice, MANGO_MINT_DECIMALS), mintAccount: noneListedAssetMode ? new PublicKey(assetMint) : listing!.asset.mint.address, }) refetch() if (response) { notify({ title: 'Transaction confirmed', type: 'success', txid: response.signature, }) } } catch (e) { console.log('error making offer', e) } finally { setSubmittingOffer(false) onClose() } }, [ metaplex, auctionHouse, bidPrice, noneListedAssetMode, assetMint, listing, onClose, refetch, setSubmittingOffer, ]) const handleBuyNow = useCallback( async (listing: Listing) => { setBuying(true) try { const { response } = await metaplex!.auctionHouse().buy({ auctionHouse: auctionHouse!, listing, }) refetch() if (response) { notify({ title: 'Transaction confirmed', type: 'success', txid: response.signature, }) } } catch (e) { console.log('error buying nft', e) } finally { setBuying(false) } }, [metaplex, auctionHouse, refetch, setBuying], ) return (

Make an Offer

{listing ? (
{listing.asset?.json?.image ? ( ) : null}

{listing.asset?.json?.name || 'Unknown'}

{listing.asset?.json?.collection?.family || 'Unknown'}

) : ( <>
) } export default BidNftModal