1
1
use std:: convert:: TryInto ;
2
2
use std:: time:: { SystemTime , UNIX_EPOCH } ;
3
3
4
+ use bitcoin:: Txid ;
4
5
use iced:: { Command , Element } ;
5
6
6
7
use super :: State ;
7
8
9
+ use revault_ui:: chart:: { FlowChart , FlowChartMessage } ;
10
+
8
11
use crate :: {
9
12
app:: {
10
13
context:: Context ,
@@ -13,7 +16,10 @@ use crate::{
13
16
view:: LoadingDashboard ,
14
17
view:: { HistoryEventListItemView , HistoryEventView , HistoryView } ,
15
18
} ,
16
- daemon:: model:: { HistoryEvent , HistoryEventKind , VaultTransactions , ALL_HISTORY_EVENTS } ,
19
+ daemon:: model:: {
20
+ HistoryEvent , HistoryEventKind , HistoryEventTransaction , TransactionKind ,
21
+ ALL_HISTORY_EVENTS ,
22
+ } ,
17
23
} ;
18
24
19
25
pub const HISTORY_EVENT_PAGE_SIZE : u64 = 20 ;
@@ -93,7 +99,7 @@ impl State for HistoryState {
93
99
}
94
100
Message :: HistoryEvent ( msg) => {
95
101
if let Some ( event) = selected_event {
96
- event. update ( msg)
102
+ event. update ( ctx , msg)
97
103
}
98
104
}
99
105
Message :: Close => {
@@ -283,7 +289,9 @@ impl HistoryEventListItemState {
283
289
#[ derive( Debug ) ]
284
290
pub struct HistoryEventState {
285
291
event : HistoryEvent ,
286
- txs : Vec < VaultTransactions > ,
292
+ txs : Vec < HistoryEventTransaction > ,
293
+ selected_tx : Option < Txid > ,
294
+ flowchart : Option < FlowChart > ,
287
295
loading_fail : Option < Error > ,
288
296
view : HistoryEventView ,
289
297
}
@@ -293,22 +301,99 @@ impl HistoryEventState {
293
301
Self {
294
302
event,
295
303
txs : Vec :: new ( ) ,
304
+ flowchart : None ,
305
+ selected_tx : None ,
296
306
loading_fail : None ,
297
307
view : HistoryEventView :: new ( ) ,
298
308
}
299
309
}
300
310
301
- pub fn update ( & mut self , message : HistoryEventMessage ) {
302
- let HistoryEventMessage :: OnChainTransactions ( res) = message;
303
- match res {
304
- Ok ( txs) => self . txs = txs,
305
- Err ( e) => self . loading_fail = Some ( e. into ( ) ) ,
311
+ pub fn update ( & mut self , ctx : & Context , message : HistoryEventMessage ) {
312
+ match message {
313
+ HistoryEventMessage :: ToggleFlowChart ( toggle) => {
314
+ if toggle {
315
+ self . flowchart = Some ( FlowChart :: new (
316
+ ctx. network ( ) ,
317
+ self . txs
318
+ . iter ( )
319
+ . map ( |event_tx| event_tx. tx . clone ( ) )
320
+ . collect ( ) ,
321
+ ) ) ;
322
+ } else {
323
+ self . flowchart = None ;
324
+ }
325
+ }
326
+ HistoryEventMessage :: FlowChart ( FlowChartMessage :: TxSelected ( txid) ) => {
327
+ if self . selected_tx . is_none ( ) {
328
+ self . selected_tx = txid;
329
+ } else {
330
+ self . selected_tx = None ;
331
+ }
332
+ }
333
+ HistoryEventMessage :: OnChainTransactions ( res) => match res {
334
+ Ok ( vault_txs) => {
335
+ let mut list: Vec < HistoryEventTransaction > = Vec :: new ( ) ;
336
+ for txs in vault_txs {
337
+ list. push ( HistoryEventTransaction :: new (
338
+ & txs. deposit ,
339
+ TransactionKind :: Deposit ,
340
+ ) ) ;
341
+
342
+ if let Some ( unvault) = txs. unvault {
343
+ list. push ( HistoryEventTransaction :: new (
344
+ & unvault,
345
+ TransactionKind :: Unvault ,
346
+ ) ) ;
347
+ }
348
+ if let Some ( cancel) = txs. cancel {
349
+ list. push ( HistoryEventTransaction :: new (
350
+ & cancel,
351
+ TransactionKind :: Cancel ,
352
+ ) ) ;
353
+ }
354
+ if let Some ( spend) = txs. spend {
355
+ list. push ( HistoryEventTransaction :: new ( & spend, TransactionKind :: Spend ) ) ;
356
+ }
357
+ if let Some ( unvault_emergency) = txs. unvault_emergency {
358
+ list. push ( HistoryEventTransaction :: new (
359
+ & unvault_emergency,
360
+ TransactionKind :: UnvaultEmergency ,
361
+ ) ) ;
362
+ }
363
+ if let Some ( emergency) = txs. emergency {
364
+ list. push ( HistoryEventTransaction :: new (
365
+ & emergency,
366
+ TransactionKind :: Emergency ,
367
+ ) ) ;
368
+ }
369
+ }
370
+
371
+ list. sort_by ( |a, b| a. blockheight . cmp ( & b. blockheight ) ) ;
372
+ self . txs = list;
373
+ }
374
+ Err ( e) => self . loading_fail = Some ( e. into ( ) ) ,
375
+ } ,
306
376
}
307
377
}
308
378
309
379
pub fn view ( & mut self , ctx : & Context ) -> Element < Message > {
310
- self . view
311
- . view ( ctx, & self . event , & self . txs , self . loading_fail . as_ref ( ) )
380
+ let selected = if let Some ( txid) = self . selected_tx {
381
+ self . txs . iter ( ) . find ( |vault_tx| vault_tx. tx . txid ( ) == txid)
382
+ } else {
383
+ None
384
+ } ;
385
+ self . view . view (
386
+ ctx,
387
+ & self . event ,
388
+ & self . txs ,
389
+ selected,
390
+ self . flowchart . as_mut ( ) . map ( |chart| {
391
+ chart
392
+ . view ( )
393
+ . map ( |msg| Message :: HistoryEvent ( HistoryEventMessage :: FlowChart ( msg) ) )
394
+ } ) ,
395
+ self . loading_fail . as_ref ( ) ,
396
+ )
312
397
}
313
398
314
399
pub fn load ( & self , ctx : & Context ) -> Command < Message > {
0 commit comments