1- "use client" ;
2-
31import { Badge } from "@/components/ui/badge" ;
42import { Button } from "@/components/ui/button" ;
5- import { Skeleton , SkeletonContainer } from "@/components/ui/skeleton" ;
3+ import { SkeletonContainer } from "@/components/ui/skeleton" ;
64import { TrackedLinkTW } from "@/components/ui/tracked-link" ;
7- import { useThirdwebClient } from "@/constants/thirdweb.client " ;
5+ import { getThirdwebClient } from "@/constants/thirdweb.server " ;
86import { resolveSchemeWithErrorHandler } from "@/lib/resolveSchemeWithErrorHandler" ;
97import { cn } from "@/lib/utils" ;
10- import { useQuery } from "@tanstack/react-query" ;
118import { moduleToBase64 } from "app/(dashboard)/published-contract/utils/module-base-64" ;
129import { RocketIcon , ShieldCheckIcon } from "lucide-react" ;
1310import Link from "next/link" ;
14- import invariant from "tiny-invariant" ;
1511import { fetchPublishedContractVersion } from "../../contract-components/fetch-contracts-with-versions" ;
1612import { 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}
0 commit comments