@@ -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:: Backup ,
21
+ export:: { ImportExportMessage , ImportExportType } ,
20
22
hw:: { HardwareWallet , HardwareWallets } ,
21
23
installer:: {
22
24
message:: { self , Message } ,
@@ -302,12 +304,62 @@ pub struct BackupDescriptor {
302
304
done : bool ,
303
305
descriptor : Option < LianaDescriptor > ,
304
306
key_aliases : HashMap < Fingerprint , String > ,
307
+ modal : Option < ExportModal > ,
305
308
}
306
309
307
310
impl Step for BackupDescriptor {
308
- fn update ( & mut self , _hws : & mut HardwareWallets , message : Message ) -> Task < Message > {
309
- if let Message :: UserActionDone ( done) = message {
310
- self . done = done;
311
+ fn subscription ( & self , _hws : & HardwareWallets ) -> iced:: Subscription < Message > {
312
+ if let Some ( modal) = & self . modal {
313
+ if let Some ( sub) = modal. subscription ( ) {
314
+ return sub. map ( |m| {
315
+ Message :: ImportExport ( crate :: export:: ImportExportMessage :: Progress ( m) )
316
+ } ) ;
317
+ }
318
+ }
319
+ iced:: Subscription :: none ( )
320
+ }
321
+ fn update (
322
+ & mut self ,
323
+ _hws : & mut HardwareWallets ,
324
+ message : Message ,
325
+ ctx : & Context ,
326
+ ) -> Task < Message > {
327
+ match message {
328
+ Message :: ImportExport ( ImportExportMessage :: Close ) => {
329
+ self . modal = None ;
330
+ }
331
+ Message :: ImportExport ( m) => {
332
+ if let Some ( modal) = self . modal . as_mut ( ) {
333
+ let task: Task < Message > = modal. update ( m) ;
334
+ return task;
335
+ } ;
336
+ }
337
+ Message :: BackupWallet => {
338
+ if self . modal . is_none ( ) {
339
+ let ctx = ctx. clone ( ) ;
340
+ return Task :: perform (
341
+ async move {
342
+ let backup = Backup :: from_installer ( ctx, true ) . await ;
343
+ let backup = backup. unwrap ( ) ;
344
+ serde_json:: to_string_pretty ( & backup) . unwrap ( )
345
+ // TODO: do not unwrap, return an error message instead
346
+ } ,
347
+ Message :: ExportWallet ,
348
+ ) ;
349
+ }
350
+ }
351
+ Message :: ExportWallet ( str) => {
352
+ if self . modal . is_none ( ) {
353
+ let modal = ExportModal :: new ( None , ImportExportType :: ExportBackup ( str) ) ;
354
+ let launch = modal. launch ( ) ;
355
+ self . modal = Some ( modal) ;
356
+ return launch;
357
+ }
358
+ }
359
+ Message :: UserActionDone ( done) => {
360
+ self . done = done;
361
+ }
362
+ _ => { }
311
363
}
312
364
Task :: none ( )
313
365
}
0 commit comments