@@ -23,20 +23,12 @@ use crate::{
2323 hw:: { HardwareWallet , HardwareWalletMessage , HardwareWallets } ,
2424 installer:: {
2525 message:: { self , Message } ,
26+ step:: import_descriptor:: { ImportDescriptorModal , BACKUP_NETWORK_NOT_MATCH } ,
2627 step:: { Context , Step } ,
2728 view, Error ,
2829 } ,
2930} ;
3031
31- const BACKUP_NETWORK_NOT_MATCH : & str = "Backup network do not match the selected network!" ;
32-
33- #[ derive( Debug ) ]
34- pub enum ImportDescriptorModal {
35- None ,
36- Export ( ExportModal ) ,
37- Decrypt ( DecryptModal ) ,
38- }
39-
4032pub struct ImportDescriptor {
4133 network : Network ,
4234 wrong_network : bool ,
@@ -95,23 +87,7 @@ impl Step for ImportDescriptor {
9587 }
9688
9789 fn subscription ( & self , hws : & HardwareWallets ) -> Subscription < Message > {
98- if let ImportDescriptorModal :: Export ( modal) = & self . modal {
99- if let Some ( sub) = modal. subscription ( ) {
100- sub. map ( |m| Message :: ImportExport ( ImportExportMessage :: Progress ( m) ) )
101- } else {
102- Subscription :: none ( )
103- }
104- } else if let ImportDescriptorModal :: Decrypt ( modal) = & self . modal {
105- let mut batch = vec ! [ hws. refresh( ) . map( Message :: HardwareWallets ) ] ;
106- if let Some ( import_modal) = modal. modal . as_ref ( ) {
107- if let Some ( sub) = import_modal. subscription ( ) {
108- batch. push ( sub. map ( |p| Message :: ImportExport ( ImportExportMessage :: Progress ( p) ) ) )
109- }
110- }
111- Subscription :: batch ( batch)
112- } else {
113- Subscription :: none ( )
114- }
90+ self . modal . subscriptions ( hws)
11591 }
11692
11793 fn update ( & mut self , hws : & mut HardwareWallets , message : Message ) -> Task < Message > {
@@ -167,29 +143,7 @@ impl Step for ImportDescriptor {
167143 self . modal = ImportDescriptorModal :: Decrypt ( DecryptModal :: new ( bytes, self . network ) ) ;
168144 None
169145 }
170- Message :: ImportExport ( ImportExportMessage :: Progress ( Progress :: Xpub ( xpub) ) ) => {
171- if let ImportDescriptorModal :: Decrypt ( modal) = & mut self . modal {
172- let _ = modal. update ( Decrypt :: CloseModal ) ;
173- Some ( modal. update ( Decrypt :: Xpub ( xpub) ) )
174- } else {
175- None
176- }
177- }
178- Message :: ImportExport ( m) => {
179- if let ImportDescriptorModal :: Export ( modal) = & mut self . modal {
180- let task: Task < Message > = modal. update ( m) ;
181- Some ( task)
182- } else if let ImportDescriptorModal :: Decrypt ( modal) = & mut self . modal {
183- if let Some ( mo) = & mut modal. modal {
184- let task: Task < Message > = mo. update ( m) ;
185- Some ( task)
186- } else {
187- None
188- }
189- } else {
190- None
191- }
192- }
146+ Message :: ImportExport ( m) => Some ( self . modal . update ( Message :: ImportExport ( m) ) ) ,
193147 Message :: HardwareWallets ( HardwareWalletMessage :: Update ) => {
194148 if let ImportDescriptorModal :: Decrypt ( modal) = & mut self . modal {
195149 modal. update_devices ( hws)
@@ -230,31 +184,7 @@ impl Step for ImportDescriptor {
230184 }
231185 None
232186 }
233- Message :: Decrypt ( msg) => {
234- if let ImportDescriptorModal :: Decrypt ( modal) = & mut self . modal {
235- match msg {
236- Decrypt :: Fetched ( _, _)
237- | Decrypt :: Xpub ( _)
238- | Decrypt :: XpubError ( _)
239- | Decrypt :: Mnemonic ( _)
240- | Decrypt :: MnemonicStatus ( _, _)
241- | Decrypt :: UnexpectedPayload ( _)
242- | Decrypt :: InvalidDescriptor
243- | Decrypt :: ContentNotSupported
244- | Decrypt :: PasteXpub
245- | Decrypt :: SelectXpub
246- | Decrypt :: PasteMnemonic
247- | Decrypt :: SelectMnemonic
248- | Decrypt :: SelectImportXpub
249- | Decrypt :: None
250- | Decrypt :: CloseModal
251- | Decrypt :: ShowOptions ( _) => Some ( modal. update ( msg) ) ,
252- Decrypt :: Backup ( _) | Decrypt :: Close => None ,
253- }
254- } else {
255- None
256- }
257- }
187+ Message :: Decrypt ( msg) => Some ( self . modal . update ( Message :: Decrypt ( msg) ) ) ,
258188 _ => None ,
259189 } ;
260190 task. unwrap_or ( Task :: none ( ) )
@@ -306,11 +236,7 @@ impl Step for ImportDescriptor {
306236 self . wrong_network ,
307237 self . error . as_ref ( ) ,
308238 ) ;
309- match & self . modal {
310- ImportDescriptorModal :: None => content,
311- ImportDescriptorModal :: Export ( modal) => modal. view ( content) ,
312- ImportDescriptorModal :: Decrypt ( modal) => modal. view ( content) ,
313- }
239+ self . modal . view ( content)
314240 }
315241}
316242
0 commit comments