@@ -29,7 +29,8 @@ import { ScrollIntoViewLink } from "../../../../../components/ScrollIntoViewLink
29
29
import { useChain } from "../../../../../hooks/useChain" ;
30
30
import { blockExplorerTransactionUrl } from "../../../../../utils/blockExplorerTransactionUrl" ;
31
31
import { getFunctionElementId } from "../../../../../utils/getFunctionElementId" ;
32
- import { encodeFunctionArgs } from "../../explore/utils/encodeFunctionArgs" ;
32
+ import { FunctionInput } from "./FunctionInput" ;
33
+ import { encodeFunctionArgs } from "./encodeFunctionArgs" ;
33
34
34
35
export enum FunctionType {
35
36
READ ,
@@ -51,6 +52,7 @@ type DecodedEvent = {
51
52
const formSchema = z . object ( {
52
53
inputs : z . array ( z . string ( ) ) ,
53
54
value : z . string ( ) . optional ( ) ,
55
+ resolvedAddresses : z . record ( z . string ( ) . optional ( ) ) . optional ( ) ,
54
56
} ) ;
55
57
56
58
const getInputLabel = ( input : AbiParameter ) : string => {
@@ -66,20 +68,9 @@ const getInputLabel = (input: AbiParameter): string => {
66
68
return input . type ;
67
69
} ;
68
70
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
-
81
71
export function FunctionField ( { systemId, worldAbi, functionAbi, useSearchParamsArgs } : Props ) {
82
72
const searchParams = useSearchParams ( ) ;
73
+ const { id : chainId } = useChain ( ) ;
83
74
const publicClient = usePublicClient ( ) ;
84
75
const operationType : FunctionType =
85
76
functionAbi . stateMutability === "view" || functionAbi . stateMutability === "pure"
@@ -89,7 +80,6 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
89
80
const wagmiConfig = useConfig ( ) ;
90
81
const account = useAccount ( ) ;
91
82
const { worldAddress } = useParams ( ) ;
92
- const { id : chainId } = useChain ( ) ;
93
83
const [ isLoading , setIsLoading ] = useState ( false ) ;
94
84
const [ result , setResult ] = useState < string > ( ) ;
95
85
const [ events , setEvents ] = useState < DecodedEvent [ ] > ( ) ;
@@ -103,6 +93,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
103
93
defaultValues : {
104
94
inputs : useSearchParamsArgs ? JSON . parse ( searchParams . get ( "args" ) || "[]" ) : [ ] ,
105
95
value : useSearchParamsArgs ? searchParams . get ( "value" ) ?? "" : "" ,
96
+ resolvedAddresses : { } ,
106
97
} ,
107
98
} ) ;
108
99
@@ -150,14 +141,19 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
150
141
setIsLoading ( true ) ;
151
142
let toastId ;
152
143
144
+ const resolvedInputs = values . inputs . map ( ( input , index ) => {
145
+ const resolvedAddress = form . getValues ( `resolvedAddresses.${ index } ` ) ;
146
+ return resolvedAddress || input ;
147
+ } ) ;
148
+
153
149
try {
154
150
if ( operationType === FunctionType . READ ) {
155
151
const { data : result } = await publicClient . call ( {
156
152
account : account . address ,
157
153
data : encodeFunctionData ( {
158
154
abi : [ ...worldAbi , functionAbi ] ,
159
155
functionName : functionAbi . name ,
160
- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
156
+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
161
157
} ) ,
162
158
to : worldAddress as Address ,
163
159
} ) ;
@@ -171,7 +167,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
171
167
const encoded = encodeSystemCall ( {
172
168
abi : [ functionAbi ] ,
173
169
functionName : functionAbi . name ,
174
- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
170
+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
175
171
systemId,
176
172
} ) ;
177
173
@@ -188,7 +184,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
188
184
abi : worldAbi ,
189
185
address : worldAddress as Address ,
190
186
functionName : functionAbi . name ,
191
- args : encodeFunctionArgs ( values . inputs , functionAbi ) ,
187
+ args : encodeFunctionArgs ( resolvedInputs , functionAbi ) ,
192
188
...( values . value && { value : BigInt ( values . value ) } ) ,
193
189
chainId,
194
190
} ) ;
@@ -225,6 +221,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
225
221
wagmiConfig ,
226
222
worldAbi ,
227
223
worldAddress ,
224
+ form ,
228
225
] ,
229
226
) ;
230
227
@@ -259,31 +256,7 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
259
256
{ functionAbi . inputs . length > 0 && (
260
257
< div className = "!mt-2 space-y-2" >
261
258
{ 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 } />
287
260
) ) }
288
261
289
262
{ functionAbi . stateMutability === "payable" && (
0 commit comments