11import type { NextApiRequest , NextApiResponse } from "next" ;
22import { getProvider } from "@/utils/get-provider" ;
3+ import { cors } from "@/lib/cors" ;
34
45export default async function handler (
56 req : NextApiRequest ,
67 res : NextApiResponse ,
78) {
9+ await cors ( req , res ) ;
10+ if ( req . method === "OPTIONS" ) {
11+ return res . status ( 200 ) . end ( ) ;
12+ }
13+
814 if ( req . method !== "GET" ) {
915 return res . status ( 405 ) . json ( { error : "Method Not Allowed" } ) ;
1016 }
1117
1218 const { pubKeyHashes, network = "1" } = req . query ;
1319
1420 if ( typeof pubKeyHashes !== "string" ) {
15- return res . status ( 400 ) . json ( { error : "Missing or invalid pubKeyHashes parameter" } ) ;
21+ return res
22+ . status ( 400 )
23+ . json ( { error : "Missing or invalid pubKeyHashes parameter" } ) ;
1624 }
1725
1826 const hashes = pubKeyHashes . split ( "," ) . map ( ( s ) => s . trim ( ) . toLowerCase ( ) ) ;
19- console . log ( hashes )
27+ console . log ( hashes ) ;
2028 const networkId = parseInt ( network as string , 10 ) ;
2129
2230 const provider = getProvider ( networkId ) ;
2331
2432 try {
25- const response = await provider . get ( ' /metadata/txs/labels/1854' ) ;
33+ const response = await provider . get ( " /metadata/txs/labels/1854" ) ;
2634
2735 if ( ! Array . isArray ( response ) ) {
2836 throw new Error ( "Invalid response format from provider" ) ;
@@ -36,7 +44,7 @@ export default async function handler(
3644 const matchedItems = validItems . filter ( ( item : any ) => {
3745 const participants = item . json_metadata . participants ;
3846 return Object . keys ( participants ) . some ( ( hash : string ) =>
39- hashes . includes ( hash . toLowerCase ( ) )
47+ hashes . includes ( hash . toLowerCase ( ) ) ,
4048 ) ;
4149 } ) ;
4250
@@ -45,4 +53,4 @@ export default async function handler(
4553 console . error ( "lookupWallet error:" , error ) ;
4654 res . status ( 500 ) . json ( { error : "Internal Server Error" } ) ;
4755 }
48- }
56+ }
0 commit comments