import { faGasPump } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useBids, useCollections, useListings, useTokens, } from '@reservoir0x/reservoir-kit-ui' import { AcceptBid, Bid, BuyNow, List } from 'components/buttons' import AddToCart from 'components/buttons/AddToCart' import CancelBid from 'components/buttons/CancelBid' import CancelListing from 'components/buttons/CancelListing' import Mint from 'components/buttons/Mint' import { Button, Flex, Grid, Tooltip, Text } from 'components/primitives' import { useRouter } from 'next/router' import { ComponentPropsWithoutRef, FC, useState } from 'react' import { MutatorCallback } from 'swr' import { useAccount } from 'wagmi' type Props = { token: ReturnType['data'][0] collection: ReturnType['data'][0] | null offer?: ReturnType['data'][0] listing?: ReturnType['data'][0] isOwner: boolean mutate?: MutatorCallback account: ReturnType } export const TokenActions: FC = ({ token, collection, offer, listing, isOwner, mutate, account, }) => { const router = useRouter() const bidOpenState = useState(true) const buyOpenState = useState(true) const [path, _] = router.asPath.split('?') const routerPath = path.split('/') const isBuyRoute = routerPath[routerPath.length - 1] === 'buy' const queryBidId = router.query.bidId as string const deeplinkToAcceptBid = router.query.acceptBid === 'true' const is1155 = token?.token?.kind === 'erc1155' const showAcceptOffer = !is1155 && token?.market?.topBid?.id !== null && token?.market?.topBid?.id !== undefined && isOwner && token?.token?.owner ? true : false const isTopBidder = account.isConnected && token?.market?.topBid?.maker?.toLowerCase() === account?.address?.toLowerCase() const isListed = token ? token?.market?.floorAsk?.id !== null : false const offerIsOracleOrder = offer?.isNativeOffChainCancellable const listingIsOracleOrder = listing?.isNativeOffChainCancellable const mintData = collection?.mintStages?.find( (stage) => stage.tokenId === token?.token?.tokenId ) const mintPriceDecimal = mintData?.price?.amount?.decimal const mintCurrency = mintData?.price?.currency?.symbol?.toUpperCase() const mintPrice = typeof mintPriceDecimal === 'number' && mintPriceDecimal !== null && mintPriceDecimal !== undefined ? mintPriceDecimal === 0 ? 'Free' : `${mintPriceDecimal} ${mintCurrency}` : undefined const buttonCss: ComponentPropsWithoutRef['css'] = { width: '100%', height: 52, justifyContent: 'center', minWidth: 'max-content', '@sm': { maxWidth: 250, }, } return ( {isOwner && !is1155 && ( )} {(!isOwner || is1155) && isListed && token?.market?.floorAsk?.price?.amount && ( {!is1155 && ( )} )} {mintData && mintPrice ? ( Mint {`${mintPrice}`} } buttonCss={{ minWidth: 'max-content', whiteSpace: 'nowrap', flexShrink: 0, flexGrow: 1, justifyContent: 'center', ...buttonCss, }} mutate={mutate} /> ) : null} {showAcceptOffer && ( )} {(!isOwner || is1155) && ( )} {isTopBidder && !is1155 && ( {!offerIsOracleOrder ? ( Cancelling this order requires gas. } > ) : ( )} } /> )} {isOwner && isListed && !is1155 && ( {!listingIsOracleOrder ? ( Cancelling this order requires gas. } > ) : ( )} } /> )} ) }