From 6fb58a88ceb301612cc8639ccb30cc87e4fb1aaa Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 20 Mar 2024 15:06:21 +0100 Subject: [PATCH 1/9] feat: add buy with crypto button to ENS detail page --- .../AssetPage/Actions/Actions.container.ts | 14 +++++++++++--- .../components/AssetPage/Actions/Actions.tsx | 19 ++++++++++++------- .../AssetPage/Actions/Actions.types.ts | 3 ++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/webapp/src/components/AssetPage/Actions/Actions.container.ts b/webapp/src/components/AssetPage/Actions/Actions.container.ts index 602bdd3747..977cb7df95 100644 --- a/webapp/src/components/AssetPage/Actions/Actions.container.ts +++ b/webapp/src/components/AssetPage/Actions/Actions.container.ts @@ -1,4 +1,5 @@ import { connect } from 'react-redux' +import { Order } from '@dcl/schemas' import { openModal } from 'decentraland-dapps/dist/modules/modal/actions' import { NFT } from '../../../modules/nft/types' import { getCurrentOrder } from '../../../modules/order/selectors' @@ -6,7 +7,7 @@ import { RootState } from '../../../modules/reducer' import { getNFTBids } from '../../../modules/ui/nft/bid/selectors' import { getWallet } from '../../../modules/wallet/selectors' import Actions from './Actions' -import { MapDispatch, MapDispatchProps, MapStateProps } from './Actions.types' +import { MapDispatch, MapDispatchProps, MapStateProps, OwnProps } from './Actions.types' const mapState = (state: RootState): MapStateProps => ({ wallet: getWallet(state), @@ -14,8 +15,15 @@ const mapState = (state: RootState): MapStateProps => ({ bids: getNFTBids(state) }) -const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({ - onLeavingSite: (nft: NFT) => dispatch(openModal('LeavingSiteModal', { nft })) +const mapDispatch = (dispatch: MapDispatch, ownProps: OwnProps): MapDispatchProps => ({ + onLeavingSite: (nft: NFT) => dispatch(openModal('LeavingSiteModal', { nft })), + onBuyWithCrypto: (order: Order) => + dispatch( + openModal('BuyNftWithCryptoModal', { + nft: ownProps.nft, + order + }) + ) }) export default connect(mapState, mapDispatch)(Actions) diff --git a/webapp/src/components/AssetPage/Actions/Actions.tsx b/webapp/src/components/AssetPage/Actions/Actions.tsx index c5108d5f94..23e1a2578d 100644 --- a/webapp/src/components/AssetPage/Actions/Actions.tsx +++ b/webapp/src/components/AssetPage/Actions/Actions.tsx @@ -1,17 +1,18 @@ import React from 'react' import { Link } from 'react-router-dom' -import { t } from 'decentraland-dapps/dist/modules/translation/utils' +import { NFTCategory } from '@dcl/schemas' import { Button } from 'decentraland-ui' -import { builderUrl } from '../../../lib/environment' -import { AssetType } from '../../../modules/asset/types' +import { t } from 'decentraland-dapps/dist/modules/translation/utils' +import { BuyWithCryptoButton } from '../SaleActionBox/BuyNFTButtons/BuyWithCryptoButton' import { isOwnedBy } from '../../../modules/asset/utils' import { locations } from '../../../modules/routing/locations' import { VendorFactory } from '../../../modules/vendor' import { Props } from './Actions.types' +import { builderUrl } from '../../../lib/environment' import styles from './Actions.module.css' const Actions = (props: Props) => { - const { wallet, nft, order, bids, onLeavingSite } = props + const { wallet, nft, order, bids, onLeavingSite, onBuyWithCrypto } = props const { contractAddress, tokenId, data } = nft const { bidService, orderService } = VendorFactory.build(nft.vendor) @@ -37,9 +38,13 @@ const Actions = (props: Props) => { ) : !isOwner ? ( <> - + {nft.category === NFTCategory.ENS ? ( + onBuyWithCrypto} /> + ) : ( + + )} {canBid ? ( - )} + onBuyWithCrypto} /> {canBid ? ( ) : null}
- {order ? ( - isCrossChainLandEnabled ? ( - - ) : ( - - ) - ) : null} + {order ? : null} {canBid ? ( { - const { type } = props - - const isInsufficientMANA = (wallet: Wallet, network: Network.ETHEREUM | Network.MATIC, price: string) => - wallet.networks[network].mana < +ethers.utils.formatEther(price) - - return ( - <> - - - - {wallet => ( - - {(asset, order) => { - const network = (order || asset)?.network - const price = type === AssetType.ITEM ? (asset as Item).price : order ? order.price : '' - - const modalProps = { - wallet: wallet, - isOwner: isOwnedBy(asset, wallet), - hasInsufficientMANA: isInsufficientMANA(wallet, network, price), - hasLowPrice: wallet.chainId !== asset.chainId && isPriceTooLow(price) - } - - return type === AssetType.NFT ? ( - - ) : type === AssetType.ITEM ? ( - - ) : null - }} - - )} - - -