@@ -19,6 +19,11 @@ import {
19
19
AlertTitle ,
20
20
} from "@/components/ui/alert" ;
21
21
22
+ const shortenAddress = ( address : string ) => {
23
+ if ( ! address || address . length < 10 ) return address ;
24
+ return `${ address . substring ( 0 , 6 ) } ...${ address . substring ( address . length - 4 ) } ` ;
25
+ } ;
26
+
22
27
export default function Result ( { result } : any ) {
23
28
const [ hashesExpanded , setHashesExpanded ] = useState ( true ) ;
24
29
const [ transactionExpanded , setTransactionExpanded ] = useState ( false ) ;
@@ -30,33 +35,26 @@ export default function Result({ result }: any) {
30
35
const [ warnings , setWarnings ] = useState < { title : string , description : string } [ ] > ( [ ] ) ;
31
36
const [ infoNotices , setInfoNotices ] = useState < { title : string , description : string } [ ] > ( [ ] ) ;
32
37
33
- if ( ! result ) return null ;
34
- else if ( result . error ) {
35
- return < div className = "max-w-3xl mx-auto" >
36
- < h3 className = "text-lg font-medium mb-4" > Error</ h3 >
37
- < p className = "text-red-500" > { result . error } </ p >
38
- </ div >
39
- }
40
-
41
- const execParams = result . transaction ?. exec_transaction ?. decoded ?. parameters ;
42
-
43
- // Mapping the parameters by name for easy access
38
+ // Process all hooks before conditionals
39
+ const execParams = result ?. transaction ?. exec_transaction ?. decoded ?. parameters ;
40
+
44
41
const params = useMemo ( ( ) => {
45
- return execParams
46
- ? execParams . reduce ( ( acc : any , param : any ) => {
47
- acc [ param . name ] = param . value ;
48
- return acc ;
49
- } , { } )
50
- : { } ;
42
+ if ( ! execParams ) return { } ;
43
+ return execParams . reduce ( ( acc : any , param : any ) => {
44
+ acc [ param . name ] = param . value ;
45
+ return acc ;
46
+ } , { } ) ;
51
47
} , [ execParams ] ) ;
52
48
53
- const networkDetails = result . network ?. name ?
49
+ const networkDetails = result ? .network ?. name ?
54
50
NETWORKS . find ( ( n ) => n . value === result . network . name || n . label === result . network . name ) :
55
51
null ;
56
-
52
+
57
53
const networkLogo = networkDetails ?. logo || '' ;
58
-
54
+
59
55
useEffect ( ( ) => {
56
+ if ( ! params ) return ;
57
+
60
58
const newWarnings : { title : string , description : string } [ ] = [ ] ;
61
59
const newInfoNotices : { title : string , description : string } [ ] = [ ] ;
62
60
@@ -116,10 +114,16 @@ export default function Result({ result }: any) {
116
114
setInfoNotices ( newInfoNotices ) ;
117
115
} , [ params ] ) ;
118
116
119
- const shortenAddress = ( address : string ) => {
120
- if ( ! address || address . length < 10 ) return address ;
121
- return `${ address . substring ( 0 , 6 ) } ...${ address . substring ( address . length - 4 ) } ` ;
122
- } ;
117
+ // Early returns after all hooks
118
+ if ( ! result ) return null ;
119
+ if ( result . error ) {
120
+ return (
121
+ < div className = "max-w-3xl mx-auto" >
122
+ < h3 className = "text-lg font-medium mb-4" > Error</ h3 >
123
+ < p className = "text-red-500" > { result . error } </ p >
124
+ </ div >
125
+ ) ;
126
+ }
123
127
124
128
return (
125
129
< div className = "max-w-3xl mx-auto" >
0 commit comments