@@ -35,6 +35,7 @@ type Props = {
35
35
addressInfo : {
36
36
balance : AddressBalance
37
37
events : ExplorerEvent [ ]
38
+ unconfirmedEvents : ExplorerEvent [ ]
38
39
unspentOutputs : ExplorerSiacoinOutput [ ]
39
40
}
40
41
}
@@ -44,6 +45,7 @@ export function Address({
44
45
addressInfo : {
45
46
balance : { unspentSiacoins, unspentSiafunds } ,
46
47
events,
48
+ unconfirmedEvents,
47
49
unspentOutputs,
48
50
} ,
49
51
} : Props ) {
@@ -66,36 +68,17 @@ export function Address({
66
68
} , [ unspentSiacoins , unspentSiafunds ] )
67
69
68
70
const eventEntities = useMemo ( ( ) => {
69
- const list : EntityListItemProps [ ] = [ ]
70
-
71
- if ( events . length ) {
72
- events . forEach ( ( event ) => {
73
- switch ( event . type ) {
74
- case 'v1Transaction' :
75
- list . push ( formatV1TransactionEntity ( id , event ) )
76
- break
77
- case 'v2Transaction' :
78
- list . push ( formatV2TransactionEntity ( id , event ) )
79
- break
80
- case 'v1ContractResolution' :
81
- list . push ( formatV1ContractResolutionEntity ( event ) )
82
- break
83
- case 'v2ContractResolution' :
84
- list . push ( formatV2ContractResolutionEntity ( event ) )
85
- break
86
- case 'payout' :
87
- list . push ( formatPayoutEntity ( event ) )
88
- break
89
- }
90
- } )
91
- }
71
+ const list : EntityListItemProps [ ] = [
72
+ ...unconfirmedEvents . map ( ( uEvent ) => formatEvent ( id , uEvent , true ) ) ,
73
+ ...events . map ( ( event ) => formatEvent ( id , event ) ) ,
74
+ ]
92
75
93
76
return list . sort (
94
77
( a , b ) =>
95
78
new Date ( b . timestamp || 0 ) . getTime ( ) -
96
79
new Date ( a . timestamp || 0 ) . getTime ( )
97
80
)
98
- } , [ id , events ] )
81
+ } , [ id , events , unconfirmedEvents ] )
99
82
100
83
const utxos = useMemo ( ( ) => {
101
84
const list : EntityListItemProps [ ] = [ ]
@@ -176,7 +159,10 @@ function getTotal({
176
159
)
177
160
}
178
161
179
- function formatV1TransactionEntity ( id : string , v1Transaction : ExplorerEvent ) {
162
+ function formatV1TransactionEntity (
163
+ id : string ,
164
+ v1Transaction : ExplorerEvent
165
+ ) : EntityListItemProps {
180
166
const { transaction } = v1Transaction . data as EventV1Transaction
181
167
return {
182
168
hash : v1Transaction . id ,
@@ -198,7 +184,10 @@ function formatV1TransactionEntity(id: string, v1Transaction: ExplorerEvent) {
198
184
}
199
185
}
200
186
201
- function formatV2TransactionEntity ( id : string , v2Transaction : ExplorerEvent ) {
187
+ function formatV2TransactionEntity (
188
+ id : string ,
189
+ v2Transaction : ExplorerEvent
190
+ ) : EntityListItemProps {
202
191
const transaction = v2Transaction . data as ExplorerV2Transaction
203
192
return {
204
193
hash : v2Transaction . id ,
@@ -223,7 +212,9 @@ function formatV2TransactionEntity(id: string, v2Transaction: ExplorerEvent) {
223
212
}
224
213
}
225
214
226
- function formatV1ContractResolutionEntity ( v1ContractResolution : ExplorerEvent ) {
215
+ function formatV1ContractResolutionEntity (
216
+ v1ContractResolution : ExplorerEvent
217
+ ) : EntityListItemProps {
227
218
const { parent, siacoinElement } =
228
219
v1ContractResolution . data as EventV1ContractResolution
229
220
return {
@@ -236,7 +227,9 @@ function formatV1ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
236
227
}
237
228
}
238
229
239
- function formatV2ContractResolutionEntity ( v1ContractResolution : ExplorerEvent ) {
230
+ function formatV2ContractResolutionEntity (
231
+ v1ContractResolution : ExplorerEvent
232
+ ) : EntityListItemProps {
240
233
const { resolution, siacoinElement } =
241
234
v1ContractResolution . data as EventV2ContractResolution
242
235
return {
@@ -249,7 +242,7 @@ function formatV2ContractResolutionEntity(v1ContractResolution: ExplorerEvent) {
249
242
}
250
243
}
251
244
252
- function formatPayoutEntity ( payout : ExplorerEvent ) {
245
+ function formatPayoutEntity ( payout : ExplorerEvent ) : EntityListItemProps {
253
246
const { siacoinElement } = payout . data as EventPayout
254
247
return {
255
248
hash : payout . id ,
@@ -264,7 +257,7 @@ function formatPayoutEntity(payout: ExplorerEvent) {
264
257
265
258
function formatUnspentSiacoinOutputEntity (
266
259
siacoinOutput : ExplorerSiacoinOutput
267
- ) {
260
+ ) : EntityListItemProps {
268
261
return {
269
262
hash : siacoinOutput . id ,
270
263
sc : new BigNumber ( siacoinOutput . siacoinOutput . value ) ,
@@ -273,3 +266,31 @@ function formatUnspentSiacoinOutputEntity(
273
266
scVariant : 'value' as const ,
274
267
}
275
268
}
269
+
270
+ const formatEvent = (
271
+ id : string ,
272
+ event : ExplorerEvent ,
273
+ isUnconfirmed = false
274
+ ) : EntityListItemProps => {
275
+ let baseEntity : EntityListItemProps
276
+
277
+ switch ( event . type ) {
278
+ case 'v1Transaction' :
279
+ baseEntity = formatV1TransactionEntity ( id , event )
280
+ break
281
+ case 'v2Transaction' :
282
+ baseEntity = formatV2TransactionEntity ( id , event )
283
+ break
284
+ case 'v1ContractResolution' :
285
+ baseEntity = formatV1ContractResolutionEntity ( event )
286
+ break
287
+ case 'v2ContractResolution' :
288
+ baseEntity = formatV2ContractResolutionEntity ( event )
289
+ break
290
+ case 'payout' :
291
+ baseEntity = formatPayoutEntity ( event )
292
+ break
293
+ }
294
+
295
+ return isUnconfirmed ? { ...baseEntity , unconfirmed : true } : baseEntity
296
+ }
0 commit comments