Skip to content

Commit b9f5ad7

Browse files
authored
Merge pull request #503 from hypercerts-org/dev
chore: new release
2 parents 926faae + c67223e commit b9f5ad7

39 files changed

+487
-378
lines changed

allowlists/getAllowListRecordsForAddressByClaimed.tsx renamed to allowlists/actions/getAllowListRecordsForAddressByClaimed.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,17 @@ const query = graphql(
3838
[AllowListRecordFragment],
3939
);
4040

41-
export async function getAllowListRecordsForAddressByClaimed(
42-
address: string,
43-
claimed: boolean,
44-
) {
45-
const res = await request(
46-
HYPERCERTS_API_URL_GRAPH,
47-
query,
48-
{
49-
address,
50-
claimed,
51-
},
52-
new Headers({
53-
"Cache-Control": "no-cache",
54-
Pragma: "no-cache",
55-
}),
56-
);
41+
export async function getAllowListRecordsForAddressByClaimed({
42+
address,
43+
claimed,
44+
}: {
45+
address: string;
46+
claimed: boolean;
47+
}) {
48+
const res = await request(HYPERCERTS_API_URL_GRAPH, query, {
49+
address,
50+
claimed,
51+
});
5752

5853
const allowlistRecords = res.allowlistRecords.data;
5954
if (!allowlistRecords) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import "server-only";
2+
3+
import { ResultOf, graphql, readFragment } from "@/lib/graphql";
4+
5+
import request from "graphql-request";
6+
import { HYPERCERTS_API_URL_GRAPH } from "@/configs/hypercerts";
7+
import { getHypercertMetadata } from "@/hypercerts/actions/getHypercertMetadata";
8+
import { UnclaimedFraction } from "@/components/profile/unclaimed-hypercerts-list";
9+
10+
export const AllowListRecordFragment = graphql(`
11+
fragment AllowListRecordFragment on AllowlistRecord {
12+
id
13+
hypercert_id
14+
token_id
15+
root
16+
leaf
17+
entry
18+
user_address
19+
claimed
20+
proof
21+
units
22+
total_units
23+
}
24+
`);
25+
export type AllowListRecord = ResultOf<typeof AllowListRecordFragment>;
26+
27+
const query = graphql(
28+
`
29+
query allowlistRecords($address: String, $claimed: Boolean) {
30+
allowlistRecords(
31+
where: { user_address: { eq: $address }, claimed: { eq: $claimed } }
32+
) {
33+
count
34+
data {
35+
...AllowListRecordFragment
36+
}
37+
}
38+
}
39+
`,
40+
[AllowListRecordFragment],
41+
);
42+
43+
const requestMap = new Map<string, Promise<any>>();
44+
45+
async function getMetadataWithDeduping(hypercertId: string) {
46+
if (requestMap.has(hypercertId)) {
47+
return requestMap.get(hypercertId);
48+
}
49+
50+
const requestPromise = getHypercertMetadata(hypercertId);
51+
requestMap.set(hypercertId, requestPromise);
52+
53+
return await requestPromise;
54+
}
55+
56+
export async function getAllowListRecordsForAddressByClaimedWithMetadata({
57+
address,
58+
claimed,
59+
}: {
60+
address: string;
61+
claimed: boolean;
62+
}): Promise<
63+
{ data: UnclaimedFraction[] | null; count: number | null } | undefined
64+
> {
65+
const res = await request(HYPERCERTS_API_URL_GRAPH, query, {
66+
address,
67+
claimed,
68+
});
69+
70+
const allowlistRecords = res.allowlistRecords.data;
71+
if (!allowlistRecords) {
72+
return undefined;
73+
}
74+
const allowlistRecordsRead = readFragment(
75+
AllowListRecordFragment,
76+
allowlistRecords,
77+
);
78+
79+
const count = res.allowlistRecords.count;
80+
81+
if (allowlistRecordsRead && allowlistRecordsRead.length > 0) {
82+
const processedData = await Promise.all(
83+
allowlistRecordsRead.map(async (fraction) => {
84+
const metadata = fraction.hypercert_id
85+
? await getMetadataWithDeduping(fraction.hypercert_id)
86+
: null;
87+
return { ...fraction, metadata: metadata?.data ?? null };
88+
}),
89+
);
90+
91+
return {
92+
count,
93+
data: processedData,
94+
};
95+
}
96+
97+
return {
98+
count,
99+
data: [...allowlistRecordsRead],
100+
};
101+
}

app/actions/revalidatePathServerAction.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ export async function revalidatePathServerAction(
99
) {
1010
const pathArray = Array.isArray(paths) ? paths : [paths];
1111

12-
pathArray.forEach((p) => {
12+
for (const p of pathArray) {
13+
console.debug("Revalidating path: ", p);
1314
if (typeof p === "string") {
1415
revalidatePath(p);
1516
} else {
1617
revalidatePath(p.path, p.type);
1718
}
18-
});
19+
}
1920
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { getHypercertMetadata } from "@/hypercerts/actions/getHypercertMetadata";
2+
import { NextResponse } from "next/server";
3+
4+
export async function GET(
5+
request: Request,
6+
{ params }: { params: { hypercertId: string } },
7+
) {
8+
try {
9+
const data = await getHypercertMetadata(params.hypercertId);
10+
11+
if (!data) {
12+
return NextResponse.json(
13+
{ error: "Metadata not found" },
14+
{ status: 404 },
15+
);
16+
}
17+
18+
return NextResponse.json(data);
19+
} catch (error) {
20+
console.error("Error fetching hypercert metadata:", error);
21+
return NextResponse.json(
22+
{ error: "Failed to fetch metadata" },
23+
{ status: 500 },
24+
);
25+
}
26+
}

app/hypercerts/[hypercertId]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Metadata, ResolvingMetadata } from "next";
22

3-
import { getHypercert } from "@/hypercerts/getHypercert";
3+
import { getHypercert } from "@/hypercerts/actions/getHypercert";
44

55
import CreatorFeedButton from "@/components/creator-feed/creator-feed-button";
66
import CreatorFeeds from "@/components/creator-feed/creator-feeds";

app/profile/[address]/hypercerts-tab-content.tsx

-155
This file was deleted.

app/profile/[address]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from "@/app/profile/[address]/tabs";
55

66
import EthAddress from "@/components/eth-address";
7-
import { HypercertsTabContent } from "@/app/profile/[address]/hypercerts-tab-content";
7+
import { HypercertsTabContent } from "@/components/profile/hypercerts-tab/hypercerts-tab-content";
88
import { CollectionsTabContent } from "@/app/profile/[address]/collections-tab-content";
99
import { MarketplaceTabContent } from "@/app/profile/[address]/marketplace-tab-content";
1010
import { BlueprintsTabContent } from "@/app/profile/[address]/blueprint-tab-content";

components/allowlist/create-allowlist-dialog.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use client";
22

3-
import { ChangeEvent, useEffect, useState } from "react";
43
import {
54
Dialog,
65
DialogContent,
@@ -9,17 +8,18 @@ import {
98
DialogTitle,
109
} from "@/components/ui/dialog";
1110
import { LoaderCircle, MinusCircle, PlusCircle } from "lucide-react";
11+
import { ChangeEvent, useEffect, useState } from "react";
1212
import { isAddress } from "viem";
1313

1414
import { Button } from "@/components/ui/button";
1515
import { Input } from "@/components/ui/input";
16-
import { cn } from "@/lib/utils";
17-
import { errorHasMessage } from "@/lib/errorHasMessage";
1816
import { toast } from "@/components/ui/use-toast";
19-
import { useValidateAllowlist } from "@/hypercerts/hooks/useCreateAllowLists";
17+
import { errorHasMessage } from "@/lib/errorHasMessage";
18+
import { cn } from "@/lib/utils";
2019
import { AllowlistEntry } from "@hypercerts-org/sdk";
2120

2221
import { DEFAULT_NUM_UNITS } from "@/configs/hypercerts";
22+
import { useValidateAllowList } from "@/hypercerts/hooks/useValidateAllowList";
2323

2424
type AllowListItem = {
2525
address?: string;
@@ -54,7 +54,7 @@ export default function Component({
5454
isPending,
5555
error: createAllowListError,
5656
reset,
57-
} = useValidateAllowlist();
57+
} = useValidateAllowList();
5858
const [allowList, setAllowList] = useState<AllowListItem[]>(
5959
initialValues?.length ? initialValues : defaultValues,
6060
);

components/evaluations/evaluation-list-item/hypercert-row.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Image from "next/image";
2-
import { getHypercert } from "@/hypercerts/getHypercert";
2+
import { getHypercert } from "@/hypercerts/actions/getHypercert";
33

44
export default async function HypercertRow({
55
hypercertId,

0 commit comments

Comments
 (0)