File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed
Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1- "use client ";
1+ import { isContract } from "@/lib/isContract ";
22
3- import { useIsContract } from "@/hooks/useIsContract" ;
3+ export async function ContractAccountBanner ( { address } : { address : string } ) {
4+ const isContractAddress = await isContract ( address ) ;
45
5- export function ContractAccountBanner ( { address } : { address : string } ) {
6- const { isContract, isLoading } = useIsContract ( address ) ;
7-
8- if ( ! isContract || isLoading ) return null ;
6+ if ( ! isContractAddress ) return null ;
97
108 return (
119 < div className = "bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-4" >
Original file line number Diff line number Diff line change 1+ import { ChainFactory } from "./chainFactory" ;
2+ import { EvmClientFactory } from "./evmClient" ;
3+ import { unstable_cache } from "next/cache" ;
4+
5+ export const isContract = unstable_cache (
6+ async ( address : string ) => {
7+ const supportedChains = ChainFactory . getSupportedChains ( ) ;
8+ const clients = supportedChains . map ( ( chainId ) =>
9+ EvmClientFactory . createClient ( chainId ) ,
10+ ) ;
11+
12+ const results = await Promise . allSettled (
13+ clients . map ( ( client ) =>
14+ client . getCode ( { address : address as `0x${string } ` } ) ,
15+ ) ,
16+ ) ;
17+
18+ return results . some (
19+ ( result ) =>
20+ result . status === "fulfilled" &&
21+ result . value !== undefined &&
22+ result . value !== "0x" ,
23+ ) ;
24+ } ,
25+ [ "isContract" ] ,
26+ { revalidate : 604800 } , // 1 week
27+ ) ;
You can’t perform that action at this time.
0 commit comments