@@ -29,7 +29,8 @@ import { ScrollIntoViewLink } from "../../../../../components/ScrollIntoViewLink
2929import { useChain } from "../../../../../hooks/useChain" ;
3030import { blockExplorerTransactionUrl } from "../../../../../utils/blockExplorerTransactionUrl" ;
3131import { getFunctionElementId } from "../../../../../utils/getFunctionElementId" ;
32- import { encodeFunctionArgs } from "../../explore/utils/encodeFunctionArgs" ;
32+ import { FunctionInput } from "./FunctionInput" ;
33+ import { encodeFunctionArgs } from "./encodeFunctionArgs" ;
3334
3435export enum FunctionType {
3536 READ ,
@@ -51,6 +52,7 @@ type DecodedEvent = {
5152const formSchema = z . object ( {
5253 inputs : z . array ( z . string ( ) ) ,
5354 value : z . string ( ) . optional ( ) ,
55+ resolvedAddresses : z . record ( z . string ( ) . optional ( ) ) . optional ( ) ,
5456} ) ;
5557
5658const getInputLabel = ( input : AbiParameter ) : string => {
@@ -66,20 +68,9 @@ const getInputLabel = (input: AbiParameter): string => {
6668 return input . type ;
6769} ;
6870
69- const getInputPlaceholder = ( input : AbiParameter ) : string => {
70- if ( ! ( "components" in input ) ) {
71- return input . type ;
72- }
73-
74- const componentsString = input . components . map ( getInputLabel ) . join ( ", " ) ;
75- if ( input . type === "tuple[]" ) {
76- return `[${ componentsString } ][]` ;
77- }
78- return `[${ componentsString } ]` ;
79- } ;
80-
8171export function FunctionField ( { systemId, worldAbi, functionAbi, useSearchParamsArgs } : Props ) {
8272 const searchParams = useSearchParams ( ) ;
73+ const { id : chainId } = useChain ( ) ;
8374 const publicClient = usePublicClient ( ) ;
8475 const operationType : FunctionType =
8576 functionAbi . stateMutability === "view" || functionAbi . stateMutability === "pure"
@@ -89,7 +80,6 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
8980 const wagmiConfig = useConfig ( ) ;
9081 const account = useAccount ( ) ;
9182 const { worldAddress } = useParams ( ) ;
92- const { id : chainId } = useChain ( ) ;
9383 const [ isLoading , setIsLoading ] = useState ( false ) ;
9484 const [ result , setResult ] = useState < string > ( ) ;
9585 const [ events , setEvents ] = useState < DecodedEvent [ ] > ( ) ;
@@ -103,6 +93,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
10393 defaultValues : {
10494 inputs : useSearchParamsArgs ? JSON . parse ( searchParams . get ( "args" ) || "[]" ) : [ ] ,
10595 value : useSearchParamsArgs ? searchParams . get ( "value" ) ?? "" : "" ,
96+ resolvedAddresses : { } ,
10697 } ,
10798 } ) ;
10899
@@ -150,14 +141,19 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
150141 setIsLoading ( true ) ;
151142 let toastId ;
152143
144+ const resolvedInputs = values . inputs . map ( ( input , index ) => {
145+ const resolvedAddress = form . getValues ( `resolvedAddresses.${ index } ` ) ;
146+ return resolvedAddress || input ;
147+ } ) ;
148+
153149 try {
154150 if ( operationType === FunctionType . READ ) {
155151 const { data : result } = await publicClient . call ( {
156152 account : account . address ,
157153 data : encodeFunctionData ( {
158154 abi : [ ...worldAbi , functionAbi ] ,
159155 functionName : functionAbi . name ,
160- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
156+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
161157 } ) ,
162158 to : worldAddress as Address ,
163159 } ) ;
@@ -171,7 +167,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
171167 const encoded = encodeSystemCall ( {
172168 abi : [ functionAbi ] ,
173169 functionName : functionAbi . name ,
174- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
170+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
175171 systemId,
176172 } ) ;
177173
@@ -188,7 +184,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
188184 abi : worldAbi ,
189185 address : worldAddress as Address ,
190186 functionName : functionAbi . name ,
191- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
187+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
192188 ...( values . value && { value : BigInt ( values . value ) } ) ,
193189 chainId,
194190 } ) ;
@@ -225,6 +221,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
225221 wagmiConfig ,
226222 worldAbi ,
227223 worldAddress ,
224+ form ,
228225 ] ,
229226 ) ;
230227
@@ -259,31 +256,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
259256 { functionAbi . inputs . length > 0 && (
260257 < div className = "!mt-2 space-y-2" >
261258 { functionAbi . inputs . map ( ( input , index ) => (
262- < FormField
263- key = { index }
264- control = { form . control }
265- name = { `inputs.${ index } ` }
266- render = { ( { field } ) => (
267- < FormItem className = "flex items-center gap-4 space-y-0" >
268- { input . name && (
269- < FormLabel className = "shrink-0 pt-1 font-mono text-sm opacity-70" > { input . name } </ FormLabel >
270- ) }
271- < div className = "flex-1" >
272- < FormControl >
273- < Input
274- placeholder = { getInputPlaceholder ( input ) }
275- value = { field . value }
276- onChange = { ( evt ) => {
277- field . onChange ( evt . target . value ) ;
278- } }
279- className = "font-mono text-sm"
280- />
281- </ FormControl >
282- < FormMessage />
283- </ div >
284- </ FormItem >
285- ) }
286- />
259+ < FunctionInput key = { index } input = { input } index = { index } />
287260 ) ) }
288261
289262 { functionAbi . stateMutability === "payable" && (
0 commit comments