Skip to content

Commit 01bb690

Browse files
committed
Move /explore page to RSCs
1 parent bc5b543 commit 01bb690

File tree

2 files changed

+45
-73
lines changed

2 files changed

+45
-73
lines changed

apps/dashboard/src/components/explore/contract-card/index.tsx

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
"use client";
2-
31
import { Badge } from "@/components/ui/badge";
42
import { Button } from "@/components/ui/button";
5-
import { Skeleton, SkeletonContainer } from "@/components/ui/skeleton";
3+
import { SkeletonContainer } from "@/components/ui/skeleton";
64
import { TrackedLinkTW } from "@/components/ui/tracked-link";
7-
import { useThirdwebClient } from "@/constants/thirdweb.client";
5+
import { getThirdwebClient } from "@/constants/thirdweb.server";
86
import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler";
97
import { cn } from "@/lib/utils";
10-
import { useQuery } from "@tanstack/react-query";
118
import { moduleToBase64 } from "app/(dashboard)/published-contract/utils/module-base-64";
129
import { RocketIcon, ShieldCheckIcon } from "lucide-react";
1310
import Link from "next/link";
14-
import invariant from "tiny-invariant";
1511
import { fetchPublishedContractVersion } from "../../contract-components/fetch-contracts-with-versions";
1612
import { ContractPublisher, replaceDeployerAddress } from "../publisher";
1713

@@ -80,7 +76,7 @@ function getContractUrl(
8076
return replaceDeployerAddress(pathName);
8177
}
8278

