Skip to content

Commit

Permalink
Batch Listing: implement price restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromcunha committed Nov 29, 2023
1 parent eb8c877 commit 743275e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
32 changes: 26 additions & 6 deletions components/portfolio/BatchListings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Props = {
}

const MINIMUM_AMOUNT = 0.000001
const MAXIMUM_AMOUNT = Infinity

const BatchListings: FC<Props> = ({
selectedItems,
Expand Down Expand Up @@ -227,12 +228,31 @@ const BatchListings: FC<Props> = ({
}, [listings, onChainRoyaltiesMap, globalPrice])

const listButtonDisabled = useMemo(() => {
const hasInvalidPrice = listings.some(
(listing) =>
listing.price === undefined ||
listing.price === '' ||
Number(listing.price) < MINIMUM_AMOUNT
)
const hasInvalidPrice = listings.some((listing) => {
const minimumAmount = listing.exchange?.minPriceRaw
? Number(
formatUnits(
BigInt(listing.exchange.minPriceRaw),
listing.currency?.decimals || 18
)
)
: MINIMUM_AMOUNT
const maximumAmount = listing.exchange?.maxPriceRaw
? Number(
formatUnits(
BigInt(listing.exchange.maxPriceRaw),
listing.currency?.decimals || 18
)
)
: MAXIMUM_AMOUNT

const withinPricingBounds =
listing.price &&
Number(listing.price) !== 0 &&
Number(listing.price) <= maximumAmount &&
Number(listing.price) >= minimumAmount
return !withinPricingBounds
})
return hasInvalidPrice
}, [listings])

Expand Down
45 changes: 39 additions & 6 deletions components/portfolio/BatchListingsTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { UserToken } from 'pages/portfolio/[[...address]]'
import CryptoCurrencyIcon from 'components/primitives/CryptoCurrencyIcon'
import { BatchListing } from './BatchListings'
import optimizeImage from 'utils/optimizeImage'
import { formatUnits } from 'viem'
import { formatNumber } from 'utils/numbers'

type BatchListingsTableRowProps = {
listing: BatchListing
Expand All @@ -44,6 +46,7 @@ type BatchListingsTableRowProps = {
}

const MINIMUM_AMOUNT = 0.000001
const MAXIMUM_AMOUNT = Infinity

export const BatchListingsTableRow: FC<BatchListingsTableRowProps> = ({
listing,
Expand Down Expand Up @@ -179,8 +182,30 @@ export const BatchListingsTableRow: FC<BatchListingsTableRowProps> = ({
)

const restrictCurrency =
listing?.exchange?.paymentTokens &&
listing.exchange.paymentTokens.length > 0
listing.exchange?.paymentTokens && listing.exchange.paymentTokens.length > 0

const minimumAmount = listing.exchange?.minPriceRaw
? Number(
formatUnits(
BigInt(listing.exchange.minPriceRaw),
listing.currency?.decimals || 18
)
)
: MINIMUM_AMOUNT
const maximumAmount = listing.exchange?.maxPriceRaw
? Number(
formatUnits(
BigInt(listing.exchange.maxPriceRaw),
listing.currency?.decimals || 18
)
)
: MAXIMUM_AMOUNT

const withinPricingBounds =
price &&
Number(price) !== 0 &&
Number(price) <= maximumAmount &&
Number(price) >= minimumAmount

return (
<TableRow
Expand Down Expand Up @@ -380,22 +405,30 @@ export const BatchListingsTableRow: FC<BatchListingsTableRowProps> = ({
))}
</Select>
)}
<Flex direction="column" align="center" css={{ gap: '$2' }}>
<Flex
direction="column"
css={{ gap: '$2', width: 100, '@bp1500': { width: 150 } }}
>
<Input
placeholder="Price"
type="number"
value={price}
onChange={(e) => {
handlePriceChange(e.target.value)
}}
css={{ width: 100, '@bp1500': { width: 150 } }}
/>
{price !== undefined &&
price !== '' &&
Number(price) !== 0 &&
Number(price) < MINIMUM_AMOUNT && (
!withinPricingBounds && (
<Text style="subtitle3" color="error">
Must exceed {MINIMUM_AMOUNT}
{maximumAmount !== Infinity
? `Amount must be between ${formatNumber(
minimumAmount
)} - ${formatNumber(maximumAmount)}`
: `Amount must be higher than ${formatNumber(
minimumAmount
)}`}
</Text>
)}
</Flex>
Expand Down

0 comments on commit 743275e

Please sign in to comment.