@@ -162,6 +162,18 @@ pub struct ImportExportSettingsState {
162
162
modal : Option < ExportModal > ,
163
163
}
164
164
165
+ macro_rules! launch {
166
+ ( $s: ident, $m: ident) => {
167
+ let launch = $m. launch( |m| {
168
+ Message :: View ( view:: Message :: Settings (
169
+ view:: SettingsMessage :: ImportExport ( m) ,
170
+ ) )
171
+ } ) ;
172
+ $s. modal = Some ( $m) ;
173
+ return launch
174
+ } ;
175
+ }
176
+
165
177
impl State for ImportExportSettingsState {
166
178
fn view < ' a > ( & ' a self , cache : & ' a Cache ) -> Element < ' a , view:: Message > {
167
179
let content = view:: settings:: import_export ( cache, self . warning . as_ref ( ) ) ;
@@ -194,27 +206,42 @@ impl State for ImportExportSettingsState {
194
206
wallet : Arc < Wallet > ,
195
207
) -> Task < Message > {
196
208
match message {
197
- Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ImportExport (
198
- ImportExportMessage :: Close ,
199
- ) ) ) => {
209
+ Message :: View ( view:: Message :: ImportExport ( ImportExportMessage :: Close ) ) => {
210
+ log:: warn!( "ImportExportSettingsState.update(Close)" ) ;
200
211
self . modal = None ;
201
212
}
213
+ Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ImportExport ( m) ) ) => {
214
+ log:: warn!( "ImportExportSettingsState.update(ImportExport({:?}))" , m) ;
215
+ if let Some ( modal) = self . modal . as_mut ( ) {
216
+ return modal. update ( m) ;
217
+ } ;
218
+ }
202
219
Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ExportDescriptor ) ) => {
220
+ log:: warn!( "ImportExportSettingsState.update(ExportDescriptor)" ) ;
203
221
if self . modal . is_none ( ) {
204
222
let modal = ExportModal :: new (
205
223
daemon,
206
224
ImportExportType :: Descriptor ( wallet. main_descriptor . clone ( ) ) ,
207
225
) ;
208
- self . modal = Some ( modal) ;
226
+ launch ! ( self , modal) ;
227
+ }
228
+ }
229
+ Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ExportTransactions ) ) => {
230
+ log:: warn!( "ImportExportSettingsState.update(ExportTransactions)" ) ;
231
+ if self . modal . is_none ( ) {
232
+ let modal = ExportModal :: new ( daemon, ImportExportType :: Transactions ) ;
233
+ launch ! ( self , modal) ;
209
234
}
210
235
}
211
236
Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ExportLabels ) ) => {
237
+ log:: warn!( "ImportExportSettingsState.update(ExportLabels)" ) ;
212
238
if self . modal . is_none ( ) {
213
239
let modal = ExportModal :: new ( daemon, ImportExportType :: ExportLabels ) ;
214
- self . modal = Some ( modal) ;
240
+ launch ! ( self , modal) ;
215
241
}
216
242
}
217
243
Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ExportWallet ) ) => {
244
+ log:: warn!( "ImportExportSettingsState.update(ExportWallet)" ) ;
218
245
if self . modal . is_none ( ) {
219
246
let datadir = cache. datadir_path . clone ( ) ;
220
247
let network = cache. network ;
@@ -225,7 +252,8 @@ impl State for ImportExportSettingsState {
225
252
async move {
226
253
let backup =
227
254
Backup :: from_app ( datadir, network, config, wallet, daemon) . await ;
228
- backup. unwrap ( ) . to_string ( )
255
+ let backup = backup. unwrap ( ) ;
256
+ serde_json:: to_string_pretty ( & backup) . unwrap ( )
229
257
// TODO: do not unwrap, return an error message instead
230
258
} ,
231
259
|s| {
@@ -237,20 +265,24 @@ impl State for ImportExportSettingsState {
237
265
}
238
266
}
239
267
Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ExportBackup ( backup) ) ) => {
268
+ log:: warn!( "ImportExportSettingsState.update(ExportBackup)" ) ;
240
269
let modal = ExportModal :: new ( daemon, ImportExportType :: ExportBackup ( backup) ) ;
241
- self . modal = Some ( modal) ;
270
+ launch ! ( self , modal) ;
242
271
}
243
272
Message :: View ( view:: Message :: Settings ( view:: SettingsMessage :: ImportWallet ) ) => {
273
+ log:: warn!( "ImportExportSettingsState.update(ImportWallet)" ) ;
244
274
// TODO:
245
275
if self . modal . is_none ( ) {
246
276
let modal = ExportModal :: new (
247
277
daemon,
248
278
ImportExportType :: Descriptor ( wallet. main_descriptor . clone ( ) ) ,
249
279
) ;
250
- self . modal = Some ( modal) ;
280
+ launch ! ( self , modal) ;
251
281
}
252
282
}
253
- _ => { }
283
+ m => {
284
+ log:: warn!( "ImportExportSettingsState.update({:?})" , m) ;
285
+ }
254
286
}
255
287
256
288
Task :: none ( )
0 commit comments