83-
export const ContractCard: React.FC<ContractCardProps> = ({
79+
export async function ContractCard({
8480
publisher,
8581
contractId,
8682
titleOverride,
@@ -89,25 +85,28 @@ export const ContractCard: React.FC<ContractCardProps> = ({
8985
tracking,
9086
modules = [],
9187
isBeta,
92-
}) => {
93-
const client = useThirdwebClient();
94-
const publishedContractResult = usePublishedContract(
95-
`${publisher}/${contractId}/${version}`,
96-
);
88+
}: ContractCardProps) {
89+
const client = getThirdwebClient();
90+
const publishedContractResult = await fetchPublishedContractVersion(
91+
publisher,
92+
contractId,
93+
version,
94+
).catch(() => null);
9795

98-
const showSkeleton = publishedContractResult.isPending;
96+
if (!publishedContractResult) {
97+
return null;
98+
}
9999

100100
const auditLink = resolveSchemeWithErrorHandler({
101-
uri: publishedContractResult.data?.audit,
101+
uri: publishedContractResult.audit,
102102
client,
103103
});
104104

105105
return (
106106
<article
107-
className={cn(
108-
"relative flex min-h-[220px] flex-col rounded-lg border border-border p-4",
109-
!showSkeleton ? "bg-muted/50 hover:bg-muted" : "pointer-events-none",
110-
)}
107+
className={
108+
"relative flex min-h-[220px] flex-col rounded-lg border border-border bg-muted/50 p-4 hover:bg-muted"
109+
}
111110
>
112111
<TrackedLinkTW
113112
className="absolute inset-0 z-0 cursor-pointer"
@@ -149,7 +148,7 @@ export const ContractCard: React.FC<ContractCardProps> = ({
149148
{/* Version */}
150149
<SkeletonContainer
151150
skeletonData="0.0.0"
152-
loadedData={publishedContractResult.data?.version}
151+
loadedData={publishedContractResult.version}
153152
render={(v) => {
154153
return (
155154
<p className="font-medium text-muted-foreground text-sm">
@@ -175,8 +174,8 @@ export const ContractCard: React.FC<ContractCardProps> = ({
175174
skeletonData="Edition Drop"
176175
loadedData={
177176
titleOverride ||
178-
publishedContractResult.data?.displayName ||
179-
publishedContractResult.data?.name
177+
publishedContractResult.displayName ||
178+
publishedContractResult.name
180179
}
181180
render={(v) => {
182181
return (
@@ -187,17 +186,10 @@ export const ContractCard: React.FC<ContractCardProps> = ({
187186
}}
188187
/>
189188

190-
{publishedContractResult.data ? (
191-
<p className="mt-1 text-muted-foreground text-sm leading-5">
192-
{descriptionOverride || publishedContractResult.data?.description}
193-
</p>
194-
) : (
195-
<div className="mt-1">
196-
<Skeleton className="h-4 w-[80%]" />
197-
<div className="h-1" />
198-
<Skeleton className="h-4 w-[60%]" />
199-
</div>
200-
)}
189+
<p className="mt-1 text-muted-foreground text-sm leading-5">
190+
{descriptionOverride || publishedContractResult.description}
191+
</p>
192+
201193
{modules.length ? (
202194
<div className="mt-auto flex flex-row flex-wrap gap-1 pt-3">
203195
{modules.slice(0, 2).map((m) => (
@@ -216,10 +208,9 @@ export const ContractCard: React.FC<ContractCardProps> = ({
216208
!modules?.length && "mt-auto",
217209
)}
218210
>
219-
<ContractPublisher
220-
addressOrEns={publishedContractResult.data?.publisher}
221-
showSkeleton={showSkeleton}
222-
/>
211+
{publishedContractResult.publisher && (
212+
<ContractPublisher addressOrEns={publishedContractResult.publisher} />
213+
)}
223214

224215
<div className="flex items-center justify-between">
225216
<Button
@@ -247,22 +238,4 @@ export const ContractCard: React.FC<ContractCardProps> = ({
247238
</div>
248239
</article>
249240
);
250-
};
251-
252-
// data fetching
253-
type PublishedContractId =
254-
| `${string}/${string}`
255-
| `${string}/${string}/${string}`;
256-
257-
function usePublishedContract(publishedContractId: PublishedContractId) {
258-
const [publisher, contractId, version] = publishedContractId.split("/");
259-
return useQuery({
260-
queryKey: ["published-contract", { publishedContractId }],
261-
queryFn: () => {
262-
invariant(publisher, "publisher is required");
263-
invariant(contractId, "contractId is required");
264-
return fetchPublishedContractVersion(publisher, contractId, version);
265-
},
266-
enabled: !!publisher || !!contractId,
267-
});
268241
}

apps/dashboard/src/components/explore/publisher/index.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
1-
import { SkeletonContainer } from "@/components/ui/skeleton";
2-
import { useEns } from "components/contract-components/hooks";
31
import { PublisherAvatar } from "components/contract-components/publisher/masked-avatar";
42
import Link from "next/link";
5-
import type { RequiredParam } from "utils/types";
63
import { shortenIfAddress } from "utils/usedapp-external";
4+
import { isEnsName, resolveEns } from "../../../lib/ens";
75

86
interface ContractPublisherProps {
9-
addressOrEns: RequiredParam<string>;
10-
showSkeleton?: boolean;
7+
addressOrEns: string;
118
}
129

13-
export const ContractPublisher: React.FC<ContractPublisherProps> = ({
10+
export const ContractPublisher: React.FC<ContractPublisherProps> = async ({
1411
addressOrEns,
15-
showSkeleton,
1612
}) => {
17-
const ensQuery = useEns(addressOrEns || undefined);
13+
let ensOrAddressToShow = addressOrEns;
14+
15+
if (!isEnsName(addressOrEns)) {
16+
try {
17+
const res = await resolveEns(addressOrEns);
18+
if (res.ensName) {
19+
ensOrAddressToShow = res.ensName;
20+
}
21+
} catch {
22+
// ignore
23+
}
24+
}
1825

1926
return (
2027
<Link
2128
className="flex shrink-0 items-center gap-1.5 hover:underline"
22-
href={replaceDeployerAddress(
23-
`/${ensQuery.data?.ensName || ensQuery.data?.address || addressOrEns}`,
24-
)}
29+
href={replaceDeployerAddress(`/${ensOrAddressToShow}`)}
2530
>
2631
<PublisherAvatar
27-
isPending={showSkeleton}
32+
isPending={false}
2833
boxSize={5}
2934
address={addressOrEns || ""}
3035
/>
3136

32-
<SkeletonContainer
33-
loadedData={
34-
ensQuery.data?.ensName || ensQuery.data?.address || addressOrEns || ""
35-
}
36-
skeletonData=""
37-
render={(v) => <p className="text-xs"> {treatAddress(v)} </p>}
38-
/>
37+
<p className="text-xs"> {treatAddress(ensOrAddressToShow)} </p>
3938
</Link>
4039
);
4140
};

0 commit comments

Comments
 (0)