Skip to content

Commit

Permalink
Merge pull request #452 from reservoirprotocol/pedro/grwth-3730-remov…
Browse files Browse the repository at this point in the history
…e-batch-listing-onchain

Remove batch listing onchain royalties and use marketplace configuration max royalty
  • Loading branch information
pedromcunha committed Mar 5, 2024
2 parents e3df420 + d9a8588 commit 38a9cc7
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 252 deletions.
38 changes: 1 addition & 37 deletions components/portfolio/ApprovalCollapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ const Img = styled('img', {
type Props = {
item: NonNullable<NonNullable<Execute['steps']>[0]['items']>[0]
batchListingData: BatchListingData[]
selectedMarketplaces: Marketplace[]
open?: boolean
}

export const ApprovalCollapsible: FC<Props> = ({
item,
batchListingData,
selectedMarketplaces,
open,
}) => {
const [collapsibleOpen, setCollapsibleOpen] = useState(false)
Expand All @@ -45,37 +43,6 @@ export const ApprovalCollapsible: FC<Props> = ({

const orderIndexes = item?.orderIndexes || []

const marketplacesSeekingApproval = useMemo(() => {
let uniqueMarketplaces: Marketplace[] = []

orderIndexes.forEach((orderIndex) => {
if (batchListingData[orderIndex]) {
const listing = batchListingData[orderIndex].listing

const marketplace = selectedMarketplaces.find(
(m) => m.orderbook === listing.orderbook
)

if (
marketplace &&
!uniqueMarketplaces.find(
(uniqueMarketplace) =>
uniqueMarketplace.orderbook === marketplace.orderbook
)
) {
uniqueMarketplaces.push(marketplace)
}
}
})
return uniqueMarketplaces
}, [orderIndexes, item, batchListingData])

const marketplaceNames = useMemo(() => {
return marketplacesSeekingApproval
.map((marketplace) => marketplace.name)
.join(' and ')
}, [marketplacesSeekingApproval])

const collectionImage: string = useMemo(() => {
const token = batchListingData[orderIndexes[0]]?.token?.token
return (
Expand Down Expand Up @@ -166,12 +133,9 @@ export const ApprovalCollapsible: FC<Props> = ({
<Flex css={{ gap: '$2' }}>
<Flex align="center">
<Img src={collectionImage} />
{marketplacesSeekingApproval.map((marketplace) => (
<Img src={marketplace.imageUrl} />
))}
</Flex>
<Text style="body3" ellipsify>
Approve {collectionName} on {marketplaceNames}
Approve {collectionName}
</Text>
</Flex>
<Flex>
Expand Down
61 changes: 3 additions & 58 deletions components/portfolio/BatchListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,13 @@ type BatchListModalStepData = {
type Props = {
listings: BatchListing[]
disabled: boolean
selectedMarketplaces: Marketplace[]
onChainRoyalties: ReturnType<typeof useOnChainRoyalties>['data']
onCloseComplete?: () => void
}

const orderFee = process.env.NEXT_PUBLIC_MARKETPLACE_FEE
const orderFees = orderFee ? [orderFee] : []

const BatchListModal: FC<Props> = ({
listings,
disabled,
selectedMarketplaces,
onChainRoyalties,
onCloseComplete,
}) => {
const BatchListModal: FC<Props> = ({ listings, disabled, onCloseComplete }) => {
const [open, setOpen] = useState(false)
const { data: wallet } = useWalletClient()
const { openConnectModal } = useConnectModal()
Expand All @@ -79,30 +71,9 @@ const BatchListModal: FC<Props> = ({
[]
)

const getUniqueMarketplaces = useCallback(
(listings: BatchListModalStepData['listings']): Marketplace[] => {
const marketplaces: Marketplace[] = []
listings.forEach((listing) => {
const marketplace = selectedMarketplaces.find(
(m) => m.orderbook === listing.listing.orderbook
)
if (marketplace && !marketplaces.includes(marketplace)) {
marketplaces.push(marketplace)
}
})
return marketplaces
},
[listings]
)

useEffect(() => {
if (stepData) {
const orderKind = stepData.listings[0].listing.orderKind || 'exchange'
const marketplaces = getUniqueMarketplaces(stepData.listings)
const marketplaceNames = marketplaces
.map((marketplace) => marketplace.name)
.join(' and ')
setUniqueMarketplaces(marketplaces)

switch (stepData.currentStep.kind) {
case 'transaction': {
Expand All @@ -114,9 +85,7 @@ const BatchListModal: FC<Props> = ({
break
}
case 'signature': {
setStepTitle(
`Confirm listings on ${marketplaceNames}\nin your wallet`
)
setStepTitle(`Confirm listings in your wallet`)
break
}
}
Expand Down Expand Up @@ -176,29 +145,6 @@ const BatchListModal: FC<Props> = ({
convertedListing.expirationTime = expirationTime
}

const onChainRoyalty =
onChainRoyalties && onChainRoyalties[i] ? onChainRoyalties[i] : null
if (onChainRoyalty && listing.orderKind?.includes('seaport')) {
convertedListing.automatedRoyalties = false
const royaltyData = onChainRoyalty.result as OnChainRoyaltyReturnType
const royalties = royaltyData[0].map((recipient, i) => {
const bps = Math.floor(
(parseFloat(
formatUnits(
royaltyData[1][i],
marketplaceChain?.nativeCurrency.decimals || 18
)
) /
1) *
10000
)
return `${recipient}:${bps}`
})
if (royalties.length > 0) {
convertedListing.fees = [...royalties]
}
}

batchListingData.push({
listing: convertedListing,
token: listing.token,
Expand Down Expand Up @@ -266,7 +212,7 @@ const BatchListModal: FC<Props> = ({
)
setTransactionError(transactionError)
})
}, [client, listings, wallet, onChainRoyalties])
}, [client, listings, wallet])

const trigger = (
<Button disabled={disabled} onClick={listTokens}>
Expand Down Expand Up @@ -357,7 +303,6 @@ const BatchListModal: FC<Props> = ({
key={i}
item={item}
batchListingData={stepData.listings}
selectedMarketplaces={selectedMarketplaces}
open={item.status == 'incomplete'}
/>
)
Expand Down

0 comments on commit 38a9cc7

Please sign in to comment.