Skip to content

Commit

Permalink
Merge pull request #25 from ThreeDotsTech/24-need-the-ability-to-make…
Browse files Browse the repository at this point in the history
…-weth-offers-to-erc721s

24 need the ability to make weth offers to erc721s
  • Loading branch information
itsMarcoSolis authored Dec 5, 2022
2 parents 7e09d17 + 59c3172 commit ab63fc2
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 227 deletions.
24 changes: 7 additions & 17 deletions src/components/ItemPageModal/MakeOffer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { TypedDataSigner } from '@ethersproject/abstract-signer';

import { Web3Provider } from '@ethersproject/providers';
import { WETH_ADDRESSES } from 'constants/addresses';
import { SupportedNFTInterfaces } from 'constants/ERC165';
import { parseEther } from 'ethers/lib/utils';
import { useERC20Contract, useERC721Contract, useStateswapAtomizicerContract, useStateswapExchangeContract } from 'hooks/useContract';
import { useERC20Contract, useStateswapAtomizicerContract } from 'hooks/useContract';
import { useERC165 } from 'hooks/useERC165';
import { create_ERC20_ERC721_OfferWithFees, create_ERC721_WETH_OR_ETH_Offer } from 'hooks/useExchangeContract';
import { createErc721_WethOrEthOffer, createWETH_Erc721Order } from 'hooks/useExchangeContract';
import React, { useState } from 'react';
import DatePicker from "react-datepicker";
import { start } from 'repl';
import styled from 'styled-components';
import { OrderWrapperInterface } from 'stateswap/orders/types';
import { isToday } from 'utils'
import { SignerExtended, wrap } from 'utils/exchangeWrapper';
import { ReactComponent as Close } from '../../assets/images/x.svg'

const CloseIcon = styled.div`
Expand Down Expand Up @@ -167,29 +165,21 @@ export default function MakeOffer({
<button onClick={() => {
if (!chainId || !endDate) return
setWrappedOrder(
isOwner ? create_ERC721_WETH_OR_ETH_Offer({
isOwner ? createErc721_WethOrEthOffer({
maker: account,
owner,
erc721Address: contractAddress,
tokenId: id,
chainId,
price: parseEther(price as string),
expirationTime: endDate.getTime()
}).getOrbitDBSafeOrderWrapper() : create_ERC20_ERC721_OfferWithFees({
}).getOrbitDBSafeOrderWrapper() : createWETH_Erc721Order({
maker: account,
owner,
erc721Address: contractAddress,
tokenId: id,
erc20Address: WETH_ADDRESSES[chainId],
erc20Amount: parseEther(price as string),
protocolFee: 30,
protocolFeeReceiver: '0x77e2415dfc1Bc4ef3455441861aA12fC1184bd66',
creatorFee: 100,
creatorFeeReceiver: '0x02aCb57384d82c6F0875030032b3f248EB46b327',
wethAmount: parseEther(price as string),
expirationTime: endDate.getTime(),
chainId: chainId,
erc20c,
atomicizerc
chainId: chainId
}
)
)
Expand Down
35 changes: 4 additions & 31 deletions src/components/ItemPageModal/Match.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { OrderType, OrderWrapperInterface } from 'stateswap/orders/types'
import styled from 'styled-components/macro'
import { MAKE_OFFER_VIEWS } from '.'
import { ReactComponent as Close } from '../../assets/images/x.svg'
import { ArrowLeft } from 'react-feather'
import Row from 'components/Row'
import { ThemedText } from '../../theme'
import { ReactComponent as Checkmark } from '../../assets/svg/checkmark.svg'
Expand All @@ -11,14 +9,15 @@ import { AddressZero, MaxUint256 } from '@ethersproject/constants'
import { CallState } from '@uniswap/redux-multicall/dist/types'
import { StateswapRegistry } from 'abis/types/StateswapRegistry'
import { ReactComponent as Spinner } from '../../assets/svg/spinner.svg'
import { createOrderAcceptAny } from 'hooks/useExchangeContract'
import { createAny_AnyOrder } from 'hooks/useExchangeContract'
import { splitSignature } from 'ethers/lib/utils'
import { NULL_SIG, ZERO_BYTES32 } from 'constants/misc'
import { useERC20Contract, useERC721Contract, useStateswapExchangeContract } from 'hooks/useContract'
import { wrap } from 'utils/exchangeWrapper'
import { WETH_ADDRESSES } from 'constants/addresses'
import { Call } from 'stateswap/verifiers'
import DocumentStore from 'orbit-db-docstore'

const CloseIcon = styled.div`
position: absolute;
right: 1rem;
Expand Down Expand Up @@ -65,18 +64,6 @@ const UpperSection = styled.div`
}
`

