Skip to content

[TOOL-3942] Playground: Fix slow dev server - generate insight sidebar links with script #6631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/playground-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint": "eslint ./src",
"prefix": "biome check ./src --fix",
"fix": "eslint ./src --fix",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"update-insight-blueprints": "bun scripts/updateInsightBlueprints.ts"
},
"dependencies": {
"@abstract-foundation/agw-client": "^1.6.2",
Expand Down
20 changes: 20 additions & 0 deletions apps/playground-web/scripts/updateInsightBlueprints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as fs from "node:fs";
import * as path from "node:path";
import { fetchAllBlueprints } from "./utils";

const blueprints = await fetchAllBlueprints();

const fileContent = `\
// This file is auto-generated by the update-insight-blueprints script
import type { MinimalBlueprintSpec } from "./utils";

export const insightBlueprints: MinimalBlueprintSpec[] = ${JSON.stringify(blueprints, null, 2)}`;

fs.writeFileSync(
path.join(__dirname, "../src/app/insight/insightBlueprints.ts"),
fileContent,
);

console.log(
"Updated insightBlueprints.ts - Please format this file and commit it",
);
56 changes: 56 additions & 0 deletions apps/playground-web/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
type BlueprintListItem,
type MinimalBlueprintSpec,
fetchBlueprintSpec,
} from "../src/app/insight/utils";

async function fetchBlueprintList() {
const res = await fetch("https://insight.thirdweb.com/v1/blueprints");

if (!res.ok) {
const text = await res.text();
throw new Error(`Failed to fetch blueprints: ${text}`);
}

const json = (await res.json()) as { data: BlueprintListItem[] };

return json.data;
}

export const fetchAllBlueprints = async (): Promise<MinimalBlueprintSpec[]> => {
try {
// fetch list
const blueprintSpecs = await fetchBlueprintList();

// fetch all blueprints
const blueprints = await Promise.all(
blueprintSpecs.map((spec) =>
fetchBlueprintSpec({
blueprintId: spec.id,
}),
),
);

return blueprints.map((blueprint) => {
const paths = Object.keys(blueprint.openapiJson.paths);
return {
id: blueprint.id,
name: blueprint.name,
paths: paths.map((pathName) => {
const pathObj = blueprint.openapiJson.paths[pathName];
if (!pathObj) {
throw new Error(`Path not found: ${pathName}`);
}

return {
name: pathObj.get?.summary || "Unknown",
path: pathName,
};
}),
} satisfies MinimalBlueprintSpec;
});
} catch (error) {
console.error(error);
return [];
}
};
187 changes: 187 additions & 0 deletions apps/playground-web/src/app/insight/insightBlueprints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// This file is auto-generated by the update-insight-blueprints script
import type { MinimalBlueprintSpec } from "./utils";

export const insightBlueprints: MinimalBlueprintSpec[] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't generate these from the downloaded files? would be generated when running the script i guess

Copy link
Member Author

@MananTank MananTank Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, This file is auto generated when running the script

