Skip to content

Commit

Permalink
feat: add all contractIds for different flows
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Oct 28, 2024
1 parent c51bd41 commit 21096cc
Show file tree
Hide file tree
Showing 11 changed files with 1,713 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Authorization } from 'decentraland-dapps/dist/modules/authorization/typ
import { isLoadingType } from 'decentraland-dapps/dist/modules/loading/selectors'
import { upsertContracts } from '../../../modules/contract/actions'
import { getContract } from '../../../modules/contract/selectors'
import { getIsOffchainPublicNFTOrdersEnabled } from '../../../modules/features/selectors'
import { createOrderRequest, CREATE_ORDER_REQUEST, cancelOrderRequest, CANCEL_ORDER_REQUEST } from '../../../modules/order/actions'
import { getLoading as getLoadingOrders } from '../../../modules/order/selectors'
import { RootState } from '../../../modules/reducer'
Expand All @@ -26,7 +27,8 @@ const mapState = (state: RootState): MapStateProps => {
authorizations: getAuthorizations(state),
isCreatingOrder: isLoadingType(getLoadingOrders(state), CREATE_ORDER_REQUEST),
isAuthorizing: isLoadingType(getLoading(state), GRANT_TOKEN_REQUEST) || isLoadingType(getLoading(state), REVOKE_TOKEN_REQUEST),
isCancelling: isLoadingType(getLoading(state), CANCEL_ORDER_REQUEST)
isCancelling: isLoadingType(getLoading(state), CANCEL_ORDER_REQUEST),
isOffchainPublicNFTOrdersEnabled: getIsOffchainPublicNFTOrdersEnabled(state)
}
}

