import { useWallet } from '@solana/wallet-adapter-react' import { ModalProps } from '../../types/modal' import Modal from '../shared/Modal' import { useEffect, useState } from 'react' import mangoStore from '@store/mangoStore' import { useTranslation } from 'next-i18next' import { ImgWithLoader } from '@components/ImgWithLoader' import { NFT } from 'types' import Input from '@components/forms/Input' import Label from '@components/forms/Label' import Button from '@components/shared/Button' import { MANGO_MINT_DECIMALS } from 'utils/governance/constants' import { PublicKey } from '@solana/web3.js' import { token } from '@metaplex-foundation/js' import metaplexStore from '@store/metaplexStore' import { useAuctionHouse, useLazyListings } from 'hooks/market/useAuctionHouse' import Loading from '@components/shared/Loading' import { notify } from 'utils/notifications' const SellNftModal = ({ isOpen, onClose }: ModalProps) => { const { publicKey } = useWallet() const { t } = useTranslation() const metaplex = metaplexStore((s) => s.metaplex) const { data: auctionHouse } = useAuctionHouse() const { refetch } = useLazyListings() const connection = mangoStore((s) => s.connection) const nfts = mangoStore((s) => s.wallet.nfts.data) const isLoadingNfts = mangoStore((s) => s.wallet.nfts.loading) const fetchNfts = mangoStore((s) => s.actions.fetchNfts) const [submitting, setSubmitting] = useState(false) const [minPrice, setMinPrice] = useState('') const [selectedNft, setSelectedNft] = useState(null) useEffect(() => { if (publicKey) { fetchNfts(connection, publicKey) } }, [publicKey]) const listAsset = async (mint: string, price: number) => { setSubmitting(true) try { const currentListings = await metaplex?.auctionHouse().findListings({ auctionHouse: auctionHouse!, seller: publicKey!, mint: new PublicKey(mint), }) const isCurrentlyListed = currentListings?.filter((x) => !x.canceledAt) .length if (isCurrentlyListed) { throw 'Item is currently listed by you' } const { response } = await metaplex!.auctionHouse().list({ auctionHouse: auctionHouse!, // A model of the Auction House related to this listing mintAccount: new PublicKey(mint), // The mint account to create a listing for, used to find the metadata price: token(price, MANGO_MINT_DECIMALS), // The listing price }) refetch() if (response) { notify({ title: 'Transaction confirmed', type: 'success', txid: response.signature, }) } onClose() } catch (e) { console.log('error listing nft', e) } finally { setSubmitting(false) } } return (
{nfts.length > 0 ? (
{nfts.map((n) => ( ))}
) : isLoadingNfts ? (
{[...Array(12)].map((x, i) => (
))}
) : (

{t('profile:no-nfts')}

)}
{ setMinPrice(e.target.value) }} suffix="MNGO" >
) } export default SellNftModal