const HoverText = styled.div`
text-decoration: none;
color: ${({ theme }) => theme.text1};
display: flex;
align-items: center;
:hover {
cursor: pointer;
}
`


export function MatchView(
{
name,
Expand All @@ -98,9 +85,7 @@ export function MatchView(
setSuccess,
setwaitingForTX,
setethWETH,
setWalletView,
toggleWalletModal,
setWrappedOrder
}: {
name: string,
contractAddress: string,
Expand All @@ -121,8 +106,6 @@ export function MatchView(
setSuccess: React.Dispatch<React.SetStateAction<boolean>>,
setethWETH: React.Dispatch<React.SetStateAction<boolean>>
toggleWalletModal: () => void,
setWalletView: React.Dispatch<React.SetStateAction<string>>,
setWrappedOrder: React.Dispatch<React.SetStateAction<OrderWrapperInterface | undefined>>,
db: DocumentStore<OrderWrapperInterface>
}
) {
Expand Down Expand Up @@ -388,14 +371,9 @@ export function MatchView(
} else {
if (!chainId || !account || !selectedOrder.signature || !erc721c) return
//Ready to match ETH for ERC721
const orderAcceptAny = createOrderAcceptAny(account, chainId)
const orderAcceptAny = createAny_AnyOrder(account, chainId)
const emptyCall = Call.utils.empty(chainId)
const erc721TransferCall = Call.erc721.transferFrom(selectedOrder.maker, account, selectedOrder.target, erc721c, selectedOrder.collection)

console.log(orderAcceptAny)
console.log(emptyCall)
console.log(selectedOrder)
console.log(erc721TransferCall)
exchange?.stateswapWith(selectedOrder.order, selectedOrder.signature, erc721TransferCall, orderAcceptAny, splitSignature(NULL_SIG), emptyCall, ZERO_BYTES32, { value: selectedOrder.price })
.then(
(tx: ContractTransaction) => {
Expand Down Expand Up @@ -468,14 +446,9 @@ export function MatchView(
} else {
//Ready to accept the order
if (!chainId || !account || !selectedOrder.signature || !erc721c || !erc20c) return
const OrderAcceptAny = createOrderAcceptAny(account, chainId)
const OrderAcceptAny = createAny_AnyOrder(account, chainId)
const erc20TransferCall = Call.erc20.transferFrom(account, selectedOrder.maker, selectedOrder.price, erc20c, WETH_ADDRESSES[chainId])
const erc721TransferCall = Call.erc721.transferFrom(selectedOrder.maker, account, selectedOrder.target, erc721c, selectedOrder.collection)

console.log(OrderAcceptAny)
console.log(erc20TransferCall)
console.log(selectedOrder)
console.log(erc721TransferCall)
exchange?.stateswap(selectedOrder.order, selectedOrder.signature, erc721TransferCall, OrderAcceptAny, splitSignature(NULL_SIG), erc20TransferCall, ZERO_BYTES32)
.then(
(tx: ContractTransaction) => {
Expand Down
24 changes: 11 additions & 13 deletions src/components/ItemPageModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,30 +453,28 @@ export default function ItemPageModal({
if (modalAction == SaleAction.MATCH) {
if (!selectedOrder || !chainId || !orbitdb || !orbitdb?.db) return
return (
<MatchView // G
<MatchView
name={name}
contractAddress={contractAddress} // o
contractAddress={contractAddress}
account={account}
chainId={chainId} // d
chainId={chainId}
setwaitingForTX={setwaitingForTX}
registryContract={registryContract} // F
registryContract={registryContract}
waitingForTX={waitingForTX}
success={success} // o
success={success}
proxyAllowance={proxyAllowance}
proxyAddress={proxyAddress} // r
proxyAddress={proxyAddress}
ethWETH={ethWETH}
isOwner={isOwner} // g
isOwner={isOwner}
selectedOrder={selectedOrder}
collectionName={collectionName} // i
collectionName={collectionName}
imageURL={imageURL}
animationURL={animationURL} // v
animationURL={animationURL}
setethWETH={setethWETH}
toggleWalletModal={toggleWalletModal} // e
setWalletView={setWalletView}
setWrappedOrder={setWrappedOrder} // M
toggleWalletModal={toggleWalletModal}
setSuccess={setSuccess}
db={orbitdb.db}
/> // e
/>
)
}
if (modalAction == SaleAction.TRANSFER) {
Expand Down
Loading

0 comments on commit ab63fc2

Please sign in to comment.