Skip to content

Commit 438c019

Browse files
committed
replace chain with chain_id in insight playground (#7099)
## [Playground] Fix: Update chain parameter handling in blueprint playground ## Notes for the reviewer This PR updates the blueprint playground to use `chain_id` instead of `chain` parameter throughout the codebase. It also adds logic to remove deprecated parameters from the form schema and specifically removes the `chain` parameter if it's present. ## How to test Test the blueprint playground with various chain selections to ensure the chain_id parameter is correctly populated and that deprecated parameters are not displayed in the form. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated all references from "chain" to "chain_id" for improved consistency across the playground interface. - Deprecated parameters are now excluded from form generation and display. - **New Features** - Blueprint listings can now indicate if a blueprint is deprecated. - **Chores** - Made the API domain configurable via environment variables with a default fallback. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces changes to the `BlueprintSection`, `fetchBlueprintSpec`, and other components to enhance the handling of blueprint parameters, including the addition of a `deprecated` flag and renaming of parameters for consistency. It also updates the API URL handling. ### Detailed summary - Added optional `deprecated` property to `blueprints` in `BlueprintSection`. - Introduced `THIRDWEB_INSIGHT_API_DOMAIN` for dynamic API URL in `fetchBlueprintSpec`. - Renamed parameter `chain` to `chain_id` in multiple places for consistency. - Removed `chain` parameter if present in `modifyParametersForPlayground`. - Updated form handling to use `chain_id` instead of `chain` in `ParameterSection`. - Skipped deprecated parameters in schema creation with `createParametersFormSchema`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6104401 commit 438c019

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function modifyParametersForPlayground(_parameters: BlueprintParameter[]) {
109109
const parameters = [..._parameters];
110110

111111
// make chain query param required - its not required in open api spec - because it either has to be set in subdomain or as a query param
112-
const chainIdParameter = parameters.find((p) => p.name === "chain");
112+
const chainIdParameter = parameters.find((p) => p.name === "chain_id");
113113
if (chainIdParameter) {
114114
chainIdParameter.required = true;
115115
}
@@ -122,6 +122,12 @@ function modifyParametersForPlayground(_parameters: BlueprintParameter[]) {
122122
parameters.splice(clientIdParameterIndex, 1);
123123
}
124124

125+
// remove the chain parameter if it is present
126+
const chainParameterIndex = parameters.findIndex((p) => p.name === "chain");
127+
if (chainParameterIndex !== -1) {
128+
parameters.splice(chainParameterIndex, 1);
129+
}
130+
125131
return parameters;
126132
}
127133

@@ -163,7 +169,7 @@ function BlueprintPlaygroundUI(props: {
163169
values[param.name] = Math.floor(
164170
(Date.now() - 3 * 30 * 24 * 60 * 60 * 1000) / 1000,
165171
);
166-
} else if (param.name === "chain") {
172+
} else if (param.name === "chain_id") {
167173
values[param.name] = [];
168174
} else {
169175
values[param.name] = "";
@@ -466,7 +472,7 @@ function ParameterSection(props: {
466472
key={param.name}
467473
className={cn(
468474
"grid items-center",
469-
param.name === "chain"
475+
param.name === "chain_id"
470476
? "grid-cols-1 lg:grid-cols-2"
471477
: "grid-cols-2",
472478
)}
@@ -485,14 +491,14 @@ function ParameterSection(props: {
485491
)}
486492
</div>
487493
<div className="relative">
488-
{param.name === "chain" ? (
494+
{param.name === "chain_id" ? (
489495
<MultiNetworkSelector
490496
selectedBadgeClassName="bg-background"
491497
selectedChainIds={
492-
props.form.watch("chain") as number[]
498+
props.form.watch("chain_id") as number[]
493499
}
494500
onChange={(chainIds) => {
495-
props.form.setValue("chain", chainIds, {
501+
props.form.setValue("chain_id", chainIds, {
496502
shouldValidate: true,
497503
shouldDirty: true,
498504
});
@@ -821,6 +827,9 @@ function openAPIV3ParamToZodFormSchema(
821827
function createParametersFormSchema(parameters: BlueprintParameter[]) {
822828
const shape: z.ZodRawShape = {};
823829
for (const param of parameters) {
830+
if (param.deprecated) {
831+
continue;
832+
}
824833
const paramSchema = openAPIV3ParamToZodFormSchema(
825834
param.schema,
826835
!!param.required,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function Page() {
4141

4242
function BlueprintSection(props: {
4343
title: string;
44-
blueprints: { name: string; link: string }[];
44+
blueprints: { name: string; link: string; deprecated?: boolean }[];
4545
}) {
4646
return (
4747
<div className="overflow-hidden rounded-lg border bg-card">

apps/playground-web/src/app/insight/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import type { OpenAPIV3 } from "openapi-types";
66
export type BlueprintParameter = OpenAPIV3.ParameterObject;
77
export type BlueprintPathMetadata = OpenAPIV3.PathItemObject;
88

9+
const THIRDWEB_INSIGHT_API_DOMAIN =
10+
process.env.NEXT_PUBLIC_INSIGHT_URL || "insight.thirdweb.com";
11+
912
export type BlueprintListItem = {
1013
id: string;
1114
name: string;
@@ -40,7 +43,7 @@ export async function fetchBlueprintSpec(params: {
4043
blueprintId: string;
4144
}) {
4245
const res = await fetch(
43-
`https://insight.thirdweb.com/v1/blueprints/${params.blueprintId}`,
46+
`https://${THIRDWEB_INSIGHT_API_DOMAIN}/v1/blueprints/${params.blueprintId}`,
4447
);
4548

4649
if (!res.ok) {

0 commit comments

Comments
 (0)