Skip to content

Commit 1603588

Browse files
committed
feat: add buy button listing status
- Disable buy button when no marketplace orders exist for the hypercert
1 parent 26c9c43 commit 1603588

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

components/hypercert/hypercert-details.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { InfoSection } from "../global/sections";
1515
import PageSkeleton from "./page-skeleton";
1616
import { cache, Suspense } from "react";
1717
import { getHypercertState } from "@/hypercerts/getHypercertState";
18+
import { getOrders } from "@/marketplace/getOpenOrders";
1819

1920
function HypercertDetailsNotFound() {
2021
return <InfoSection>Hypercert not found</InfoSection>;
@@ -38,6 +39,9 @@ export default async function HypercertDetails({
3839
hypercertId: string;
3940
}) {
4041
const hypercert = await getHypercertDetails(hypercertId);
42+
const orders = await getOrders({ filter: { hypercertId: hypercertId } });
43+
44+
const isListed = orders?.data?.length > 0 && orders?.count > 0;
4145

4246
if (!hypercert) {
4347
return <HypercertDetailsNotFound />;
@@ -57,7 +61,7 @@ export default async function HypercertDetails({
5761
{hypercert?.metadata?.name || "[Untitled]"}
5862
</h1>
5963
<div className="flex space-x-2">
60-
<BuyButton />
64+
<BuyButton isListed={isListed} />
6165
<MutationButtons hypercert={hypercert} />
6266
</div>
6367
</div>

components/marketplace/buy-button.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Button } from "@/components/ui/button";
44

5-
export function BuyButton() {
5+
export function BuyButton({ isListed }: { isListed: boolean }) {
66
const handleClick = () => {
77
const listingsSection = document.getElementById("marketplace-listings");
88
if (listingsSection) {
@@ -12,5 +12,11 @@ export function BuyButton() {
1212
}
1313
};
1414

15-
return <Button onClick={handleClick}>Buy</Button>;
15+
return (
16+
<Button onClick={handleClick} disabled={!isListed}>
17+
Buy
18+
</Button>
19+
);
1620
}
21+
22+
export default BuyButton;

0 commit comments

Comments
 (0)