11"use client" ;
2-
3- import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors" ;
42import { CodeClient , CodeLoading } from "@/components/code/code.client" ;
53import { ScrollShadow } from "@/components/ui/ScrollShadow/ScrollShadow" ;
64import { Spinner } from "@/components/ui/Spinner/Spinner" ;
@@ -35,6 +33,7 @@ import {
3533 useForm ,
3634} from "react-hook-form" ;
3735import { z } from "zod" ;
36+ import { MultiNetworkSelector } from "../../../components/blocks/NetworkSelectors" ;
3837import type { BlueprintParameter , BlueprintPathMetadata } from "../utils" ;
3938
4039export function BlueprintPlayground ( props : {
@@ -156,14 +155,16 @@ export function BlueprintPlaygroundUI(props: {
156155 } , [ parameters ] ) ;
157156
158157 const defaultValues = useMemo ( ( ) => {
159- const values : Record < string , string | number > = { } ;
158+ const values : Record < string , string | number | string [ ] | number [ ] > = { } ;
160159 for ( const param of parameters ) {
161160 if ( param . schema && "type" in param . schema && param . schema . default ) {
162161 values [ param . name ] = param . schema . default ;
163162 } else if ( param . name === "filter_block_timestamp_gte" ) {
164163 values [ param . name ] = Math . floor (
165164 ( Date . now ( ) - 3 * 30 * 24 * 60 * 60 * 1000 ) / 1000 ,
166165 ) ;
166+ } else if ( param . name === "chain" ) {
167+ values [ param . name ] = [ ] ;
167168 } else {
168169 values [ param . name ] = "" ;
169170 }
@@ -407,7 +408,7 @@ function RequestConfigSection(props: {
407408}
408409
409410type ParametersForm = UseFormReturn < {
410- [ x : string ] : string | number ;
411+ [ x : string ] : string | number | string [ ] | number [ ] ;
411412} > ;
412413
413414function ParameterSection ( props : {
@@ -485,13 +486,15 @@ function ParameterSection(props: {
485486 </ div >
486487 < div className = "relative" >
487488 { param . name === "chain" ? (
488- < SingleNetworkSelector
489- chainId = {
490- field . value ? Number ( field . value ) : undefined
489+ < MultiNetworkSelector
490+ selectedBadgeClassName = "bg-background"
491+ selectedChainIds = {
492+ props . form . watch ( "chain" ) as number [ ]
491493 }
492- onChange = { ( chainId ) => {
493- field . onChange ( {
494- target : { value : chainId . toString ( ) } ,
494+ onChange = { ( chainIds ) => {
495+ props . form . setValue ( "chain" , chainIds , {
496+ shouldValidate : true ,
497+ shouldDirty : true ,
495498 } ) ;
496499 } }
497500 className = "rounded-none border-0 border-t lg:border-none"
@@ -502,11 +505,14 @@ function ParameterSection(props: {
502505 : undefined
503506 }
504507 />
505- ) : (
508+ ) : field . value && ! Array . isArray ( field . value ) ? (
506509 < >
507510 < ParameterInput
508511 param = { param }
509- field = { field }
512+ field = { {
513+ ...field ,
514+ value : field . value ,
515+ } }
510516 showTip = { showTip }
511517 hasError = { hasError }
512518 placeholder = { placeholder }
@@ -549,7 +555,7 @@ function ParameterSection(props: {
549555 </ ToolTipLabel >
550556 ) }
551557 </ >
552- ) }
558+ ) : null }
553559 </ div >
554560 </ div >
555561 < FormMessage className = "mt-0 border-destructive-text border-t px-3 py-2" />
@@ -780,6 +786,26 @@ function openAPIV3ParamToZodFormSchema(
780786 return isRequired ? booleanSchema : booleanSchema . optional ( ) ;
781787 }
782788
789+ case "array" : {
790+ if ( "type" in schema . items ) {
791+ let itemSchema : z . ZodTypeAny | undefined = undefined ;
792+ if ( schema . items . type === "number" ) {
793+ itemSchema = z . number ( ) ;
794+ } else if ( schema . items . type === "integer" ) {
795+ itemSchema = z . number ( ) . int ( ) ;
796+ } else if ( schema . items . type === "string" ) {
797+ itemSchema = z . string ( ) ;
798+ }
799+
800+ if ( itemSchema ) {
801+ return isRequired
802+ ? z . array ( itemSchema )
803+ : z . array ( itemSchema ) . optional ( ) ;
804+ }
805+ }
806+ break ;
807+ }
808+
783809 // everything else - just accept it as a string;
784810 default : {
785811 const stringSchema = z . string ( ) ;
@@ -840,7 +866,13 @@ function createBlueprintUrl(options: {
840866 for ( const parameter of queryParams ) {
841867 const value = values [ parameter . name ] ;
842868 if ( value ) {
843- searchParams . append ( parameter . name , value ) ;
869+ if ( Array . isArray ( value ) ) {
870+ for ( const v of value ) {
871+ searchParams . append ( parameter . name , v ) ;
872+ }
873+ } else {
874+ searchParams . append ( parameter . name , value ) ;
875+ }
844876 }
845877 }
846878
0 commit comments