Skip to content

Commit a066c4a

Browse files
committed
[TOOL-3942] Playground: Fix slow dev server - generate insight sidebar links with script
1 parent 5faaf1b commit a066c4a

File tree

7 files changed

+293
-77
lines changed

7 files changed

+293
-77
lines changed

apps/playground-web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "eslint ./src",
1212
"prefix": "biome check ./src --fix",
1313
"fix": "eslint ./src --fix",
14-
"typecheck": "tsc --noEmit"
14+
"typecheck": "tsc --noEmit",
15+
"update-insight-blueprints": "bun scripts/updateInsightBlueprints.ts"
1516
},
1617
"dependencies": {
1718
"@abstract-foundation/agw-client": "^1.6.2",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
3+
import { fetchAllBlueprints } from "./utils";
4+
5+
const blueprints = await fetchAllBlueprints();
6+
7+
const fileContent = `\
8+
// This file is auto-generated by the update-insight-blueprints script
9+
import type { MinimalBlueprintSpec } from "./utils";
10+
11+
export const insightBlueprints: MinimalBlueprintSpec[] = ${JSON.stringify(blueprints, null, 2)}`;
12+
13+
fs.writeFileSync(
14+
path.join(__dirname, "../src/app/insight/insightBlueprints.ts"),
15+
fileContent,
16+
);
17+
18+
console.log(
19+
"Updated insightBlueprints.ts - Please format this file and commit it",
20+
);

apps/playground-web/scripts/utils.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
type BlueprintListItem,
3+
type MinimalBlueprintSpec,
4+
fetchBlueprintSpec,
5+
} from "../src/app/insight/utils";
6+
7+
async function fetchBlueprintList() {
8+
const res = await fetch("https://insight.thirdweb.com/v1/blueprints");
9+
10+
if (!res.ok) {
11+
const text = await res.text();
12+
throw new Error(`Failed to fetch blueprints: ${text}`);
13+
}
14+
15+
const json = (await res.json()) as { data: BlueprintListItem[] };
16+
17+
return json.data;
18+
}
19+
20+
export const fetchAllBlueprints = async (): Promise<MinimalBlueprintSpec[]> => {
21+
try {
22+
// fetch list
23+
const blueprintSpecs = await fetchBlueprintList();
24+
25+
// fetch all blueprints
26+
const blueprints = await Promise.all(
27+
blueprintSpecs.map((spec) =>
28+
fetchBlueprintSpec({
29+
blueprintId: spec.id,
30+
}),
31+
),
32+
);
33+
34+
return blueprints.map((blueprint) => {
35+
const paths = Object.keys(blueprint.openapiJson.paths);
36+
return {
37+
id: blueprint.id,
38+
name: blueprint.name,
39+
paths: paths.map((pathName) => {
40+
const pathObj = blueprint.openapiJson.paths[pathName];
41+
if (!pathObj) {
42+
throw new Error(`Path not found: ${pathName}`);
43+
}
44+
45+
return {
46+
name: pathObj.get?.summary || "Unknown",
47+
path: pathName,
48+
};
49+
}),
50+
} satisfies MinimalBlueprintSpec;
51+
});
52+
} catch (error) {
53+
console.error(error);
54+
return [];
55+
}
56+
};
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// This file is auto-generated by the update-insight-blueprints script
2+
import type { MinimalBlueprintSpec } from "./utils";
3+
4+
export const insightBlueprints: MinimalBlueprintSpec[] = [
5+
{
6+
id: "transactions",
7+
name: "Transactions",
8+
paths: [
9+
{
10+
name: "Get transactions",
11+
path: "/v1/transactions",
12+
},
13+
{
14+
name: "Get contract transactions",
15+
path: "/v1/transactions/:contractAddress",
16+
},
17+
{
18+
name: "Get contract transactions with specific signature",
19+
path: "/v1/transactions/:contractAddress/:signature",
20+
},
21+
{
22+
name: "Get wallet transactions",
23+
path: "/v1/wallets/:wallet_address/transactions",
24+
},
25+
],
26+
},
27+
{
28+
id: "events",
29+
name: "Events",
30+
paths: [
31+
{
32+
name: "Get events",
33+
path: "/v1/events",
34+
},
35+
{
36+
name: "Get contract events",
37+
path: "/v1/events/:contractAddress",
38+
},
39+
{
40+
name: "Get contract events with specific signature",
41+
path: "/v1/events/:contractAddress/:signature",
42+
},
43+
],
44+
},
45+
{
46+
id: "tokens",
47+
name: "Tokens",
48+
paths: [
49+
{
50+
name: "Get token transfers by transaction",
51+
path: "/v1/tokens/transfers/transaction/:transaction_hash",
52+
},
53+
{
54+
name: "Get token transfers by contract",
55+
path: "/v1/tokens/transfers/:contract_address",
56+
},
57+
{
58+
name: "Get token transfers by wallet address",
59+
path: "/v1/tokens/transfers",
60+
},
61+
{
62+
name: "Get ERC-20 balances by address",
63+
path: "/v1/tokens/erc20/:ownerAddress",
64+
},
65+
{
66+
name: "Get ERC-721 balances by address",
67+
path: "/v1/tokens/erc721/:ownerAddress",
68+
},
69+
{
70+
name: "Get ERC-1155 balances by address",
71+
path: "/v1/tokens/erc1155/:ownerAddress",
72+
},
73+
{
74+
name: "Get supported tokens for price data",
75+
path: "/v1/tokens/price/supported",
76+
},
77+
{
78+
name: "Get token price",
79+
path: "/v1/tokens/price",
80+
},
81+
],
82+
},
83+
{
84+
id: "resolve",
85+
name: "Resolve",
86+
paths: [
87+
{
88+
name: "Resolve",
89+
path: "/v1/resolve/:input",
90+
},
91+
],
92+
},
93+
{
94+
id: "blocks",
95+
name: "Blocks",
96+
paths: [
97+
{
98+
name: "Get blocks",
99+
path: "/v1/blocks",
100+
},
101+
],
102+
},
103+
{
104+
id: "contracts",
105+
name: "Contracts",
106+
paths: [
107+
{
108+
name: "Get contract ABI​",
109+
path: "/v1/contracts/abi/:contractAddress",
110+
},
111+
{
112+
name: "Get contract metadata​",
113+
path: "/v1/contracts/metadata/:contractAddress",
114+
},
115+
],
116+
},
117+
{
118+
id: "decode",
119+
name: "Decode",
120+
paths: [
121+
{
122+
name: "Unknown",
123+
path: "/v1/decode/:contractAddress",
124+
},
125+
],
126+
},
127+
{
128+
id: "nfts",
129+
name: "Nfts",
130+
paths: [
131+
{
132+
name: "Get NFTs by owner",
133+
path: "/v1/nfts",
134+
},
135+
{
136+
name: "Get NFT owners by contract",
137+
path: "/v1/nfts/owners/:contract_address",
138+
},
139+
{
140+
name: "Get NFT owners by token",
141+
path: "/v1/nfts/owners/:contract_address/:token_id",
142+
},
143+
{
144+
name: "Get NFT transfers by owner",
145+
path: "/v1/nfts/transfers",
146+
},
147+
{
148+
name: "Get NFT transfers by transaction",
149+
path: "/v1/nfts/transfers/transaction/:transaction_hash",
150+
},
151+
{
152+
name: "Get NFT transfers by contract",
153+
path: "/v1/nfts/transfers/:contract_address",
154+
},
155+
{
156+
name: "Get NFTs by contract",
157+
path: "/v1/nfts/:contract_address",
158+
},
159+
{
160+
name: "Get NFT transfers by token",
161+
path: "/v1/nfts/transfers/:contract_address/:token_id",
162+
},
163+
{
164+
name: "Get NFT by token",
165+
path: "/v1/nfts/:contract_address/:token_id",
166+
},
167+
{
168+
name: "Force refresh collection metadata",
169+
path: "/v1/nfts/metadata/refresh/:contract_address",
170+
},
171+
{
172+
name: "Force refresh token metadata",
173+
path: "/v1/nfts/metadata/refresh/:contract_address/:token_id",
174+
},
175+
],
176+
},
177+
{
178+
id: "wallets",
179+
name: "Wallets",
180+
paths: [
181+
{
182+
name: "Get wallet transactions",
183+
path: "/v1/wallets/:wallet_address/transactions",
184+
},
185+
],
186+
},
187+
];

