@@ -7,6 +7,8 @@ import { RuntimeContext } from "../../useRuntime";
7
7
import TransactionAddressWithCopy from "../components/TransactionAddressWithCopy" ;
8
8
import DecodedLogSignature from "./decoder/DecodedLogSignature" ;
9
9
import DecodedParamsTable from "./decoder/DecodedParamsTable" ;
10
+ import DecodedScillaLogSignature from "./decoder/DecodedScillaLogSignature" ;
11
+ import DecodedScillaParamsTable from "./decoder/DecodedScillaParamsTable" ;
10
12
import LogIndex from "./log/LogIndex" ;
11
13
import RawLog from "./log/RawLog" ;
12
14
import TwoColumnPanel from "./log/TwoColumnPanel" ;
@@ -19,27 +21,65 @@ type LogEntryProps = {
19
21
log : Log ;
20
22
} ;
21
23
24
+ type ScillaLog = {
25
+ eventName : string ;
26
+ address : string ;
27
+ params : object ;
28
+ } ;
29
+
30
+ const EvmLogDisplay : FC < LogDisplayProps > = ( { resolvedLogDesc} ) => {
31
+ return ( < div > { resolvedLogDesc === undefined ? (
32
+ < TwoColumnPanel > Waiting for data...</ TwoColumnPanel >
33
+ ) : resolvedLogDesc === null ? (
34
+ < TwoColumnPanel > Cannot decode data</ TwoColumnPanel >
35
+ ) : (
36
+ < TwoColumnPanel >
37
+ < DecodedLogSignature event = { resolvedLogDesc . fragment } />
38
+ < DecodedParamsTable
39
+ args = { resolvedLogDesc . args }
40
+ paramTypes = { resolvedLogDesc . fragment . inputs }
41
+ hasParamNames = { resolvedLogDesc === logDesc || resolvedLogDesc === scillaLogDesc }
42
+ />
43
+ </ TwoColumnPanel >
44
+ )
45
+ } </ div > ) ;
46
+ } ;
47
+
48
+ /// Display a scilla log; if the log were null, we would have defaulted to
49
+ /// EvmLogDisplay, so no need to handle undefined or null.
50
+ const ScillaLogDisplay : FC < ScillaLog > = ( { scillaLogDesc} ) => {
51
+ let eventProps = { name : scillaLogDesc . eventName , address : scillaLogDesc . address }
52
+ return ( < div > < TwoColumnPanel >
53
+ < DecodedScillaLogSignature event = { eventProps } />
54
+ < DecodedScillaParamsTable params = { scillaLogDesc . params } />
55
+ </ TwoColumnPanel >
56
+ </ div >
57
+ )
58
+ }
59
+
60
+
61
+
22
62
const LogEntry : FC < LogEntryProps > = ( { log } ) => {
23
63
const { provider } = useContext ( RuntimeContext ) ;
24
64
const match = useSourcifyMetadata ( log . address , provider ?. _network . chainId ) ;
25
65
26
- const scillaLogDesc = useMemo ( ( ) => {
66
+ const scillaLogDesc : ScillaLog | undefined = useMemo ( ( ) => {
27
67
// Scilla logs are encoded as a single JSON string.
28
68
try {
29
69
const data = JSON . parse ( AbiCoder . defaultAbiCoder ( ) . decode ( [ "string" ] , log . data ) [ 0 ] ) ;
30
- const params : any [ ] = data . params ;
31
- return new LogDescription (
32
- EventFragment . from ( { type : "event" , name : data . _eventname , inputs : params . map ( p => ( { name : p . vname , type : p . type } ) ) } ) ,
33
- "" ,
34
- Result . fromItems ( params . map ( p => ( p . value ) ) , params . map ( p => ( p . name ) ) )
35
- ) ;
70
+ return {
71
+ eventName : data . _eventname ,
72
+ address : data . address ,
73
+ params : data . params
74
+ }
36
75
} catch ( err ) {
37
76
// Silently ignore on purpose
38
77
return undefined ;
39
78
}
40
79
} , [ log ] ) ;
41
80
42
- const logDesc = useMemo ( ( ) => {
81
+ const logDesc = scillaLogDesc ? undefined :
82
+ useMemo ( ( ) => {
43
83
if ( ! match ) {
44
84
return match ;
45
85
}
@@ -58,9 +98,9 @@ const LogEntry: FC<LogEntryProps> = ({ log }) => {
58
98
} , [ log , match ] ) ;
59
99
60
100
const rawTopic0 = log . topics [ 0 ] ;
61
- const topic0 = useTopic0 ( rawTopic0 ) ;
101
+ const topic0 = scillaLogDesc ? undefined : useTopic0 ( rawTopic0 ) ;
62
102
63
- const topic0LogDesc = useMemo ( ( ) => {
103
+ const topic0LogDesc = scillaLogDesc ? undefined : useMemo ( ( ) => {
64
104
if ( ! topic0 ) {
65
105
return topic0 ;
66
106
}
@@ -84,7 +124,7 @@ const LogEntry: FC<LogEntryProps> = ({ log }) => {
84
124
return undefined ;
85
125
} , [ topic0 , log ] ) ;
86
126
87
- const resolvedLogDesc = scillaLogDesc ?? logDesc ?? topic0LogDesc ;
127
+ const resolvedLogDesc = logDesc ?? topic0LogDesc ;
88
128
89
129
return (
90
130
< div className = "flex space-x-10 py-5" >
@@ -105,22 +145,11 @@ const LogEntry: FC<LogEntryProps> = ({ log }) => {
105
145
</ TwoColumnPanel >
106
146
</ Tab . List >
107
147
< Tab . Panels as = { React . Fragment } >
108
- < Tab . Panel >
109
- { resolvedLogDesc === undefined ? (
110
- < TwoColumnPanel > Waiting for data...</ TwoColumnPanel >
111
- ) : resolvedLogDesc === null ? (
112
- < TwoColumnPanel > Can't decode data</ TwoColumnPanel >
113
- ) : (
114
- < TwoColumnPanel >
115
- < DecodedLogSignature event = { resolvedLogDesc . fragment } />
116
- < DecodedParamsTable
117
- args = { resolvedLogDesc . args }
118
- paramTypes = { resolvedLogDesc . fragment . inputs }
119
- hasParamNames = { resolvedLogDesc === logDesc || resolvedLogDesc === scillaLogDesc }
120
- />
121
- </ TwoColumnPanel >
122
- ) }
123
- </ Tab . Panel >
148
+ < Tab . Panel >
149
+ ({ scillaLogDesc !== undefined && scillaLogDesc !== null ?
150
+ < ScillaLogDisplay scillaLogDesc = { scillaLogDesc } /> :
151
+ < EvmLogDisplay resolvedLogDesc = { resolvedLogDesc } /> } )
152
+ </ Tab . Panel >
124
153
< Tab . Panel as = { React . Fragment } >
125
154
< RawLog topics = { log . topics } data = { log . data } />
126
155
</ Tab . Panel >
0 commit comments