Skip to content

Commit 50f98d7

Browse files
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 -->
1 parent 40aeb52 commit 50f98d7

File tree

5 files changed

+95
-38
lines changed

5 files changed

+95
-38
lines changed

.changeset/stale-fans-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix useProfiles not updating when connecting to a different account
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { NextResponse } from "next/server";
2+
import type { ChainMetadata } from "thirdweb/chains";
3+
4+
export const maxDuration = 300; // max timeout 300 seconds (5min)
5+
export const revalidate = 86400; // Revalidate every 24 hours (86400 seconds)
6+
7+
type ApiResponseType = {
8+
data: Record<string, { service: string; enabled: boolean }[]>;
9+
};
10+
11+
export async function GET() {
12+
const [chainsWithServices, allChains] = await Promise.all([
13+
fetch("https://api.thirdweb.com/v1/chains/services", {
14+
headers: {
15+
"Content-Type": "application/json",
16+
},
17+
})
18+
.then((res) => res.json() as Promise<ApiResponseType>)
19+
.catch((error) => {
20+
console.error(error);
21+
return { data: {} as ApiResponseType["data"] };
22+
}),
23+
fetch("https://api.thirdweb.com/v1/chains", {
24+
headers: {
25+
"Content-Type": "application/json",
26+
},
27+
})
28+
.then((res) => res.json() as Promise<{ data: ChainMetadata[] }>)
29+
.catch((error) => {
30+
console.error(error);
31+
return { data: [] as ChainMetadata[] };
32+
}),
33+
]);
34+
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+
44+
const intersectedChains = allChains.data
45+
.filter((chain) =>
46+
aaChains.some((aaChainId) => aaChainId === chain.chainId),
47+
)
48+
.filter((c) => c.name)
49+
.sort((a, b) => a.name.localeCompare(b.name));
50+
51+
return NextResponse.json({
52+
data: intersectedChains,
53+
});
54+
}

apps/portal/src/app/connect/account-abstraction/infrastructure/page.mdx

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMetadata } from "@doc";
1+
import { createMetadata, AAChainList } from "@doc";
22

33
export const metadata = createMetadata({
44
image: {
@@ -23,43 +23,7 @@ You can configure your client ID to restrict interactions only with your own con
2323

2424
With a thirdweb API key, you get access to bundler and paymaster infrastructure on the following chains:
2525

26-
| Chain | Mainnet | Testnet |
27-
| -------------------- | ------- | ------- |
28-
| Ethereum |||
29-
| Polygon |||
30-
| Arbitrum (one, nova) |||
31-
| Optimism |||
32-
| Gnosis |||
33-
| Linea |||
34-
| Base |||
35-
| Avalanche C-Chain |||
36-
| Scroll |||
37-
| Celo |||
38-
| Binance |||
39-
| Xai Orbit |||
40-
| Mode |||
41-
| Zora |||
42-
| Fraxtal |||
43-
| Lisk |||
44-
| Taiko |||
45-
| Degen |||
46-
| Mantle |||
47-
| Ancient8 |||
48-
| Blast |||
49-
| B3 |||
50-
| Plume |||
51-
| Camp Network |||
52-
| Vanar |||
53-
| DFK |||
54-
| Form |||
55-
| Cyber |||
56-
| Treasure Ruby |||
57-
| Redstone |||
58-
| Klaytn Cypress |||
59-
| OpBNB |||
60-
| Nautilus |||
61-
| Fuse |||
62-
| zkCandy |||
26+
<AAChainList />
6327

6428
To support a chain not listed, [contact us](https://thirdweb.com/contact-us).
6529

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* eslint-disable @next/next/no-img-element */
2+
import { cn } from "@/lib/utils";
3+
import type { ChainMetadata } from "thirdweb/chains";
4+
import { getBaseUrl } from "../../lib/getBaseUrl";
5+
6+
async function getChains(): Promise<ChainMetadata[]> {
7+
try {
8+
const chains = await fetch(`${getBaseUrl()}/api/aa-chains`);
9+
if (!chains.ok) {
10+
return [];
11+
}
12+
const result = (await chains.json()) as { data: ChainMetadata[] };
13+
return result.data;
14+
} catch (error) {
15+
console.error(error);
16+
return [];
17+
}
18+
}
19+
20+
export async function AAChainList() {
21+
const chains = await getChains();
22+
return (
23+
<div className={cn("my-4 rounded-lg border p-4")}>
24+
<ul className="grid grid-cols-1 gap-2 md:grid-cols-2">
25+
{chains?.map((chain) => (
26+
<li key={chain.name} className="flex items-center">
27+
{chain.name} ({chain.chainId})
28+
</li>
29+
))}
30+
</ul>
31+
</div>
32+
);
33+
}

apps/portal/src/components/Document/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export { Stack } from "./Stack";
2525
export { createMetadata } from "./metadata";
2626
export { ConnectCard } from "./Cards/ConnectCard";
2727
export { FeatureCard } from "./FeatureCard";
28+
export { AAChainList } from "./AAChainList";

0 commit comments

Comments
 (0)