import { ModalProps } from '../../types/modal' import Modal from '../shared/Modal' import { useAuctionHouse, useBids, useLazyListings, } from 'hooks/market/useAuctionHouse' import { toUiDecimals } from '@blockworks-foundation/mango-v4' import { MANGO_MINT_DECIMALS } from 'utils/governance/constants' import metaplexStore from '@store/metaplexStore' import { LazyBid, Listing, PublicBid } from '@metaplex-foundation/js' import { useTranslation } from 'next-i18next' import EmptyState from './EmptyState' import dayjs from 'dayjs' import NftMarketButton from './NftMarketButton' import Loading from '@components/shared/Loading' import { useState } from 'react' import { notify } from 'utils/notifications' const AssetBidsModal = ({ isOpen, onClose, listing, }: ModalProps & { listing: Listing }) => { const { t } = useTranslation(['nft-market']) const [accepting, setAccepting] = useState('') const metaplex = metaplexStore((s) => s.metaplex) const { data: auctionHouse } = useAuctionHouse() const { data: lazyBids, refetch: reftechBids } = useBids() const { refetch: refetchLazyListings } = useLazyListings() const assetBids = lazyBids?.filter((x) => x.metadataAddress.equals(listing.asset.metadataAddress), ) const acceptBid = async (lazyBid: LazyBid) => { setAccepting(lazyBid.metadataAddress.toString()) try { const bid = await metaplex!.auctionHouse().loadBid({ lazyBid, loadJsonMetadata: true, }) const { response } = await metaplex!.auctionHouse().sell({ auctionHouse: auctionHouse!, bid: bid as PublicBid, sellerToken: listing.asset.token, }) refetchLazyListings() reftechBids() if (response) { notify({ title: 'Transaction confirmed', type: 'success', txid: response.signature, }) } } catch (e) { console.log('error accepting offer', e) } finally { setAccepting('') } } return (

Offers

{assetBids && assetBids.length ? ( assetBids.map((x) => (

{dayjs(x.createdAt.toNumber() * 1000).format( 'DD MMM YY h:mma', )}

{toUiDecimals(x.price.basisPoints, MANGO_MINT_DECIMALS)}{' '} MNGO
) : ( t('accept') ) } colorClass="error" onClick={() => acceptBid(x)} />
)) ) : ( )}
) } export default AssetBidsModal