@@ -26,6 +26,14 @@ const PATH = 'interpret'
2626export default function DecodingForm ( { decoded, currentHash, chainID, error } : FormProps ) {
2727 const [ result , setResult ] = React . useState < Interpretation > ( )
2828 const [ persistedSchema , setSchema ] = useLocalStorage ( decoded ?. toAddress ?? 'unknown' , '' )
29+ const [ isInterpreting , setIsInterpreting ] = React . useState ( false )
30+ const [ userAddress , setUserAddress ] = React . useState < string > ( '' )
31+
32+ const matchingExample = React . useMemo ( ( ) => {
33+ return Object . values ( EXAMPLE_TXS )
34+ . flatMap ( ( categoryTxs ) => categoryTxs )
35+ . find ( ( tx ) => tx . hash . toLowerCase ( ) === currentHash ?. toLowerCase ( ) )
36+ } , [ currentHash ] )
2937
3038 const schema = React . useMemo ( ( ) => {
3139 if ( persistedSchema !== '' ) return persistedSchema
@@ -54,11 +62,25 @@ export default function DecodingForm({ decoded, currentHash, chainID, error }: F
5462 schema : schema ,
5563 }
5664
57- applyInterpreter ( decoded , newInterpreter ) . then ( ( res ) => {
58- setResult ( res )
59- } )
65+ setIsInterpreting ( true )
66+ setResult ( undefined )
67+
68+ applyInterpreter ( decoded , newInterpreter , userAddress || undefined )
69+ . then ( ( res ) => {
70+ setResult ( res )
71+ } )
72+ . finally ( ( ) => {
73+ setIsInterpreting ( false )
74+ } )
6075 }
61- } , [ schema , decoded ] )
76+ } , [ schema , decoded , userAddress ] )
77+
78+ // Set user address from example if available
79+ React . useEffect ( ( ) => {
80+ if ( matchingExample && ( matchingExample as any ) . interpretAsUserAddress ) {
81+ setUserAddress ( ( matchingExample as any ) . interpretAsUserAddress )
82+ }
83+ } , [ matchingExample ] )
6284
6385 // Run the interpreter on page load
6486 React . useEffect ( ( ) => {
@@ -68,14 +90,10 @@ export default function DecodingForm({ decoded, currentHash, chainID, error }: F
6890 } , [ schema , decoded , result , onRun ] )
6991
7092 const interpreterSourceLink = React . useMemo ( ( ) => {
71- const matchingExample = Object . values ( EXAMPLE_TXS )
72- . flatMap ( ( categoryTxs ) => categoryTxs )
73- . find ( ( tx ) => tx . hash . toLowerCase ( ) === currentHash ?. toLowerCase ( ) )
74-
7593 return matchingExample ?. interpreter
7694 ? `${ INTERPRETER_REPO } /interpreters/${ matchingExample ?. interpreter } .ts`
7795 : INTERPRETER_REPO
78- } , [ currentHash ] )
96+ } , [ matchingExample ] )
7997
8098 return (
8199 < div className = "grid h-full items-stretch gap-6 grid-cols-1 lg:grid-cols-[1fr_200px]" >
@@ -102,12 +120,22 @@ export default function DecodingForm({ decoded, currentHash, chainID, error }: F
102120 < Button type = "submit" className = "flex-1" >
103121 Decode
104122 </ Button >
105- < Button variant = { 'outline' } onClick = { onRun } type = "button" className = "flex-1" >
123+ < Button variant = { 'outline' } onClick = { onRun } type = "button" className = "flex-1" disabled = { isInterpreting } >
106124 < PlayIcon className = "mr-2 h-4 w-4" />
107- Interpret
125+ { isInterpreting ? 'Interpreting...' : ' Interpret' }
108126 </ Button >
109127 </ div >
110128 </ div >
129+ < div className = "flex w-full lg:items-center gap-2 flex-col lg:flex-row mt-2" >
130+ < Input
131+ className = "flex-1"
132+ id = "userAddress"
133+ name = "userAddress"
134+ placeholder = "Optional: interpret as user address"
135+ value = { userAddress }
136+ onChange = { ( e ) => setUserAddress ( e . target . value ) }
137+ />
138+ </ div >
111139 </ form >
112140
113141 { error ? (
@@ -146,12 +174,21 @@ export default function DecodingForm({ decoded, currentHash, chainID, error }: F
146174 < Label > Result:</ Label >
147175 </ div >
148176
149- < CodeBlock
150- language = "json"
151- value = { result ?. error ? result ?. error : JSON . stringify ( result ?. interpretation , null , 2 ) }
152- readonly = { true }
153- lineNumbers = { false }
154- />
177+ { isInterpreting ? (
178+ < div className = "flex items-center justify-center p-8 border rounded-md" >
179+ < div className = "text-center" >
180+ < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900 mx-auto mb-2" > </ div >
181+ < p className = "text-sm text-gray-600" > Interpreting transaction...</ p >
182+ </ div >
183+ </ div >
184+ ) : (
185+ < CodeBlock
186+ language = "json"
187+ value = { result ?. error ? result ?. error : JSON . stringify ( result ?. interpretation , null , 2 ) }
188+ readonly = { true }
189+ lineNumbers = { false }
190+ />
191+ ) }
155192 </ div >
156193 </ div >
157194 ) }
0 commit comments