// import { useTranslation } from 'next-i18next' import { useEffect, useState } from 'react' import { useAuctionHouse, useBids, useListings, useLoadBids, } from 'hooks/market/useAuctionHouse' import { toUiDecimals } from '@blockworks-foundation/mango-v4' import { MANGO_MINT_DECIMALS } from 'utils/governance/constants' import { useWallet } from '@solana/wallet-adapter-react' import metaplexStore from '@store/metaplexStore' import { Bid, Listing, PublicBid, PublicKey } from '@metaplex-foundation/js' import BidNftModal from './BidNftModal' import mangoStore from '@store/mangoStore' import { Table, TableDateDisplay, Td, Th, TrBody, TrHead, } from '@components/shared/TableElements' import { ImgWithLoader } from '@components/ImgWithLoader' import NftMarketButton from './NftMarketButton' import { abbreviateAddress } from 'utils/formatting' import { NoSymbolIcon } from '@heroicons/react/20/solid' const AllBidsView = () => { const { publicKey } = useWallet() const { data: auctionHouse } = useAuctionHouse() const metaplex = metaplexStore((s) => s.metaplex) // const { t } = useTranslation(['nft-market']) const [showBidModal, setShowBidModal] = useState(false) const [bidListing, setBidListing] = useState(null) const { data: bids, refetch } = useBids() const bidsToLoad = bids ? bids : [] const { data: loadedBids } = useLoadBids(bidsToLoad) const connection = mangoStore((s) => s.connection) const fetchNfts = mangoStore((s) => s.actions.fetchNfts) const nfts = mangoStore((s) => s.wallet.nfts.data) const { data: listings } = useListings() useEffect(() => { if (publicKey) { fetchNfts(connection, publicKey!) } }, [publicKey]) const cancelBid = async (bid: Bid) => { await metaplex!.auctionHouse().cancelBid({ auctionHouse: auctionHouse!, bid, }) refetch() } const sellAsset = async (bid: Bid, tokenAccountPk: string) => { console.log(tokenAccountPk) const tokenAccount = await metaplex ?.tokens() .findTokenByAddress({ address: new PublicKey(tokenAccountPk) }) await metaplex!.auctionHouse().sell({ auctionHouse: auctionHouse!, bid: bid as PublicBid, sellerToken: tokenAccount!, }) refetch() } const buyAsset = async (listing: Listing) => { await metaplex!.auctionHouse().buy({ auctionHouse: auctionHouse!, listing, }) refetch() } const openBidModal = (listing: Listing) => { setBidListing(listing) setShowBidModal(true) } return ( <>
{loadedBids?.length ? ( {loadedBids .sort((a, b) => b.createdAt.toNumber() - a.createdAt.toNumber()) .map((x, idx) => { const listing = listings?.results?.find( (nft: Listing) => nft.asset.mint.toString() === x.asset.mint.toString() ) return ( ) })}
Date NFT Offer Buy Now Price Buyer Actions

{toUiDecimals( x.price.basisPoints.toNumber(), MANGO_MINT_DECIMALS )} {' MNGO'}

{listing ? ( <> {toUiDecimals( listing.price.basisPoints.toNumber(), MANGO_MINT_DECIMALS )} {' MNGO'} ) : ( '–' )}

{abbreviateAddress(x.buyerAddress)}

{publicKey && !x.buyerAddress.equals(publicKey) && nfts.find( (ownNft) => ownNft.mint === x.asset.address.toBase58() ) ? ( sellAsset( x, nfts.find( (ownNft) => ownNft.mint === x.asset.address.toBase58() )!.tokenAccount ) } colorClass="fgd-3" text="Accept Offer" /> ) : ( <> {publicKey && x.buyerAddress.equals(publicKey) ? ( cancelBid(x)} /> ) : listing ? ( openBidModal(listing)} /> ) : null} {listing ? ( buyAsset(listing)} /> ) : null} )}
) : (

No offers to show...

)}
{showBidModal ? ( setShowBidModal(false)} /> ) : null} ) } export default AllBidsView