Expand Down
9 changes: 7 additions & 2 deletions webapp/src/components/Modals/SellModal/SellModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { toFixedMANAValue } from 'decentraland-dapps/dist/lib/mana'
import { AuthorizationType, Authorization as Authorizations } from 'decentraland-dapps/dist/modules/authorization/types'
import { hasAuthorization } from 'decentraland-dapps/dist/modules/authorization/utils'
import { T, t } from 'decentraland-dapps/dist/modules/translation/utils'
import { ContractName } from 'decentraland-transactions'
import { ContractName, getContract as getDecentralandContract } from 'decentraland-transactions'
import { Button, Field, Loader, Mana, Message, ModalNavigation } from 'decentraland-ui'
import { useAuthorization } from '../../../lib/authorization'
import { formatWeiMANA, parseMANANumber } from '../../../lib/mana'
Expand Down Expand Up @@ -43,6 +43,7 @@ const SellModal = ({
error,
onFetchAuthorizations,
isCancelling,
isOffchainPublicNFTOrdersEnabled,
onCancelOrder
}: Props) => {
const { orderService } = VendorFactory.build(nft.vendor)
Expand Down Expand Up @@ -83,9 +84,13 @@ const SellModal = ({
network: nft.network
})

const offchainOrdersContract = isOffchainPublicNFTOrdersEnabled
? getDecentralandContract(ContractName.OffChainMarketplace, nft.chainId)
: null

const authorization: Authorizations = {
address: wallet?.address || '',
authorizedAddress: marketplace!.address,
authorizedAddress: !!offchainOrdersContract && isOffchainPublicNFTOrdersEnabled ? offchainOrdersContract.address : marketplace!.address,
contractAddress: nft.contractAddress,
contractName:
(nft.category === NFTCategory.WEARABLE || nft.category === NFTCategory.EMOTE) && nft.network === Network.MATIC
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/Modals/SellModal/SellModal.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Props = Omit<ModalProps, 'metadata'> & {
authorizations: Authorization[]
isCreatingOrder: boolean
isAuthorizing: boolean
isOffchainPublicNFTOrdersEnabled: boolean
onFetchAuthorizations: typeof fetchAuthorizationsRequest
onUpsertContracts: typeof upsertContracts
onCancelOrder: typeof cancelOrderRequest
Expand All @@ -34,7 +35,14 @@ export type OwnProps = Pick<Props, 'metadata'>

export type MapStateProps = Pick<
Props,
'authorizations' | 'wallet' | 'isCreatingOrder' | 'error' | 'getContract' | 'isAuthorizing' | 'isCancelling'
| 'authorizations'
| 'wallet'
| 'isCreatingOrder'
| 'error'
| 'getContract'
| 'isAuthorizing'
| 'isCancelling'
| 'isOffchainPublicNFTOrdersEnabled'
>

export type MapDispatchProps = Pick<Props, 'onCreateOrder' | 'onFetchAuthorizations' | 'onUpsertContracts' | 'onCancelOrder'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { getData as getAuthorizations, getLoading } from 'decentraland-dapps/dist/modules/authorization/selectors'
import { areEqual } from 'decentraland-dapps/dist/modules/authorization/utils'
import { getContract } from '../../../modules/contract/selectors'
import { getIsOffchainPublicNFTOrdersEnabled } from '../../../modules/features/selectors'
import { RootState } from '../../../modules/reducer'
import { getPendingAuthorizationTransactions } from '../../../modules/transaction/selectors'
import { hasTransactionPending } from '../../../modules/transaction/utils'
Expand All @@ -35,7 +36,8 @@ const mapState = (state: RootState, { authorization }: OwnProps): MapStateProps
authorizations,
pendingTransactions,
isLoading: isLoading || hasTransactionPending(pendingTransactions, authorizedAddress, contractAddress),
getContract: (query: Partial<Contract>) => getContract(state, query)
getContract: (query: Partial<Contract>) => getContract(state, query),
isOffchainPublicNFTOrdersEnabled: getIsOffchainPublicNFTOrdersEnabled(state)
}
}

Expand Down
16 changes: 14 additions & 2 deletions webapp/src/components/SettingsPage/Authorization/Authorization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ import { ChainCheck, TransactionLink } from 'decentraland-dapps/dist/containers'
import { getChainConfiguration } from 'decentraland-dapps/dist/lib/chainConfiguration'
import { AuthorizationType } from 'decentraland-dapps/dist/modules/authorization/types'
import { t, T } from 'decentraland-dapps/dist/modules/translation/utils'
import { ContractName, getContract as getDecentralandContract } from 'decentraland-transactions'
import { Form, Radio, Loader, Popup, RadioProps } from 'decentraland-ui'
import { isAuthorized } from '../../../lib/authorization'
import { locations } from '../../../modules/routing/locations'
import { Props } from './Authorization.types'
import './Authorization.css'

const Authorization = (props: Props) => {
const { authorization, authorizations, shouldUpdateSpendingCap, isLoading, onGrant, onRevoke, getContract } = props
const {
authorization,
authorizations,
shouldUpdateSpendingCap,
isLoading,
isOffchainPublicNFTOrdersEnabled,
onGrant,
onRevoke,
getContract
} = props

const handleOnChange = useCallback(
(isChecked: boolean) => {
Expand All @@ -39,7 +49,9 @@ const Authorization = (props: Props) => {

const { contractAddress, authorizedAddress } = authorization

const contract = getContract({ address: authorizedAddress })
const contract = isOffchainPublicNFTOrdersEnabled
? getDecentralandContract(ContractName.OffChainMarketplace, authorization.chainId)
: getContract({ address: authorizedAddress })
const token = getContract({ address: contractAddress })

if (!contract || !token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export type Props = {
authorizations: Authorization[]
pendingTransactions: Transaction[]
isLoading: boolean
isOffchainPublicNFTOrdersEnabled: boolean
shouldUpdateSpendingCap?: boolean
getContract: (query: Partial<Contract>) => ReturnType<typeof getContract>
onGrant: typeof grantTokenRequest
onRevoke: typeof revokeTokenRequest
}

export type OwnProps = Pick<Props, 'authorization'>
export type MapStateProps = Pick<Props, 'authorizations' | 'pendingTransactions' | 'isLoading' | 'getContract'>
export type MapStateProps = Pick<
Props,
'authorizations' | 'pendingTransactions' | 'isLoading' | 'getContract' | 'isOffchainPublicNFTOrdersEnabled'
>
export type MapDispatchProps = Pick<Props, 'onGrant' | 'onRevoke'>
export type MapDispatch = Dispatch<GrantTokenRequestAction | RevokeTokenRequestAction>
Loading

0 comments on commit 21096cc

Please sign in to comment.