@@ -18,7 +18,7 @@ use async_hwi::DeviceKind;
18
18
use crate :: {
19
19
app:: { state:: export:: ExportModal , wallet:: wallet_name} ,
20
20
backup:: { self , Backup } ,
21
- export:: { ImportExportMessage , ImportExportType } ,
21
+ export:: { ImportExportMessage , ImportExportType , Progress } ,
22
22
hw:: { HardwareWallet , HardwareWallets } ,
23
23
installer:: {
24
24
message:: { self , Message } ,
@@ -32,6 +32,8 @@ pub struct ImportDescriptor {
32
32
imported_descriptor : form:: Value < String > ,
33
33
wrong_network : bool ,
34
34
error : Option < String > ,
35
+ modal : Option < ExportModal > ,
36
+ imported_backup : bool ,
35
37
}
36
38
37
39
impl ImportDescriptor {
@@ -41,6 +43,8 @@ impl ImportDescriptor {
41
43
imported_descriptor : form:: Value :: default ( ) ,
42
44
wrong_network : false ,
43
45
error : None ,
46
+ modal : None ,
47
+ imported_backup : false ,
44
48
}
45
49
}
46
50
@@ -77,19 +81,60 @@ impl Step for ImportDescriptor {
77
81
fn skip ( & self , ctx : & Context ) -> bool {
78
82
ctx. remote_backend . is_some ( )
79
83
}
80
- // form value is set as valid each time it is edited.
81
- // Verification of the values is happening when the user click on Next button.
84
+
85
+ fn subscription ( & self , _hws : & HardwareWallets ) -> Subscription < Message > {
86
+ if let Some ( modal) = & self . modal {
87
+ if let Some ( sub) = modal. subscription ( ) {
88
+ sub. map ( |m| Message :: ImportExport ( ImportExportMessage :: Progress ( m) ) )
89
+ } else {
90
+ Subscription :: none ( )
91
+ }
92
+ } else {
93
+ Subscription :: none ( )
94
+ }
95
+ }
96
+
82
97
fn update (
83
98
& mut self ,
84
99
_hws : & mut HardwareWallets ,
85
100
message : Message ,
86
101
_ctx : & Context ,
87
102
) -> Task < Message > {
88
- if let Message :: DefineDescriptor ( message:: DefineDescriptor :: ImportDescriptor ( desc) ) =
89
- message
90
- {
91
- self . imported_descriptor . value = desc;
92
- self . check_descriptor ( self . network ) ;
103
+ match message {
104
+ Message :: DefineDescriptor ( message:: DefineDescriptor :: ImportDescriptor ( desc) ) => {
105
+ self . imported_descriptor . value = desc;
106
+ self . check_descriptor ( self . network ) ;
107
+ }
108
+ Message :: ImportExport ( ImportExportMessage :: Close ) => {
109
+ self . modal = None ;
110
+ }
111
+ Message :: ImportBackup => {
112
+ if !self . imported_backup {
113
+ let modal = ExportModal :: new ( None , ImportExportType :: WalletFromBackup ) ;
114
+ let launch = modal. launch ( false ) ;
115
+ self . modal = Some ( modal) ;
116
+ return launch;
117
+ }
118
+ }
119
+ Message :: ImportExport ( ImportExportMessage :: Progress ( Progress :: WalletFromBackup ( r) ) ) => {
120
+ let ( descriptor, network, aliases, backup) = r;
121
+ if self . network == network {
122
+ self . imported_backup = true ;
123
+ self . imported_descriptor . value = descriptor. to_string ( ) ;
124
+ return Task :: perform ( async move { ( aliases, backup) } , |( a, b) | {
125
+ Message :: WalletFromBackup ( ( a, b) )
126
+ } ) ;
127
+ } else {
128
+ self . error = Some ( "Backup network do not match the selected network!" . into ( ) ) ;
129
+ }
130
+ }
131
+ Message :: ImportExport ( m) => {
132
+ if let Some ( modal) = self . modal . as_mut ( ) {
133
+ let task: Task < Message > = modal. update ( m) ;
134
+ return task;
135
+ } ;
136
+ }
137
+ _ => { }
93
138
}
94
139
Task :: none ( )
95
140
}
@@ -113,13 +158,19 @@ impl Step for ImportDescriptor {
113
158
progress : ( usize , usize ) ,
114
159
email : Option < & ' a str > ,
115
160
) -> Element < Message > {
116
- view:: import_descriptor (
161
+ let content = view:: import_descriptor (
117
162
progress,
118
163
email,
119
164
& self . imported_descriptor ,
165
+ self . imported_backup ,
120
166
self . wrong_network ,
121
167
self . error . as_ref ( ) ,
122
- )
168
+ ) ;
169
+ if let Some ( modal) = & self . modal {
170
+ modal. view ( content)
171
+ } else {
172
+ content
173
+ }
123
174
}
124
175
}
125
176
0 commit comments