@@ -16,7 +16,9 @@ use liana_ui::{component::form, widget::Element};
16
16
use async_hwi:: DeviceKind ;
17
17
18
18
use crate :: {
19
- app:: wallet:: wallet_name,
19
+ app:: { state:: export:: ExportModal , wallet:: wallet_name} ,
20
+ backup:: { self , Backup } ,
21
+ export:: { ImportExportMessage , ImportExportType } ,
20
22
hw:: { HardwareWallet , HardwareWallets } ,
21
23
installer:: {
22
24
message:: { self , Message } ,
@@ -302,17 +304,70 @@ pub struct BackupDescriptor {
302
304
done : bool ,
303
305
descriptor : Option < LianaDescriptor > ,
304
306
key_aliases : HashMap < Fingerprint , String > ,
307
+ modal : Option < ExportModal > ,
308
+ error : Option < Error > ,
305
309
}
306
310
307
311
impl Step for BackupDescriptor {
312
+ fn subscription ( & self , _hws : & HardwareWallets ) -> Subscription < Message > {
313
+ if let Some ( modal) = & self . modal {
314
+ if let Some ( sub) = modal. subscription ( ) {
315
+ sub. map ( |m| Message :: ImportExport ( ImportExportMessage :: Progress ( m) ) )
316
+ } else {
317
+ Subscription :: none ( )
318
+ }
319
+ } else {
320
+ Subscription :: none ( )
321
+ }
322
+ }
308
323
fn update (
309
324
& mut self ,
310
325
_hws : & mut HardwareWallets ,
311
326
message : Message ,
312
- _ctx : & Context ,
327
+ ctx : & Context ,
313
328
) -> Task < Message > {
314
- if let Message :: UserActionDone ( done) = message {
315
- self . done = done;
329
+ match message {
330
+ Message :: ImportExport ( ImportExportMessage :: Close ) => {
331
+ self . modal = None ;
332
+ }
333
+ Message :: ImportExport ( m) => {
334
+ if let Some ( modal) = self . modal . as_mut ( ) {
335
+ let task: Task < Message > = modal. update ( m) ;
336
+ return task;
337
+ } ;
338
+ }
339
+ Message :: BackupWallet => {
340
+ if self . modal . is_none ( ) {
341
+ let ctx = ctx. clone ( ) ;
342
+ return Task :: perform (
343
+ async move {
344
+ let backup = Backup :: from_installer ( ctx, true ) . await ?;
345
+ serde_json:: to_string_pretty ( & backup) . map_err ( |_| backup:: Error :: Json )
346
+ } ,
347
+ Message :: ExportWallet ,
348
+ ) ;
349
+ }
350
+ }
351
+ Message :: ExportWallet ( str) => {
352
+ if self . modal . is_none ( ) {
353
+ let str = match str {
354
+ Ok ( s) => s,
355
+ Err ( e) => {
356
+ tracing:: error!( "{e:?}" ) ;
357
+ self . error = Some ( Error :: Backup ( e) ) ;
358
+ return Task :: none ( ) ;
359
+ }
360
+ } ;
361
+ let modal = ExportModal :: new ( None , ImportExportType :: ExportBackup ( str) ) ;
362
+ let launch = modal. launch ( ) ;
363
+ self . modal = Some ( modal) ;
364
+ return launch;
365
+ }
366
+ }
367
+ Message :: UserActionDone ( done) => {
368
+ self . done = done;
369
+ }
370
+ _ => { }
316
371
}
317
372
Task :: none ( )
318
373
}
@@ -334,13 +389,19 @@ impl Step for BackupDescriptor {
334
389
progress : ( usize , usize ) ,
335
390
email : Option < & ' a str > ,
336
391
) -> Element < Message > {
337
- view:: backup_descriptor (
392
+ let content = view:: backup_descriptor (
338
393
progress,
339
394
email,
340
395
self . descriptor . as_ref ( ) . expect ( "Must be a descriptor" ) ,
341
396
& self . key_aliases ,
397
+ self . error . as_ref ( ) ,
342
398
self . done ,
343
- )
399
+ ) ;
400
+ if let Some ( modal) = & self . modal {
401
+ modal. view ( content)
402
+ } else {
403
+ content
404
+ }
344
405
}
345
406
}
346
407
0 commit comments