11import { NextResponse } from "next/server" ;
22import type { ChainMetadata } from "thirdweb/chains" ;
3- import invariant from "tiny-invariant" ;
43
54export const maxDuration = 300 ; // max timeout 300 seconds (5min)
65export const revalidate = 86400 ; // Revalidate every 24 hours (86400 seconds)
76
8- export async function GET ( ) {
9- const bundlerServiceKey = process . env . BUNDLER_SERVICE_KEY ;
10- invariant ( bundlerServiceKey , "BUNDLER_SERVICE_KEY is not set" ) ;
7+ type ApiResponseType = {
8+ data : Record < string , { service : string ; enabled : boolean } [ ] > ;
9+ } ;
1110
12- const [ aaChains , allChains ] = await Promise . all ( [
13- fetch ( "https://1.bundler.thirdweb.com/service/chains" , {
11+ export async function GET ( ) {
12+ const [ chainsWithServices , allChains ] = await Promise . all ( [
13+ fetch ( "https://api.thirdweb.com/v1/chains/services" , {
1414 headers : {
1515 "Content-Type" : "application/json" ,
16- "x-service-api-key" : bundlerServiceKey ,
1716 } ,
1817 } )
19- . then ( ( res ) => res . json ( ) as Promise < { data : number [ ] } > )
18+ . then ( ( res ) => res . json ( ) as Promise < ApiResponseType > )
2019 . catch ( ( error ) => {
2120 console . error ( error ) ;
22- return { data : [ ] as number [ ] } ;
21+ return { data : { } as ApiResponseType [ "data" ] } ;
2322 } ) ,
2423 fetch ( "https://api.thirdweb.com/v1/chains" , {
2524 headers : {
@@ -33,9 +32,18 @@ export async function GET() {
3332 } ) ,
3433 ] ) ;
3534
35+ const aaChains = Object . entries ( chainsWithServices . data )
36+ . filter ( ( [ , services ] ) =>
37+ services . some (
38+ ( service ) =>
39+ service . service === "account-abstraction" && service . enabled ,
40+ ) ,
41+ )
42+ . map ( ( [ chainId ] ) => Number ( chainId ) ) ;
43+
3644 const intersectedChains = allChains . data
3745 . filter ( ( chain ) =>
38- aaChains . data . some ( ( aaChainId ) => aaChainId === chain . chainId ) ,
46+ aaChains . some ( ( aaChainId ) => aaChainId === chain . chainId ) ,
3947 )
4048 . filter ( ( c ) => c . name )
4149 . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
0 commit comments