-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
portal: show all supported chains in AA docs (#5090)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `Document` component by adding the `AAChainList` feature, which fetches and displays account abstraction chains. It also improves the API route for fetching chain data. ### Detailed summary - Added `AAChainList` component in `apps/portal/src/components/Document/AAChainList.tsx`. - Implemented `getChains` function to fetch account abstraction chains. - Updated API route in `apps/portal/src/app/api/aa-chains/route.ts` to fetch services and chains. - Integrated `AAChainList` in the `page.mdx` for displaying available chains. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
40aeb52
commit 50f98d7
Showing
5 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Fix useProfiles not updating when connecting to a different account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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<string, { service: string; enabled: boolean }[]>; | ||
}; | ||
|
||
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<ApiResponseType>) | ||
.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, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import { cn } from "@/lib/utils"; | ||
import type { ChainMetadata } from "thirdweb/chains"; | ||
import { getBaseUrl } from "../../lib/getBaseUrl"; | ||
|
||
async function getChains(): Promise<ChainMetadata[]> { | ||
try { | ||
const chains = await fetch(`${getBaseUrl()}/api/aa-chains`); | ||
if (!chains.ok) { | ||
return []; | ||
} | ||
const result = (await chains.json()) as { data: ChainMetadata[] }; | ||
return result.data; | ||
} catch (error) { | ||
console.error(error); | ||
return []; | ||
} | ||
} | ||
|
||
export async function AAChainList() { | ||
const chains = await getChains(); | ||
return ( | ||
<div className={cn("my-4 rounded-lg border p-4")}> | ||
<ul className="grid grid-cols-1 gap-2 md:grid-cols-2"> | ||
{chains?.map((chain) => ( | ||
<li key={chain.name} className="flex items-center"> | ||
{chain.name} ({chain.chainId}) | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters