Skip to content

Commit

Permalink
fix contract calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa Anabella Rossi committed Sep 30, 2024
1 parent 6b1b3da commit 56171e6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FETCH_AUTHORIZATIONS_REQUEST } from 'decentraland-dapps/dist/modules/au
import { getLoading as getLoadingAuthorizations } from 'decentraland-dapps/dist/modules/authorization/selectors'
import { isLoadingType } from 'decentraland-dapps/dist/modules/loading/selectors'
import { getContract } from '../../../modules/contract/selectors'
import { getIsOffchainPublicNFTOrdersEnabled } from '../../../modules/features/selectors'
import { executeOrderRequest, executeOrderWithCardRequest, EXECUTE_ORDER_REQUEST, clearOrderErrors } from '../../../modules/order/actions'
import { getLoading as getLoadingOrders } from '../../../modules/order/selectors'
import { RootState } from '../../../modules/reducer'
Expand All @@ -16,7 +17,8 @@ const mapState = (state: RootState): MapStateProps => ({
isLoadingType(getLoadingAuthorizations(state), FETCH_AUTHORIZATIONS_REQUEST) ||
isLoadingType(getLoadingOrders(state), EXECUTE_ORDER_REQUEST),
isBuyWithCardPage: getIsBuyWithCardPage(state),
getContract: (query: Partial<Contract>) => getContract(state, query)
getContract: (query: Partial<Contract>) => getContract(state, query),
isOffchainPublicNFTOrdersEnabled: getIsOffchainPublicNFTOrdersEnabled(state)
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
Expand Down
10 changes: 7 additions & 3 deletions webapp/src/components/BuyPage/BuyNFTModal/BuyNFTModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AuthorizedAction } from 'decentraland-dapps/dist/containers/withAuthori
import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics/utils'
import { AuthorizationType } from 'decentraland-dapps/dist/modules/authorization/types'
import { T, t } from 'decentraland-dapps/dist/modules/translation/utils'
import { ContractName } from 'decentraland-transactions'
import { ContractName, getContract as getDCLContract } from 'decentraland-transactions'
import { Header, Button, Mana, Icon } from 'decentraland-ui'
import { AssetType } from '../../../modules/asset/types'
import { isWearableOrEmote } from '../../../modules/asset/utils'
Expand Down Expand Up @@ -42,6 +42,7 @@ const BuyNFTModal = (props: Props) => {
hasLowPrice,
isBuyWithCardPage,
isLoadingAuthorization,
isOffchainPublicNFTOrdersEnabled,
getContract,
onExecuteOrder,
onExecuteOrderWithCard,
Expand Down Expand Up @@ -80,6 +81,9 @@ const BuyNFTModal = (props: Props) => {
network: nft.network
}) as DCLContract

const offchainMarketplace =
isOffchainPublicNFTOrdersEnabled && order?.tradeId && getDCLContract(ContractName.OffChainMarketplace, nft.chainId)

const handleSubmit = useCallback(() => {
if (isBuyWithCardPage) {
handleExecuteOrder()
Expand All @@ -90,9 +94,9 @@ const BuyNFTModal = (props: Props) => {
onAuthorizedAction({
targetContractName: ContractName.MANAToken,
authorizationType: AuthorizationType.ALLOWANCE,
authorizedAddress: order.marketplaceAddress,
authorizedAddress: offchainMarketplace ? offchainMarketplace.address : order.marketplaceAddress,
targetContract: mana as Contract,
authorizedContractLabel: marketplace.label || marketplace.name,
authorizedContractLabel: offchainMarketplace ? offchainMarketplace.name : marketplace.label || marketplace.name,
requiredAllowanceInWei: order.price,
onAuthorized: handleExecuteOrder
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export type Props = {
hasInsufficientMANA: boolean
hasLowPrice: boolean
isBuyWithCardPage: boolean
isOffchainPublicNFTOrdersEnabled: boolean
getContract: (query: Partial<Contract>) => ReturnType<typeof getContract>
onExecuteOrder: typeof executeOrderRequest
onExecuteOrderWithCard: typeof executeOrderWithCardRequest
onClearOrderErrors: typeof clearOrderErrors
} & WithAuthorizedActionProps

export type MapStateProps = Pick<Props, 'isLoading' | 'getContract' | 'isBuyWithCardPage'>
export type MapStateProps = Pick<Props, 'isLoading' | 'getContract' | 'isBuyWithCardPage' | 'isOffchainPublicNFTOrdersEnabled'>
export type MapDispatchProps = Pick<Props, 'onExecuteOrder' | 'onExecuteOrderWithCard' | 'onClearOrderErrors'>
export type MapDispatch = Dispatch<ExecuteOrderRequestAction | ExecuteOrderWithCardRequestAction | ClearOrderErrorsAction>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Item } from '@dcl/schemas'
import { isLoadingType } from 'decentraland-dapps/dist/modules/loading'
import type { Route } from 'decentraland-transactions/crossChain'
import { getContract } from '../../../../modules/contract/selectors'
import { getIsOffchainPublicNFTOrdersEnabled } from '../../../../modules/features/selectors'
import { BUY_ITEM_CROSS_CHAIN_REQUEST, buyItemCrossChainRequest } from '../../../../modules/item/actions'
import { getLoading as getItemsLoading } from '../../../../modules/item/selectors'
import { EXECUTE_ORDER_REQUEST, executeOrderRequest, executeOrderWithCardRequest } from '../../../../modules/order/actions'
Expand All @@ -17,6 +18,7 @@ const mapState = (state: RootState): MapStateProps => {
return {
isExecutingOrder: isLoadingType(getLoadingOrders(state), EXECUTE_ORDER_REQUEST),
isExecutingOrderCrossChain: isLoadingType(getItemsLoading(state), BUY_ITEM_CROSS_CHAIN_REQUEST),
isOffchainPublicNFTOrdersEnabled: getIsOffchainPublicNFTOrdersEnabled(state),
getContract: (query: Partial<Contract>) => getContract(state, query)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import withAuthorizedAction from 'decentraland-dapps/dist/containers/withAuthori
import { AuthorizedAction } from 'decentraland-dapps/dist/containers/withAuthorizedAction/AuthorizationModal'
import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics'
import { AuthorizationType } from 'decentraland-dapps/dist/modules/authorization'
import { ContractName } from 'decentraland-transactions'
import { ContractName, getContract as getDCLContract } from 'decentraland-transactions'
import { useFingerprint } from '../../../../modules/nft/hooks'
import { getBuyItemStatus, getError } from '../../../../modules/order/selectors'
import { getContractNames } from '../../../../modules/vendor'
Expand All @@ -20,6 +20,7 @@ const BuyNftWithCryptoModalHOC = (props: Props) => {
name,
isExecutingOrder,
isExecutingOrderCrossChain,
isOffchainPublicNFTOrdersEnabled,
onClose,
isLoadingAuthorization,
getContract,
Expand All @@ -45,12 +46,15 @@ const BuyNftWithCryptoModalHOC = (props: Props) => {
network: nft.network
}) as DCLContract

const offchainMarketplace =
isOffchainPublicNFTOrdersEnabled && order?.tradeId && getDCLContract(ContractName.OffChainMarketplace, nft.chainId)

onAuthorizedAction({
targetContractName: ContractName.MANAToken,
authorizationType: AuthorizationType.ALLOWANCE,
authorizedAddress: order.marketplaceAddress,
authorizedAddress: offchainMarketplace ? offchainMarketplace.address : order.marketplaceAddress,
targetContract: mana as Contract,
authorizedContractLabel: marketplace.label || marketplace.name,
authorizedContractLabel: offchainMarketplace ? offchainMarketplace.name : marketplace.label || marketplace.name,
requiredAllowanceInWei: order.price,
onAuthorized: (alreadyAuthorized: boolean) => onExecuteOrder(order, nft, fingerprint, !alreadyAuthorized) // undefined as fingerprint
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export type Props = WithAuthorizedActionProps &
metadata: { nft: NFT; order: Order; slippage?: number }
isExecutingOrder: boolean
isExecutingOrderCrossChain: boolean
isOffchainPublicNFTOrdersEnabled: boolean
getContract: (query: Partial<Contract>) => ReturnType<typeof getContract>
onExecuteOrder: typeof executeOrderRequest
onExecuteOrderCrossChain: (route: Route) => unknown
onExecuteOrderWithCard: typeof executeOrderWithCardRequest
}

export type MapStateProps = Pick<Props, 'getContract' | 'isExecutingOrder' | 'isExecutingOrderCrossChain'>
export type MapStateProps = Pick<
Props,
'getContract' | 'isExecutingOrder' | 'isExecutingOrderCrossChain' | 'isOffchainPublicNFTOrdersEnabled'
>
export type MapDispatchProps = Pick<Props, 'onExecuteOrder' | 'onExecuteOrderCrossChain' | 'onExecuteOrderWithCard'>
export type OwnProps = Pick<Props, 'metadata'>

0 comments on commit 56171e6

Please sign in to comment.