Skip to content

Commit

Permalink
Merge pull request #155 from BibliothecaDAO/tenox/bug_fixes
Browse files Browse the repository at this point in the history
Fix marketplace collection sorting and filtering
  • Loading branch information
RedBeardEth authored Mar 5, 2024
2 parents eb49446 + bf71569 commit 9d4dd3e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ const GridDetails = ({
token: RouterOutputs["erc721Tokens"]["all"]["items"][number];
address?: string;
}) => (
<div className=" flex h-full w-full flex-col justify-between p-3">
<div className="flex h-full w-full flex-col justify-between p-3 ">
<div className="flex justify-between pb-2">
<span className="truncate">{decodeURIComponent(token.name ?? "")}</span>
</div>

<div className="flex justify-between font-sans">
<div className="flex justify-between font-sans">
<Price token={token} />
{token.lastPrice && (
<span className="flex text-bright-yellow/50">
Expand Down Expand Up @@ -173,7 +173,7 @@ const ListDetails = ({
{useStarkDisplayName(address)}
</Button>
</div>
<div className="absolute bottom-0 right-0 w-full px-3 opacity-0 transition-all duration-300 group-hover:bottom-2 group-hover:opacity-100">
<div className="absolute bottom-0 right-0 w-full px-3 opacity-0 transition-all duration-300 group-hover:bottom-2 group-hover:opacity-100">
<CardAction token={token} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const L2ActivityCard = ({ activity }: ActivityCardProps) => {
break;
}
return (
<div className=" flex w-full flex-wrap border-b p-2">
<div className="flex w-full flex-wrap border-b p-2 ">
<div className="mr-6 w-full flex-none self-center rounded px-4 py-1 font-semibold sm:w-1/12">
{eventType === "Sale" && <Gavel />}
{eventType === "Listing" && <NotebookPen />}
Expand Down
18 changes: 7 additions & 11 deletions apps/nextjs/src/app/collection/[id]/[tokenId]/L2Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useTimeDiff } from "@/hooks/useTimeDiff";
import Lords from "@/icons/lords.svg";
import { api } from "@/trpc/react";
import { findLowestPriceActiveListing } from "@/utils/getters";
import { padAddress } from "@/utils/utils";
import { useAccount } from "@starknet-react/core";
import { Clock } from "lucide-react";
Expand Down Expand Up @@ -50,26 +51,21 @@ export const L2Token = ({
) => listing.active && listing.created_by == erc721Token.owner,
);

const lowestPriceActiveListing = activeListings?.reduce(
(minPriceListing, currentListing) =>
(currentListing.price ?? 0) < (minPriceListing?.price ?? 0)
? currentListing
: minPriceListing,
activeListings[0],
const lowestPriceActiveListing = findLowestPriceActiveListing(
erc721Token?.listings,
erc721Token?.owner,
);

const collectionId = getCollectionFromAddress(contractAddress);
// eslint-disable-next-line react-hooks/rules-of-hooks
const expiryDiff = useTimeDiff(lowestPriceActiveListing?.expiration ?? 0);

const price = lowestPriceActiveListing?.price
? BigInt(parseInt(lowestPriceActiveListing?.price || "0")).toString()
: null;
const price = lowestPriceActiveListing?.price;

return (
<>
{lowestPriceActiveListing?.expiration && (
<div className="my-2 flex items-center py-4 text-xs opacity-60">
<div className="my-2 flex items-center py-4 text-xs opacity-60">
<Clock className="mr-2 w-6" />
<span>Listing ends in {expiryDiff}</span>
</div>
Expand All @@ -94,7 +90,7 @@ export const L2Token = ({
<TokenOwnerActions token={token} />
) : (
<div>
{lowestPriceActiveListing && (
{price && (
<BuyModal
trigger={
<Button className="w-full" size={"lg"}>
Expand Down
37 changes: 20 additions & 17 deletions packages/api/src/router/erc721Tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ export const erc721TokensRouter = createTRPCRouter({
} = input;
const whereFilter: SQL[] = [];
const cursors = [];
console.log(cursor)

// Order By tokenId
if (orderBy == "tokenId") {
cursors.push([
schema.erc721Tokens.token_id, // Column to use for cursor
direction ?? "desc", // Sort order ('asc' or 'desc')
direction ?? "asc", // Sort order ('asc' or 'desc')
cursor?.token_id, // Cursor value
]);
} else {
}
// Order By price
else {
if (
cursor == undefined ||
(cursor?.token_id != 0 && cursor?.price != null)
) {
cursors.push(
[
schema.erc721Tokens.price, // Column to use for cursor
sql`case when EXTRACT(EPOCH FROM now()) < ${schema.erc721Tokens.expiration} then ${schema.erc721Tokens.price} else ${direction === "dsc" ? "0" : null} end`,
direction ?? "asc", // Sort order ('asc' or 'desc')
cursor?.price, // Cursor value
],
Expand Down Expand Up @@ -97,21 +100,21 @@ export const erc721TokensRouter = createTRPCRouter({
const attributesObject: SQL[] = [];
for (const [key, value] of Object.entries(attributeFilter)) {
attributesObject.push(
eq(schema.erc721TokenAttributes.value, value),
eq(schema.erc721TokenAttributes.key, key),
inArray(
schema.erc721Tokens.id,
ctx.db
.select({ id: schema.erc721TokenAttributes.token_key })
.from(schema.erc721TokenAttributes)
.where(
and(
eq(schema.erc721TokenAttributes.value, value),
eq(schema.erc721TokenAttributes.key, key),
),
),
),
);
}
whereFilter.push(
inArray(
schema.erc721Tokens.id,
ctx.db
.select({ id: schema.erc721TokenAttributes.token_key })
.from(schema.erc721TokenAttributes)
.where(and(...attributesObject)),

//.where(and(...attributesObject)),
),
);
whereFilter.push(...attributesObject);
}
/*const items = await ctx.db
.select({
Expand Down

0 comments on commit 9d4dd3e

Please sign in to comment.