apps/playground-web/src/app/insight/page.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
2-
import {} from "lucide-react";
32
import Link from "next/link";
4-
import { fetchAllBlueprints } from "./utils";
5-
6-
export default async function Page() {
7-
const blueprints = await fetchAllBlueprints();
3+
import { insightBlueprints } from "./insightBlueprints";
84

5+
export default function Page() {
96
return (
107
<div className="pb-20">
118
<h2 className="mb-2 font-semibold text-2xl tracking-tight">Blueprints</h2>
@@ -23,22 +20,15 @@ export default async function Page() {
2320
</p>
2421

2522
<div className="flex flex-col gap-8">
26-
{blueprints.map((blueprint) => {
27-
const paths = Object.keys(blueprint.openapiJson.paths);
28-
23+
{insightBlueprints.map((blueprint) => {
2924
return (
3025
<BlueprintSection
3126
key={blueprint.id}
32-
blueprintId={blueprint.id}
3327
title={blueprint.name}
34-
blueprints={paths.map((pathName) => {
35-
const pathObj = blueprint.openapiJson.paths[pathName];
36-
if (!pathObj) {
37-
throw new Error(`Path not found: ${pathName}`);
38-
}
28+
blueprints={blueprint.paths.map((pathInfo) => {
3929
return {
40-
name: pathObj.get?.summary || "Unknown",
41-
link: `/insight/${blueprint.id}?path=${pathName}`,
30+
name: pathInfo.name,
31+
link: `/insight/${blueprint.id}?path=${pathInfo.path}`,
4232
};
4333
})}
4434
/>
@@ -51,7 +41,6 @@ export default async function Page() {
5141

5242
function BlueprintSection(props: {
5343
title: string;
54-
blueprintId: string;
5544
blueprints: { name: string; link: string }[];
5645
}) {
5746
return (

0 commit comments

Comments
 (0)