handleOnChange(!!props.checked)}
- />
+
+ {isEnabled => handleOnChange(!!props.checked)}
+ />}
+
{
>
{t('global.cancel')}
-
+
diff --git a/webapp/src/components/UserMenu/UserMenu.tsx b/webapp/src/components/UserMenu/UserMenu.tsx
index 8244f86449..effb0d30a6 100644
--- a/webapp/src/components/UserMenu/UserMenu.tsx
+++ b/webapp/src/components/UserMenu/UserMenu.tsx
@@ -1,8 +1,9 @@
import React from 'react'
import { UserMenu as BaseUserMenu } from 'decentraland-dapps/dist/containers'
import { IntroPopup } from '../IntroPopup'
+import { Props } from './UserMenu.types'
-export default class UserMenu extends React.PureComponent {
+export default class UserMenu extends React.PureComponent {
render() {
return (
<>
diff --git a/webapp/src/modules/item/sagas.spec.ts b/webapp/src/modules/item/sagas.spec.ts
index 6e523bcb6c..4ab891396b 100644
--- a/webapp/src/modules/item/sagas.spec.ts
+++ b/webapp/src/modules/item/sagas.spec.ts
@@ -1,13 +1,8 @@
import { expectSaga } from 'redux-saga-test-plan'
-import { Address } from 'web3x-es/address'
-import { getWallet } from '../wallet/selectors'
import * as matchers from 'redux-saga-test-plan/matchers'
import { ChainId, Item } from '@dcl/schemas'
import { call, select } from 'redux-saga/effects'
-import { ContractName, getContract } from 'decentraland-transactions'
-import { CollectionStore } from '../../contracts/CollectionStore'
-import { ContractFactory } from '../contract/ContractFactory'
-import { sendTransaction } from '../wallet/utils'
+import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import {
buyItemRequest,
buyItemFailure,
@@ -19,10 +14,10 @@ import {
fetchItemRequest,
fetchItemFailure
} from './actions'
-import { itemSaga } from './sagas'
-import { TxSend } from 'web3x-es/contract'
+import { getWallet } from '../wallet/selectors'
import { View } from '../ui/types'
import { itemAPI } from '../vendor/decentraland/item/api'
+import { itemSaga } from './sagas'
const item = {
itemId: 'anItemId',
@@ -35,15 +30,6 @@ const wallet = {
address: '0x32be343b94f860124dc4fee278fdcbd38c102d88'
}
-const collectionStoreContractConfig = getContract(
- ContractName.CollectionStore,
- item.chainId
-)
-const collectionStoreContract = new CollectionStore(
- jest.fn() as any,
- Address.fromString(collectionStoreContractConfig.address)
-)
-
const txHash =
'0x9fc518261399c1bd236997706347f8b117a061cef5518073b1c3eefd5efbff84'
@@ -66,28 +52,11 @@ describe('when handling the buy items request action', () => {
})
})
- describe("when there's an error while building the store contract", () => {
- it('should dispatch an action signaling the failure of the action handling', () => {
- return expectSaga(itemSaga)
- .provide([
- [select(getWallet), wallet],
- [matchers.call.fn(ContractFactory.build), Promise.reject(anError)]
- ])
- .put(buyItemFailure(anError.message))
- .dispatch(buyItemRequest(item))
- .run({ silenceTimeout: true })
- })
- })
-
describe('when sending the meta transaction fails', () => {
it('should dispatch an action signaling the failure of the action handling', () => {
return expectSaga(itemSaga)
.provide([
[select(getWallet), wallet],
- [
- matchers.call.fn(ContractFactory.build),
- Promise.resolve(collectionStoreContract)
- ],
[matchers.call.fn(sendTransaction), Promise.reject(anError)]
])
.put(buyItemFailure(anError.message))
@@ -97,38 +66,11 @@ describe('when handling the buy items request action', () => {
})
describe('when the meta transaction is sent succesfully', () => {
- const buyTransactionParameters = [
- {
- collection: Address.fromString(item.contractAddress),
- ids: [item.itemId],
- prices: [item.price],
- beneficiaries: [Address.fromString(wallet.address)]
- }
- ]
-
- const txBuy = {} as TxSend
-
it('should send a meta transaction to the collection store contract living in the chain provided by the item and dispatch the success action', () => {
return expectSaga(itemSaga)
.provide([
[select(getWallet), wallet],
- [
- matchers.call.fn(ContractFactory.build),
- Promise.resolve(collectionStoreContract)
- ],
- [
- call(collectionStoreContract.methods.buy, buyTransactionParameters),
- txBuy
- ],
- [
- call(
- sendTransaction,
- txBuy,
- collectionStoreContractConfig,
- Address.fromString(wallet.address)
- ),
- Promise.resolve(txHash)
- ]
+ [matchers.call.fn(sendTransaction), Promise.resolve(txHash)]
])
.put(buyItemSuccess(item.chainId, txHash, item))
.dispatch(buyItemRequest(item))
diff --git a/webapp/src/modules/item/sagas.ts b/webapp/src/modules/item/sagas.ts
index c96e308533..41ac584c07 100644
--- a/webapp/src/modules/item/sagas.ts
+++ b/webapp/src/modules/item/sagas.ts
@@ -1,16 +1,9 @@
import { Item } from '@dcl/schemas'
import { put, takeEvery } from '@redux-saga/core/effects'
-import {
- ContractData,
- ContractName,
- getContract
-} from 'decentraland-transactions'
+import { ContractName, getContract } from 'decentraland-transactions'
+import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import { call, select } from 'redux-saga/effects'
-import {
- CollectionStore,
- CollectionStoreTransactionReceipt
-} from '../../contracts/CollectionStore'
-import { ContractFactory } from '../contract/ContractFactory'
+import { push } from 'connected-react-router'
import { itemAPI } from '../vendor/decentraland/item/api'
import { getWallet } from '../wallet/selectors'
import {
@@ -28,10 +21,6 @@ import {
FETCH_ITEM_REQUEST,
BUY_ITEM_SUCCESS
} from './actions'
-import { Address } from 'web3x-es/address'
-import { sendTransaction } from '../wallet/utils'
-import { TxSend } from 'web3x-es/contract'
-import { push } from 'connected-react-router'
import { locations } from '../routing/locations'
export function* itemSaga() {
@@ -79,33 +68,15 @@ function* handleBuyItem(action: BuyItemRequestAction) {
throw new Error('A defined wallet is required to buy an item')
}
- const collectionStoreContractConfig: ContractData = getContract(
- ContractName.CollectionStore,
- item.chainId
- )
- const collectionStoreContract: CollectionStore = yield call(
- [ContractFactory, 'build'],
- CollectionStore,
- collectionStoreContractConfig.address
- )
-
- const txBuy: TxSend = yield call(
- collectionStoreContract.methods.buy,
- [
- {
- collection: Address.fromString(item.contractAddress),
- ids: [item.itemId],
- prices: [item.price],
- beneficiaries: [Address.fromString(wallet.address)]
- }
- ]
- )
+ const contract = getContract(ContractName.CollectionStore, item.chainId)
const txHash: string = yield call(
sendTransaction,
- txBuy,
- collectionStoreContractConfig,
- Address.fromString(wallet.address)
+ contract,
+ collectionStore =>
+ collectionStore.buy([
+ [item.contractAddress, [item.itemId], [item.price], [wallet.address]]
+ ])
)
yield put(buyItemSuccess(item.chainId, txHash, item))
diff --git a/webapp/src/modules/sagas.ts b/webapp/src/modules/sagas.ts
index ec35eb833a..03aaeae4f6 100644
--- a/webapp/src/modules/sagas.ts
+++ b/webapp/src/modules/sagas.ts
@@ -1,5 +1,5 @@
import { all } from 'redux-saga/effects'
-import { createAuthorizationSaga } from 'decentraland-dapps/dist/modules/authorization/sagas'
+import { authorizationSaga } from 'decentraland-dapps/dist/modules/authorization/sagas'
import { createAnalyticsSaga } from 'decentraland-dapps/dist/modules/analytics/sagas'
import { createProfileSaga } from 'decentraland-dapps/dist/modules/profile/sagas'
import { transactionSaga } from 'decentraland-dapps/dist/modules/transaction/sagas'
@@ -16,15 +16,10 @@ import { uiSaga } from './ui/sagas'
import { walletSaga } from './wallet/sagas'
import { itemSaga } from './item/sagas'
-import { TRANSACTIONS_API_URL } from './wallet/utils'
-
const analyticsSaga = createAnalyticsSaga()
const profileSaga = createProfileSaga({
peerUrl: process.env.REACT_APP_PEER_URL!
})
-const authorizationSaga = createAuthorizationSaga({
- metaTransactionServerUrl: TRANSACTIONS_API_URL
-})
export function* rootSaga() {
yield all([
diff --git a/webapp/src/modules/vendor/decentraland/NFTService.ts b/webapp/src/modules/vendor/decentraland/NFTService.ts
index 5b349ecf0e..37c9c9e277 100644
--- a/webapp/src/modules/vendor/decentraland/NFTService.ts
+++ b/webapp/src/modules/vendor/decentraland/NFTService.ts
@@ -1,15 +1,12 @@
-import { Address } from 'web3x-es/address'
import { Network } from '@dcl/schemas'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
+import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import {
ContractData,
ContractName,
getContract
} from 'decentraland-transactions'
-import { ERC721 } from '../../../contracts/ERC721'
-import { ContractFactory } from '../../contract/ContractFactory'
import { NFT, NFTsFetchParams, NFTsCountParams } from '../../nft/types'
-import { sendTransaction } from '../../wallet/utils'
import { Account } from '../../account/types'
import ERC721Abi from '../../../contracts/ERC721Abi'
import { NFTService as NFTServiceInterface } from '../services'
@@ -56,14 +53,11 @@ export class NFTService
return [nft, response.order || undefined] as const
}
- async transfer(wallet: Wallet | null, toAddress: string, nft: NFT) {
+ async transfer(wallet: Wallet | null, to: string, nft: NFT) {
if (!wallet) {
throw new Error('Invalid address. Wallet must be connected.')
}
- const from = Address.fromString(wallet.address)
- const to = Address.fromString(toAddress)
- const erc721 = await ContractFactory.build(ERC721, nft.contractAddress)
const contract: ContractData =
nft.network !== Network.ETHEREUM
? {
@@ -78,8 +72,9 @@ export class NFTService
version: '1'
}
- const transferFrom = erc721.methods.transferFrom(from, to, nft.tokenId)
- return sendTransaction(transferFrom, contract, from)
+ return sendTransaction(contract, erc721 =>
+ erc721.transferFrom(wallet.address, to, nft.tokenId)
+ )
}
toAccount(address: string): Account {
diff --git a/webapp/src/modules/vendor/decentraland/OrderService.ts b/webapp/src/modules/vendor/decentraland/OrderService.ts
index 18eb73b356..cc7d987528 100644
--- a/webapp/src/modules/vendor/decentraland/OrderService.ts
+++ b/webapp/src/modules/vendor/decentraland/OrderService.ts
@@ -1,15 +1,12 @@
-import { Address } from 'web3x-es/address'
-import { toWei } from 'web3x-es/utils'
+import { utils } from 'ethers'
import { ContractName, getContract } from 'decentraland-transactions'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
-import { Marketplace } from '../../../contracts/Marketplace'
-import { ContractFactory } from '../../contract/ContractFactory'
+import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import { NFT } from '../../nft/types'
import { Order, OrderStatus } from '../../order/types'
import { orderAPI } from './order/api'
import { VendorName } from '../types'
import { OrderService as OrderServiceInterface } from '../services'
-import { sendTransaction } from '../../wallet/utils'
export class OrderService
implements OrderServiceInterface {
@@ -23,87 +20,53 @@ export class OrderService
}
async create(
- wallet: Wallet | null,
+ _wallet: Wallet | null,
nft: NFT,
price: number,
expiresAt: number
) {
- const contractData = getContract(ContractName.Marketplace, nft.chainId)
- const marketplace = await this.getMarketplaceContract(contractData.address)
-
- if (!wallet) {
- throw new Error('Invalid address. Wallet must be connected.')
- }
- const from = Address.fromString(wallet.address)
-
- const createOrder = marketplace.methods.createOrder(
- Address.fromString(nft.contractAddress),
- nft.tokenId,
- toWei(price.toString(), 'ether'),
- expiresAt
+ const contract = getContract(ContractName.Marketplace, nft.chainId)
+ return sendTransaction(contract, marketplace =>
+ marketplace.createOrder(
+ nft.contractAddress,
+ nft.tokenId,
+ utils.parseEther(price.toString()),
+ expiresAt
+ )
)
-
- return sendTransaction(createOrder, contractData, from)
}
async execute(
- wallet: Wallet | null,
+ _wallet: Wallet | null,
nft: NFT,
order: Order,
fingerprint?: string
) {
- const contractData = getContract(ContractName.Marketplace, nft.chainId)
- const marketplace = await this.getMarketplaceContract(contractData.address)
- const { price } = order
-
- if (!wallet) {
- throw new Error('Invalid address. Wallet must be connected.')
- }
- const from = Address.fromString(wallet.address)
-
+ const contract = getContract(ContractName.Marketplace, nft.chainId)
if (fingerprint) {
- return marketplace.methods
- .safeExecuteOrder(
- Address.fromString(nft.contractAddress),
+ return sendTransaction(contract, marketplace =>
+ marketplace.safeExecuteOrder(
+ nft.contractAddress,
nft.tokenId,
- price,
+ order.price,
fingerprint
)
- .send({ from })
- .getTxHash()
+ )
} else {
- const executeOrder = marketplace.methods.executeOrder(
- Address.fromString(nft.contractAddress),
- nft.tokenId,
- price
+ return sendTransaction(contract, marketplace =>
+ marketplace.executeOrder(nft.contractAddress, nft.tokenId, order.price)
)
-
- return sendTransaction(executeOrder, contractData, from)
}
}
- async cancel(wallet: Wallet | null, nft: NFT) {
- const contractData = getContract(ContractName.Marketplace, nft.chainId)
- const marketplace = await this.getMarketplaceContract(contractData.address)
-
- if (!wallet) {
- throw new Error('Invalid address. Wallet must be connected.')
- }
-
- const from = Address.fromString(wallet.address)
- const cancelOrder = marketplace.methods.cancelOrder(
- Address.fromString(nft.contractAddress),
- nft.tokenId
+ async cancel(_wallet: Wallet | null, nft: NFT) {
+ const contract = getContract(ContractName.Marketplace, nft.chainId)
+ return sendTransaction(contract, marketplace =>
+ marketplace.cancelOrder(nft.contractAddress, nft.tokenId)
)
-
- return sendTransaction(cancelOrder, contractData, from)
}
canSell() {
return true
}
-
- private getMarketplaceContract(address: string) {
- return ContractFactory.build(Marketplace, address)
- }
}
diff --git a/webapp/src/modules/wallet/sagas.ts b/webapp/src/modules/wallet/sagas.ts
index 22b491bb2f..aa45f92335 100644
--- a/webapp/src/modules/wallet/sagas.ts
+++ b/webapp/src/modules/wallet/sagas.ts
@@ -14,15 +14,17 @@ import {
Authorization,
AuthorizationType
} from 'decentraland-dapps/dist/modules/authorization/types'
+import { ContractName } from 'decentraland-transactions'
import { getContractNames } from '../vendor'
import { contracts, getContract } from '../contract/utils'
import { isPartner } from '../vendor/utils'
-import { ContractName } from 'decentraland-transactions'
+import { TRANSACTIONS_API_URL } from './utils'
const baseWalletSaga = createWalletSaga({
CHAIN_ID: +(process.env.REACT_APP_CHAIN_ID || 1),
- POLL_INTERVAL: 0
+ POLL_INTERVAL: 0,
+ TRANSACTIONS_API_URL
})
export function* walletSaga() {
diff --git a/webapp/src/modules/wallet/utils.ts b/webapp/src/modules/wallet/utils.ts
index 29e38b40e7..a9555b384a 100644
--- a/webapp/src/modules/wallet/utils.ts
+++ b/webapp/src/modules/wallet/utils.ts
@@ -1,16 +1,3 @@
-import { TxSend } from 'web3x-es/contract'
-import { Address } from 'web3x-es/address'
-import { Network } from '@dcl/schemas'
-import { getChainConfiguration } from 'decentraland-dapps/dist/lib/chainConfiguration'
-import {
- ContractData,
- sendMetaTransaction as baseSendMetaTransaction
-} from 'decentraland-transactions'
-import {
- getConnectedProvider,
- getNetworkProvider
-} from 'decentraland-dapps/dist/lib/eth'
-
export const TRANSACTIONS_API_URL = process.env.REACT_APP_TRANSACTIONS_API_URL
export function shortenAddress(address: string) {
@@ -26,42 +13,3 @@ export function addressEquals(address1?: string, address2?: string) {
address1.toLowerCase() === address2.toLowerCase()
)
}
-
-export function sendTransaction(
- method: TxSend,
- contract: ContractData,
- from: Address
-): Promise {
- const { network } = getChainConfiguration(contract.chainId)
-
- switch (network) {
- case Network.ETHEREUM:
- return method.send({ from }).getTxHash()
- case Network.MATIC: {
- return sendMetaTransaction(method, contract, from)
- }
- default:
- throw new Error(`Undefined network ${network}`)
- }
-}
-
-export async function sendMetaTransaction(
- method: TxSend,
- contract: ContractData,
- from: Address
-): Promise {
- const provider = await getConnectedProvider()
- if (!provider) {
- throw new Error('Could not get a valid connected Wallet')
- }
- const metaTxProvider = await getNetworkProvider(contract.chainId)
- const txData = getMethodData(method, from)
- return baseSendMetaTransaction(provider, metaTxProvider, txData, contract, {
- serverURL: TRANSACTIONS_API_URL
- })
-}
-
-export function getMethodData(method: TxSend, from: Address): string {
- const payload = method.getSendRequestPayload({ from })
- return payload.params[0].data
-}