Skip to content

Commit d606150

Browse files
fix: update useProfiles when connecting to different account (#5089)
1 parent 0898092 commit d606150

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
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

apps/portal/src/app/api/aa-chains/route.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { NextResponse } from "next/server";
22
import type { ChainMetadata } from "thirdweb/chains";
3-
import invariant from "tiny-invariant";
43

54
export const maxDuration = 300; // max timeout 300 seconds (5min)
65
export 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

Comments
 (0)