diff --git a/apps/portal/src/app/api/aa-chains/route.ts b/apps/portal/src/app/api/aa-chains/route.ts deleted file mode 100644 index 1ec580c67b2..00000000000 --- a/apps/portal/src/app/api/aa-chains/route.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { NextResponse } from "next/server"; -import type { ChainMetadata } from "thirdweb/chains"; - -export const maxDuration = 300; // max timeout 300 seconds (5min) -export const revalidate = 86400; // Revalidate every 24 hours (86400 seconds) - -type ApiResponseType = { - data: Record; -}; - -export async function GET() { - const [chainsWithServices, allChains] = await Promise.all([ - fetch("https://api.thirdweb.com/v1/chains/services", { - headers: { - "Content-Type": "application/json", - }, - }) - .then((res) => res.json() as Promise) - .catch((error) => { - console.error(error); - return { data: {} as ApiResponseType["data"] }; - }), - fetch("https://api.thirdweb.com/v1/chains", { - headers: { - "Content-Type": "application/json", - }, - }) - .then((res) => res.json() as Promise<{ data: ChainMetadata[] }>) - .catch((error) => { - console.error(error); - return { data: [] as ChainMetadata[] }; - }), - ]); - - const aaChains = Object.entries(chainsWithServices.data) - .filter(([, services]) => - services.some( - (service) => - service.service === "account-abstraction" && service.enabled, - ), - ) - .map(([chainId]) => Number(chainId)); - - const intersectedChains = allChains.data - .filter((chain) => - aaChains.some((aaChainId) => aaChainId === chain.chainId), - ) - .filter((c) => c.name) - .sort((a, b) => a.name.localeCompare(b.name)); - - return NextResponse.json({ - data: intersectedChains, - }); -} diff --git a/apps/portal/src/components/Document/AAChainList.tsx b/apps/portal/src/components/Document/AAChainList.tsx index bf359869638..357928def46 100644 --- a/apps/portal/src/components/Document/AAChainList.tsx +++ b/apps/portal/src/components/Document/AAChainList.tsx @@ -1,19 +1,45 @@ /* eslint-disable @next/next/no-img-element */ import { cn } from "@/lib/utils"; import type { ChainMetadata } from "thirdweb/chains"; -import { getBaseUrl } from "../../lib/getBaseUrl"; + +type ApiResponseType = { + data: Record; +}; async function getChains(): Promise { try { - const chains = await fetch(`${getBaseUrl()}/api/aa-chains`); - if (!chains.ok) { - return []; - } - const result = (await chains.json()) as { data: ChainMetadata[] }; - return result.data; + const [chainsWithServices, allChains] = await Promise.all([ + fetch("https://api.thirdweb.com/v1/chains/services", { + headers: { + "Content-Type": "application/json", + }, + }).then((res) => res.json() as Promise), + fetch("https://api.thirdweb.com/v1/chains", { + headers: { + "Content-Type": "application/json", + }, + }).then((res) => res.json() as Promise<{ data: ChainMetadata[] }>), + ]); + + const aaChains = Object.entries(chainsWithServices.data) + .filter(([, services]) => + services.some( + (service) => + service.service === "account-abstraction" && service.enabled, + ), + ) + .map(([chainId]) => Number(chainId)); + + const intersectedChains = allChains.data + .filter((chain) => + aaChains.some((aaChainId) => aaChainId === chain.chainId), + ) + .filter((c) => c.name) + .sort((a, b) => a.name.localeCompare(b.name)); + return intersectedChains; } catch (error) { - console.error(error); - return []; + console.error("Failed to fetch chains", error); + throw error; } }