Skip to content

chore: new release #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ const query = graphql(
[AllowListRecordFragment],
);

export async function getAllowListRecordsForAddressByClaimed(
address: string,
claimed: boolean,
) {
const res = await request(
HYPERCERTS_API_URL_GRAPH,
query,
{
address,
claimed,
},
new Headers({
"Cache-Control": "no-cache",
Pragma: "no-cache",
}),
);
export async function getAllowListRecordsForAddressByClaimed({
address,
claimed,
}: {
address: string;
claimed: boolean;
}) {
const res = await request(HYPERCERTS_API_URL_GRAPH, query, {
address,
claimed,
});

const allowlistRecords = res.allowlistRecords.data;
if (!allowlistRecords) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import "server-only";

import { ResultOf, graphql, readFragment } from "@/lib/graphql";

import request from "graphql-request";
import { HYPERCERTS_API_URL_GRAPH } from "@/configs/hypercerts";
import { getHypercertMetadata } from "@/hypercerts/actions/getHypercertMetadata";
import { UnclaimedFraction } from "@/components/profile/unclaimed-hypercerts-list";

export const AllowListRecordFragment = graphql(`
fragment AllowListRecordFragment on AllowlistRecord {
id
hypercert_id
token_id
root
leaf
entry
user_address
claimed
proof
units
total_units
}
`);
export type AllowListRecord = ResultOf<typeof AllowListRecordFragment>;

const query = graphql(
`
query allowlistRecords($address: String, $claimed: Boolean) {
allowlistRecords(
where: { user_address: { eq: $address }, claimed: { eq: $claimed } }
) {
count
data {
...AllowListRecordFragment
}
}
}
`,
[AllowListRecordFragment],
);

const requestMap = new Map<string, Promise<any>>();

async function getMetadataWithDeduping(hypercertId: string) {
if (requestMap.has(hypercertId)) {
return requestMap.get(hypercertId);
}

const requestPromise = getHypercertMetadata(hypercertId);
requestMap.set(hypercertId, requestPromise);

return await requestPromise;
}

export async function getAllowListRecordsForAddressByClaimedWithMetadata({
address,
claimed,
}: {
address: string;
claimed: boolean;
}): Promise<
{ data: UnclaimedFraction[] | null; count: number | null } | undefined
> {
const res = await request(HYPERCERTS_API_URL_GRAPH, query, {
address,
claimed,
});

const allowlistRecords = res.allowlistRecords.data;
if (!allowlistRecords) {
return undefined;
}
const allowlistRecordsRead = readFragment(
AllowListRecordFragment,
allowlistRecords,
);

const count = res.allowlistRecords.count;

if (allowlistRecordsRead && allowlistRecordsRead.length > 0) {
const processedData = await Promise.all(
allowlistRecordsRead.map(async (fraction) => {
const metadata = fraction.hypercert_id
? await getMetadataWithDeduping(fraction.hypercert_id)
: null;
return { ...fraction, metadata: metadata?.data ?? null };
}),
);

return {
count,
data: processedData,
};
}

return {
count,
data: [...allowlistRecordsRead],
};
}
5 changes: 3 additions & 2 deletions app/actions/revalidatePathServerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export async function revalidatePathServerAction(
) {
const pathArray = Array.isArray(paths) ? paths : [paths];

pathArray.forEach((p) => {
for (const p of pathArray) {
console.debug("Revalidating path: ", p);
if (typeof p === "string") {
revalidatePath(p);
} else {
revalidatePath(p.path, p.type);
}
});
}
}
26 changes: 26 additions & 0 deletions app/api/hypercerts/[hypercertId]/metadata/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getHypercertMetadata } from "@/hypercerts/actions/getHypercertMetadata";
import { NextResponse } from "next/server";

export async function GET(
request: Request,
{ params }: { params: { hypercertId: string } },
) {
try {
const data = await getHypercertMetadata(params.hypercertId);

if (!data) {
return NextResponse.json(
{ error: "Metadata not found" },
{ status: 404 },
);
}

return NextResponse.json(data);
} catch (error) {
console.error("Error fetching hypercert metadata:", error);
return NextResponse.json(
{ error: "Failed to fetch metadata" },
{ status: 500 },
);
}
}
2 changes: 1 addition & 1 deletion app/hypercerts/[hypercertId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Metadata, ResolvingMetadata } from "next";

import { getHypercert } from "@/hypercerts/getHypercert";
import { getHypercert } from "@/hypercerts/actions/getHypercert";

import CreatorFeedButton from "@/components/creator-feed/creator-feed-button";
import CreatorFeeds from "@/components/creator-feed/creator-feeds";
Expand Down
155 changes: 0 additions & 155 deletions app/profile/[address]/hypercerts-tab-content.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion app/profile/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "@/app/profile/[address]/tabs";

import EthAddress from "@/components/eth-address";
import { HypercertsTabContent } from "@/app/profile/[address]/hypercerts-tab-content";
import { HypercertsTabContent } from "@/components/profile/hypercerts-tab/hypercerts-tab-content";
import { CollectionsTabContent } from "@/app/profile/[address]/collections-tab-content";
import { MarketplaceTabContent } from "@/app/profile/[address]/marketplace-tab-content";
import { BlueprintsTabContent } from "@/app/profile/[address]/blueprint-tab-content";
Expand Down
10 changes: 5 additions & 5 deletions components/allowlist/create-allowlist-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { ChangeEvent, useEffect, useState } from "react";
import {
Dialog,
DialogContent,
Expand All @@ -9,17 +8,18 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { LoaderCircle, MinusCircle, PlusCircle } from "lucide-react";
import { ChangeEvent, useEffect, useState } from "react";
import { isAddress } from "viem";

import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import { errorHasMessage } from "@/lib/errorHasMessage";
import { toast } from "@/components/ui/use-toast";
import { useValidateAllowlist } from "@/hypercerts/hooks/useCreateAllowLists";
import { errorHasMessage } from "@/lib/errorHasMessage";
import { cn } from "@/lib/utils";
import { AllowlistEntry } from "@hypercerts-org/sdk";

import { DEFAULT_NUM_UNITS } from "@/configs/hypercerts";
import { useValidateAllowList } from "@/hypercerts/hooks/useValidateAllowList";

type AllowListItem = {
address?: string;
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function Component({
isPending,
error: createAllowListError,
reset,
} = useValidateAllowlist();
} = useValidateAllowList();
const [allowList, setAllowList] = useState<AllowListItem[]>(
initialValues?.length ? initialValues : defaultValues,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Image from "next/image";
import { getHypercert } from "@/hypercerts/getHypercert";
import { getHypercert } from "@/hypercerts/actions/getHypercert";

export default async function HypercertRow({
hypercertId,
Expand Down
Loading