{
id: "transactions",
name: "Transactions",
paths: [
{
name: "Get transactions",
path: "/v1/transactions",
},
{
name: "Get contract transactions",
path: "/v1/transactions/:contractAddress",
},
{
name: "Get contract transactions with specific signature",
path: "/v1/transactions/:contractAddress/:signature",
},
{
name: "Get wallet transactions",
path: "/v1/wallets/:wallet_address/transactions",
},
],
},
{
id: "events",
name: "Events",
paths: [
{
name: "Get events",
path: "/v1/events",
},
{
name: "Get contract events",
path: "/v1/events/:contractAddress",
},
{
name: "Get contract events with specific signature",
path: "/v1/events/:contractAddress/:signature",
},
],
},
{
id: "tokens",
name: "Tokens",
paths: [
{
name: "Get token transfers by transaction",
path: "/v1/tokens/transfers/transaction/:transaction_hash",
},
{
name: "Get token transfers by contract",
path: "/v1/tokens/transfers/:contract_address",
},
{
name: "Get token transfers by wallet address",
path: "/v1/tokens/transfers",
},
{
name: "Get ERC-20 balances by address",
path: "/v1/tokens/erc20/:ownerAddress",
},
{
name: "Get ERC-721 balances by address",
path: "/v1/tokens/erc721/:ownerAddress",
},
{
name: "Get ERC-1155 balances by address",
path: "/v1/tokens/erc1155/:ownerAddress",
},
{
name: "Get supported tokens for price data",
path: "/v1/tokens/price/supported",
},
{
name: "Get token price",
path: "/v1/tokens/price",
},
],
},
{
id: "resolve",
name: "Resolve",
paths: [
{
name: "Resolve",
path: "/v1/resolve/:input",
},
],
},
{
id: "blocks",
name: "Blocks",
paths: [
{
name: "Get blocks",
path: "/v1/blocks",
},
],
},
{
id: "contracts",
name: "Contracts",
paths: [
{
name: "Get contract ABI​",
path: "/v1/contracts/abi/:contractAddress",
},
{
name: "Get contract metadata​",
path: "/v1/contracts/metadata/:contractAddress",
},
],
},
{
id: "decode",
name: "Decode",
paths: [
{
name: "Unknown",
path: "/v1/decode/:contractAddress",
},
],
},
{
id: "nfts",
name: "Nfts",
paths: [
{
name: "Get NFTs by owner",
path: "/v1/nfts",
},
{
name: "Get NFT owners by contract",
path: "/v1/nfts/owners/:contract_address",
},
{
name: "Get NFT owners by token",
path: "/v1/nfts/owners/:contract_address/:token_id",
},
{
name: "Get NFT transfers by owner",
path: "/v1/nfts/transfers",
},
{
name: "Get NFT transfers by transaction",
path: "/v1/nfts/transfers/transaction/:transaction_hash",
},
{
name: "Get NFT transfers by contract",
path: "/v1/nfts/transfers/:contract_address",
},
{
name: "Get NFTs by contract",
path: "/v1/nfts/:contract_address",
},
{
name: "Get NFT transfers by token",
path: "/v1/nfts/transfers/:contract_address/:token_id",
},
{
name: "Get NFT by token",
path: "/v1/nfts/:contract_address/:token_id",
},
{
name: "Force refresh collection metadata",
path: "/v1/nfts/metadata/refresh/:contract_address",
},
{
name: "Force refresh token metadata",
path: "/v1/nfts/metadata/refresh/:contract_address/:token_id",
},
],
},
{
id: "wallets",
name: "Wallets",
paths: [
{
name: "Get wallet transactions",
path: "/v1/wallets/:wallet_address/transactions",
},
],
},
];
23 changes: 6 additions & 17 deletions apps/playground-web/src/app/insight/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
import {} from "lucide-react";
import Link from "next/link";
import { fetchAllBlueprints } from "./utils";

export default async function Page() {
const blueprints = await fetchAllBlueprints();
import { insightBlueprints } from "./insightBlueprints";

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

<div className="flex flex-col gap-8">
{blueprints.map((blueprint) => {
const paths = Object.keys(blueprint.openapiJson.paths);

{insightBlueprints.map((blueprint) => {
return (
<BlueprintSection
key={blueprint.id}
blueprintId={blueprint.id}
title={blueprint.name}
blueprints={paths.map((pathName) => {
const pathObj = blueprint.openapiJson.paths[pathName];
if (!pathObj) {
throw new Error(`Path not found: ${pathName}`);
}
blueprints={blueprint.paths.map((pathInfo) => {
return {
name: pathObj.get?.summary || "Unknown",
link: `/insight/${blueprint.id}?path=${pathName}`,
name: pathInfo.name,
link: `/insight/${blueprint.id}?path=${pathInfo.path}`,
};
})}
/>
Expand All @@ -51,7 +41,6 @@ export default async function Page() {

function BlueprintSection(props: {
title: string;
blueprintId: string;
blueprints: { name: string; link: string }[];
}) {
return (
Expand Down
Loading
Loading