From 654220ebae403fc19733a03180568c7870526cce Mon Sep 17 00:00:00 2001 From: LautaroPetaccio Date: Fri, 7 Feb 2025 17:55:23 -0300 Subject: [PATCH 1/2] feat: Add off chain marketplace to contract settings --- .../components/SettingsPage/SettingsPage.tsx | 32 ++++++++++++++++++ webapp/src/modules/contract/sagas.ts | 32 ++++++++++++++++++ .../modules/vendor/decentraland/contracts.ts | 33 +++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/webapp/src/components/SettingsPage/SettingsPage.tsx b/webapp/src/components/SettingsPage/SettingsPage.tsx index 22b8dfff9..6d516326d 100644 --- a/webapp/src/components/SettingsPage/SettingsPage.tsx +++ b/webapp/src/components/SettingsPage/SettingsPage.tsx @@ -44,6 +44,16 @@ const SettingsPage = (props: Props) => { network: Network.MATIC }) + const offChainMarketplaceEthereum = getContract({ + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.ETHEREUM + }) + + const offChainMarketplaceMatic = getContract({ + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.MATIC + }) + const bidsEthereum = getContract({ name: contractNames.BIDS, network: Network.ETHEREUM @@ -75,6 +85,8 @@ const SettingsPage = (props: Props) => { !collectionStore || !marketplaceEthereum || !marketplaceMatic || + !offChainMarketplaceEthereum || + !offChainMarketplaceMatic || !bidsEthereum || !bidsMatic || !manaEthereum || @@ -180,6 +192,26 @@ const SettingsPage = (props: Props) => { type: AuthorizationType.ALLOWANCE }} /> + + + const offChainMarketplaceEthereum: Contract | null = (yield select(getContract, { + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.ETHEREUM + })) as ReturnType + + const offChainMarketplaceMatic: Contract | null = (yield select(getContract, { + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.MATIC + })) as ReturnType + const legacyMarketplaceMatic: Contract | null = (yield select(getContract, { name: contractNames.LEGACY_MARKETPLACE, network: Network.MATIC @@ -116,6 +126,17 @@ export function* handleFetchContractsSuccess() { }) } + if (offChainMarketplaceEthereum && manaEthereum) { + authorizations.push({ + address, + authorizedAddress: offChainMarketplaceEthereum.address, + contractAddress: manaEthereum.address, + contractName: ContractName.MANAToken, + chainId: manaEthereum.chainId, + type: AuthorizationType.ALLOWANCE + }) + } + if (marketplaceMatic && manaMatic) { authorizations.push({ address, @@ -138,6 +159,17 @@ export function* handleFetchContractsSuccess() { }) } + if (offChainMarketplaceMatic && manaMatic) { + authorizations.push({ + address, + authorizedAddress: offChainMarketplaceMatic.address, + contractAddress: manaMatic.address, + contractName: ContractName.MANAToken, + chainId: manaMatic.chainId, + type: AuthorizationType.ALLOWANCE + }) + } + if (bidsEthereum && manaEthereum) { authorizations.push({ address, diff --git a/webapp/src/modules/vendor/decentraland/contracts.ts b/webapp/src/modules/vendor/decentraland/contracts.ts index 09b812dc0..38c9da91f 100644 --- a/webapp/src/modules/vendor/decentraland/contracts.ts +++ b/webapp/src/modules/vendor/decentraland/contracts.ts @@ -7,6 +7,7 @@ export const LEGACY_MARKETPLACE_MAINNET_CONTRACT = '0xb3bca6f5052c7e24726b44da74 export enum ContractName { MANA = 'MANA', MARKETPLACE = 'Marketplace', + OFF_CHAIN_MARKETPLACE = 'OffChainMarketplace', LEGACY_MARKETPLACE = 'LegacyMarketplace', BIDS = 'Bids', COLLECTION_STORE = 'CollectionStore', @@ -466,6 +467,14 @@ const localContracts = { network: Network.ETHEREUM, chainId: ChainId.ETHEREUM_SEPOLIA }, + { + name: ContractName.OFF_CHAIN_MARKETPLACE, + address: getContract(CN.OffChainMarketplace, ChainId.ETHEREUM_SEPOLIA).address, + vendor: 'decentraland', + category: null, + network: Network.ETHEREUM, + chainId: ChainId.ETHEREUM_SEPOLIA + }, { name: ContractName.BIDS, address: getContract(CN.Bid, ChainId.ETHEREUM_SEPOLIA).address, @@ -499,6 +508,14 @@ const localContracts = { network: Network.MATIC, chainId: ChainId.MATIC_AMOY }, + { + name: ContractName.OFF_CHAIN_MARKETPLACE, + address: getContract(CN.OffChainMarketplace, ChainId.MATIC_AMOY).address, + vendor: 'decentraland', + category: null, + network: Network.MATIC, + chainId: ChainId.MATIC_AMOY + }, { name: ContractName.LEGACY_MARKETPLACE, address: getContract(CN.Marketplace, ChainId.MATIC_MUMBAI).address, @@ -618,6 +635,14 @@ const localContracts = { network: Network.ETHEREUM, chainId: ChainId.ETHEREUM_MAINNET }, + { + name: ContractName.OFF_CHAIN_MARKETPLACE, + address: getContract(CN.OffChainMarketplace, ChainId.ETHEREUM_MAINNET).address, + vendor: 'decentraland', + category: null, + network: Network.ETHEREUM, + chainId: ChainId.ETHEREUM_MAINNET + }, { name: ContractName.BIDS, address: getContract(CN.Bid, ChainId.ETHEREUM_MAINNET).address, @@ -650,6 +675,14 @@ const localContracts = { network: Network.MATIC, chainId: ChainId.MATIC_MAINNET }, + { + name: ContractName.OFF_CHAIN_MARKETPLACE, + address: getContract(CN.OffChainMarketplace, ChainId.MATIC_MAINNET).address, + vendor: 'decentraland', + category: null, + network: Network.MATIC, + chainId: ChainId.MATIC_MAINNET + }, { name: ContractName.LEGACY_MARKETPLACE, address: getContract(CN.Marketplace, ChainId.MATIC_MAINNET).address, From 9a19a593f1a36926d411e3d500c9eadb29c62040 Mon Sep 17 00:00:00 2001 From: LautaroPetaccio Date: Sat, 8 Feb 2025 15:16:05 -0300 Subject: [PATCH 2/2] fix: Tests --- webapp/src/modules/contract/sagas.spec.ts | 48 +++++++++++++++++++++++ webapp/src/modules/contract/sagas.ts | 38 ++++++++---------- 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/webapp/src/modules/contract/sagas.spec.ts b/webapp/src/modules/contract/sagas.spec.ts index e70f3517c..50db680cd 100644 --- a/webapp/src/modules/contract/sagas.spec.ts +++ b/webapp/src/modules/contract/sagas.spec.ts @@ -60,6 +60,24 @@ describe('when handling the fetch contracts request', () => { vendor: VendorName.DECENTRALAND } + const offChainMarketplaceEthereum: Contract = { + address: 'offChainMarketplaceEthereumAddress', + category: null, + chainId: ChainId.ETHEREUM_MAINNET, + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.ETHEREUM, + vendor: VendorName.DECENTRALAND + } + + const offChainMarketplaceMatic: Contract = { + address: 'offChainMarketplaceMaticAddress', + category: null, + chainId: ChainId.MATIC_MAINNET, + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.MATIC, + vendor: VendorName.DECENTRALAND + } + const legacyMarketplace: Contract = { address: 'legacyMarketplaceAddress', category: null, @@ -142,6 +160,20 @@ describe('when handling the fetch contracts request', () => { }), marketplaceMatic ], + [ + select(getContract, { + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.ETHEREUM + }), + offChainMarketplaceEthereum + ], + [ + select(getContract, { + name: contractNames.OFF_CHAIN_MARKETPLACE, + network: Network.MATIC + }), + offChainMarketplaceMatic + ], [ select(getContract, { name: contractNames.LEGACY_MARKETPLACE, @@ -208,6 +240,22 @@ describe('when handling the fetch contracts request', () => { .put(fetchContractsSuccess([])) .put( fetchAuthorizationsRequest([ + { + address, + authorizedAddress: offChainMarketplaceEthereum.address, + contractAddress: manaEthereum.address, + contractName: ContractName.MANAToken, + chainId: ChainId.ETHEREUM_GOERLI, + type: AuthorizationType.ALLOWANCE + }, + { + address, + authorizedAddress: offChainMarketplaceMatic.address, + contractAddress: manaMatic.address, + contractName: ContractName.MANAToken, + chainId: ChainId.MATIC_AMOY, + type: AuthorizationType.ALLOWANCE + }, { address, authorizedAddress: marketplaceEthereum.address, diff --git a/webapp/src/modules/contract/sagas.ts b/webapp/src/modules/contract/sagas.ts index 0e82bf443..341cc6153 100644 --- a/webapp/src/modules/contract/sagas.ts +++ b/webapp/src/modules/contract/sagas.ts @@ -18,8 +18,7 @@ import { getAuthorizationKey } from './utils' export function* contractSaga() { yield takeEvery(FETCH_CONTRACTS_REQUEST, handleFetchContractsRequest) yield takeEvery(FETCH_CONTRACTS_SUCCESS, handleFetchContractsSuccess) - yield takeEvery(CHANGE_ACCOUNT, handleChangeAccount) - yield takeEvery(CONNECT_WALLET_SUCCESS, handleConnectWalletSuccess) + yield takeEvery([CHANGE_ACCOUNT, CONNECT_WALLET_SUCCESS], handleWalletChange) yield takeEvery(FETCH_TRANSACTION_SUCCESS, handleFetchTransactionSuccess) } @@ -115,10 +114,10 @@ export function* handleFetchContractsSuccess() { let authorizations: Authorization[] = [] - if (marketplaceEthereum && manaEthereum) { + if (offChainMarketplaceEthereum && manaEthereum) { authorizations.push({ address, - authorizedAddress: marketplaceEthereum.address, + authorizedAddress: offChainMarketplaceEthereum.address, contractAddress: manaEthereum.address, contractName: ContractName.MANAToken, chainId: manaEthereum.chainId, @@ -126,32 +125,32 @@ export function* handleFetchContractsSuccess() { }) } - if (offChainMarketplaceEthereum && manaEthereum) { + if (offChainMarketplaceMatic && manaMatic) { authorizations.push({ address, - authorizedAddress: offChainMarketplaceEthereum.address, - contractAddress: manaEthereum.address, + authorizedAddress: offChainMarketplaceMatic.address, + contractAddress: manaMatic.address, contractName: ContractName.MANAToken, - chainId: manaEthereum.chainId, + chainId: manaMatic.chainId, type: AuthorizationType.ALLOWANCE }) } - if (marketplaceMatic && manaMatic) { + if (marketplaceEthereum && manaEthereum) { authorizations.push({ address, - authorizedAddress: marketplaceMatic.address, - contractAddress: manaMatic.address, + authorizedAddress: marketplaceEthereum.address, + contractAddress: manaEthereum.address, contractName: ContractName.MANAToken, - chainId: manaMatic.chainId, + chainId: manaEthereum.chainId, type: AuthorizationType.ALLOWANCE }) } - if (legacyMarketplaceMatic && manaMatic) { + if (marketplaceMatic && manaMatic) { authorizations.push({ address, - authorizedAddress: legacyMarketplaceMatic.address, + authorizedAddress: marketplaceMatic.address, contractAddress: manaMatic.address, contractName: ContractName.MANAToken, chainId: manaMatic.chainId, @@ -159,10 +158,10 @@ export function* handleFetchContractsSuccess() { }) } - if (offChainMarketplaceMatic && manaMatic) { + if (legacyMarketplaceMatic && manaMatic) { authorizations.push({ address, - authorizedAddress: offChainMarketplaceMatic.address, + authorizedAddress: legacyMarketplaceMatic.address, contractAddress: manaMatic.address, contractName: ContractName.MANAToken, chainId: manaMatic.chainId, @@ -265,15 +264,10 @@ export function* handleFetchContractsSuccess() { ) authorizations = authorizations.filter(authorization => !storeAuthorizationsMap.has(getAuthorizationKey(authorization))) - yield put(fetchAuthorizationsRequest(authorizations)) } -function* handleChangeAccount() { - yield put(resetHasFetched()) -} - -function* handleConnectWalletSuccess() { +function* handleWalletChange() { yield put(resetHasFetched()) }