From f1443671efe0df15443f0be3975bf6ec5a93b3d9 Mon Sep 17 00:00:00 2001 From: lynn <41491154+lynnshaoyu@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:22:19 -0500 Subject: [PATCH] feat: Web 1854 listed card (#5160) * init * it's working with jack's card.tsx components * add nft details on cards for view my nfts * listed cards ready for review * remove unnecessary code * updated radius * first round charlie comments * respond all comments * init * fix * color * remove floor price when not on sell mode * remove floor when nft is listed * feat: Web 1858 disabled card 1155 when sell mode is on (#5169) * disabled states + tooltips * remove collection asset changes * popover offset changes * respond to padmini comment * respond to charlie --- src/components/Popover/index.tsx | 23 +++++++-- src/components/Tooltip/index.tsx | 3 +- src/nft/components/collection/Card.tsx | 26 ++++++++-- .../profile/view/ViewMyNftsAsset.tsx | 51 +++++++++++++++---- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/components/Popover/index.tsx b/src/components/Popover/index.tsx index ef3ab7ab2b..967f8123ef 100644 --- a/src/components/Popover/index.tsx +++ b/src/components/Popover/index.tsx @@ -1,7 +1,7 @@ import { Options, Placement } from '@popperjs/core' import Portal from '@reach/portal' import useInterval from 'lib/hooks/useInterval' -import React, { useCallback, useMemo, useState } from 'react' +import React, { CSSProperties, useCallback, useMemo, useState } from 'react' import { usePopper } from 'react-popper' import styled from 'styled-components/macro' import { Z_INDEX } from 'theme/zIndex' @@ -76,9 +76,20 @@ export interface PopoverProps { show: boolean children: React.ReactNode placement?: Placement + offsetX?: number + offsetY?: number + style?: CSSProperties } -export default function Popover({ content, show, children, placement = 'auto' }: PopoverProps) { +export default function Popover({ + content, + show, + children, + placement = 'auto', + offsetX = 8, + offsetY = 8, + style, +}: PopoverProps) { const [referenceElement, setReferenceElement] = useState(null) const [popperElement, setPopperElement] = useState(null) const [arrowElement, setArrowElement] = useState(null) @@ -88,12 +99,12 @@ export default function Popover({ content, show, children, placement = 'auto' }: placement, strategy: 'fixed', modifiers: [ - { name: 'offset', options: { offset: [8, 8] } }, + { name: 'offset', options: { offset: [offsetX, offsetY] } }, { name: 'arrow', options: { element: arrowElement } }, { name: 'preventOverflow', options: { padding: 8 } }, ], }), - [arrowElement, placement] + [arrowElement, offsetX, offsetY, placement] ) const { styles, update, attributes } = usePopper(referenceElement, popperElement, options) @@ -105,7 +116,9 @@ export default function Popover({ content, show, children, placement = 'auto' }: return ( <> - {children} + + {children} + {content} diff --git a/src/components/Tooltip/index.tsx b/src/components/Tooltip/index.tsx index f97974053c..4d89226a3d 100644 --- a/src/components/Tooltip/index.tsx +++ b/src/components/Tooltip/index.tsx @@ -42,9 +42,10 @@ export function MouseoverTooltip({ text, disableHover, children, ...rest }: Omit const [show, setShow] = useState(false) const open = useCallback(() => setShow(true), [setShow]) const close = useCallback(() => setShow(false), [setShow]) + const noOp = () => null return ( -
+
{children}
diff --git a/src/nft/components/collection/Card.tsx b/src/nft/components/collection/Card.tsx index 9ae585f6da..8b5ca3c5c3 100644 --- a/src/nft/components/collection/Card.tsx +++ b/src/nft/components/collection/Card.tsx @@ -163,10 +163,19 @@ interface CardProps { addAssetToBag: () => void removeAssetFromBag: () => void children: ReactNode + isDisabled?: boolean onClick?: () => void } -const Container = ({ asset, selected, addAssetToBag, removeAssetFromBag, children, onClick }: CardProps) => { +const Container = ({ + asset, + selected, + addAssetToBag, + removeAssetFromBag, + children, + isDisabled, + onClick, +}: CardProps) => { const [hovered, toggleHovered] = useReducer((s) => !s, false) const [href, setHref] = useState(baseHref(asset)) @@ -210,8 +219,9 @@ const Container = ({ asset, selected, addAssetToBag, removeAssetFromBag, childre onMouseEnter={() => toggleHovered()} onMouseLeave={() => toggleHovered()} transition="250" - cursor={asset.notForSale ? 'default' : 'pointer'} - onClick={onClick ?? handleAssetInBag} + opacity={isDisabled ? '0.5' : '1'} + cursor={isDisabled ? 'default' : 'pointer'} + onClick={isDisabled ? () => null : onClick ?? handleAssetInBag} > {children} @@ -535,8 +545,14 @@ const ProfileNftDetails = ({ asset, isSellMode }: ProfileNftDetailsProps) => { {asset.susFlag && } - - {!!asset.floorPrice && isSellMode && {`${floorFormatter(asset.floorPrice)} ETH Floor`}} + + {!asset.notForSale && {`${floorFormatter(asset.floor_sell_order_price)} ETH`}} + {asset.notForSale && isSellMode && !!asset.floorPrice && ( + {`${floorFormatter(asset.floorPrice)} ETH Floor`} + )} ) diff --git a/src/nft/components/profile/view/ViewMyNftsAsset.tsx b/src/nft/components/profile/view/ViewMyNftsAsset.tsx index fd9bdf3bab..d349106c8e 100644 --- a/src/nft/components/profile/view/ViewMyNftsAsset.tsx +++ b/src/nft/components/profile/view/ViewMyNftsAsset.tsx @@ -1,10 +1,14 @@ +import { Trans } from '@lingui/macro' +import { MouseoverTooltip } from 'components/Tooltip' +import { Box } from 'nft/components/Box' import * as Card from 'nft/components/collection/Card' import { AssetMediaType } from 'nft/components/collection/Card' +import { bodySmall } from 'nft/css/common.css' +import { themeVars } from 'nft/css/sprinkles.css' import { useBag, useIsMobile, useSellAsset } from 'nft/hooks' import { WalletAsset } from 'nft/types' import { useMemo } from 'react' import { useNavigate } from 'react-router-dom' - const NFT_DETAILS_HREF = (asset: WalletAsset) => `/nfts/asset/${asset.asset_contract.address}/${asset.tokenId}?origin=profile` @@ -15,6 +19,21 @@ interface ViewMyNftsAssetProps { setCurrentTokenPlayingMedia: (tokenId: string | undefined) => void } +const getNftDisplayComponent = ( + assetMediaType: AssetMediaType, + mediaShouldBePlaying: boolean, + setCurrentTokenPlayingMedia: (tokenId: string | undefined) => void +) => { + switch (assetMediaType) { + case AssetMediaType.Image: + return + case AssetMediaType.Video: + return + case AssetMediaType.Audio: + return + } +} + export const ViewMyNftsAsset = ({ asset, isSellMode, @@ -53,6 +72,10 @@ export const ViewMyNftsAsset = ({ const assetMediaType = Card.useAssetMediaType(asset) + const isDisabled = asset.asset_contract.tokenType === 'ERC1155' || (isSellMode && asset.susFlag) + const disabledTooltipText = + asset.asset_contract.tokenType === 'ERC1155' ? 'ERC-1155 support coming soon' : 'Blocked from trading' + return ( handleSelect(false)} removeAssetFromBag={() => handleSelect(true)} onClick={onCardClick} + isDisabled={isDisabled} > - - {assetMediaType === AssetMediaType.Image ? ( - - ) : assetMediaType === AssetMediaType.Video ? ( - - ) : ( - - )} - + + {disabledTooltipText}{' '} + + } + placement="bottom" + offsetX={0} + offsetY={-100} + style={{ display: 'block' }} + disableHover={!isDisabled} + > + + {getNftDisplayComponent(assetMediaType, mediaShouldBePlaying, setCurrentTokenPlayingMedia)} + +