@@ -269,97 +269,86 @@ abstract class SWB {
269269
270270 final List <dynamic > backupWallets = [];
271271 for (final wallet in _wallets.wallets) {
272- try {
273- final Map <String , dynamic > backupWallet = {};
274- backupWallet['name' ] = wallet.info.name;
275- backupWallet['id' ] = wallet.walletId;
276- backupWallet['isFavorite' ] = wallet.info.isFavourite;
277- backupWallet['otherDataJsonString' ] = wallet.info.otherDataJsonString;
278-
279- // Check secure storage for view-only data even if flag is missing.
280- String ? rawViewOnlyData;
281- if (wallet is ViewOnlyOptionInterface ) {
282- rawViewOnlyData = await _secureStore.read (
283- key: Wallet .getViewOnlyWalletDataSecStoreKey (
284- walletId: wallet.walletId,
285- ),
272+ final Map <String , dynamic > backupWallet = {};
273+ backupWallet['name' ] = wallet.info.name;
274+ backupWallet['id' ] = wallet.walletId;
275+ backupWallet['isFavorite' ] = wallet.info.isFavourite;
276+ backupWallet['otherDataJsonString' ] = wallet.info.otherDataJsonString;
277+
278+ // Check secure storage for view-only data even if flag is missing.
279+ String ? rawViewOnlyData;
280+ if (wallet is ViewOnlyOptionInterface ) {
281+ rawViewOnlyData = await _secureStore.read (
282+ key: Wallet .getViewOnlyWalletDataSecStoreKey (
283+ walletId: wallet.walletId,
284+ ),
285+ );
286+ }
287+
288+ if (rawViewOnlyData != null ) {
289+ backupWallet['viewOnlyWalletDataKey' ] = rawViewOnlyData;
290+ // Patch missing isViewOnlyKey flag in otherDataJsonString.
291+ if (wallet.info.otherData[WalletInfoKeys .isViewOnlyKey] != true ) {
292+ final patchedOtherData = Map <String , dynamic >.from (
293+ wallet.info.otherData,
294+ );
295+ patchedOtherData[WalletInfoKeys .isViewOnlyKey] = true ;
296+ final parsed = ViewOnlyWalletData .fromJsonEncodedString (
297+ rawViewOnlyData,
298+ walletId: wallet.walletId,
286299 );
300+ patchedOtherData[WalletInfoKeys .viewOnlyTypeIndexKey] =
301+ parsed.type.index;
302+ backupWallet['otherDataJsonString' ] = jsonEncode (patchedOtherData);
287303 }
288-
289- if (rawViewOnlyData != null ) {
290- backupWallet['viewOnlyWalletDataKey' ] = rawViewOnlyData;
291- // Patch missing isViewOnlyKey flag in otherDataJsonString.
292- if (wallet.info.otherData[WalletInfoKeys .isViewOnlyKey] != true ) {
293- final patchedOtherData = Map <String , dynamic >.from (
294- wallet.info.otherData,
295- );
296- patchedOtherData[WalletInfoKeys .isViewOnlyKey] = true ;
297- final parsed = ViewOnlyWalletData .fromJsonEncodedString (
298- rawViewOnlyData,
299- walletId: wallet.walletId,
300- );
301- patchedOtherData[WalletInfoKeys .viewOnlyTypeIndexKey] =
302- parsed.type.index;
303- backupWallet['otherDataJsonString' ] = jsonEncode (
304- patchedOtherData,
305- );
306- }
307- } else if (wallet is MnemonicInterface ) {
308- backupWallet['mnemonic' ] = await wallet.getMnemonic ();
309- backupWallet['mnemonicPassphrase' ] = await wallet
310- .getMnemonicPassphrase ();
311- } else if (wallet is PrivateKeyInterface ) {
312- backupWallet['privateKey' ] = await wallet.getPrivateKey ();
313- } else if (wallet is BitcoinFrostWallet ) {
314- final String ? keys = await wallet.getSerializedKeys ();
315- final String ? config = await wallet.getMultisigConfig ();
316- if (keys == null || config == null ) {
317- final String err =
318- "${wallet .info .coin .identifier } wallet ${wallet .info .name } "
319- "has null keys or config" ;
320- Logging .instance.e (err);
321- throw Exception (err);
322- }
323- //This case should never actually happen in practice unless the whole
324- // wallet is somehow corrupt
325- // TODO [prio=low]: solve case in which either keys or config is null.
326-
327- // Format keys & config as a JSON string and set otherDataJsonString.
328- final Map <String , dynamic > frostData = {};
329- frostData["keys" ] = keys;
330- frostData["config" ] = config;
331- backupWallet['frostWalletData' ] = jsonEncode (frostData);
304+ } else if (wallet is MnemonicInterface ) {
305+ backupWallet['mnemonic' ] = await wallet.getMnemonic ();
306+ backupWallet['mnemonicPassphrase' ] = await wallet
307+ .getMnemonicPassphrase ();
308+ } else if (wallet is PrivateKeyInterface ) {
309+ backupWallet['privateKey' ] = await wallet.getPrivateKey ();
310+ } else if (wallet is BitcoinFrostWallet ) {
311+ final String ? keys = await wallet.getSerializedKeys ();
312+ final String ? config = await wallet.getMultisigConfig ();
313+ if (keys == null || config == null ) {
314+ final String err =
315+ "${wallet .info .coin .identifier } wallet ${wallet .info .name } "
316+ "has null keys or config" ;
317+ Logging .instance.e (err);
318+ throw Exception (err);
332319 }
333- backupWallet['coinName' ] = wallet.info.coin.identifier;
334- backupWallet['storedChainHeight' ] = wallet.info.cachedChainHeight;
320+ //This case should never actually happen in practice unless the whole
321+ // wallet is somehow corrupt
322+ // TODO [prio=low]: solve case in which either keys or config is null.
323+
324+ // Format keys & config as a JSON string and set otherDataJsonString.
325+ final Map <String , dynamic > frostData = {};
326+ frostData["keys" ] = keys;
327+ frostData["config" ] = config;
328+ backupWallet['frostWalletData' ] = jsonEncode (frostData);
329+ }
330+ backupWallet['coinName' ] = wallet.info.coin.identifier;
331+ backupWallet['storedChainHeight' ] = wallet.info.cachedChainHeight;
335332
336- // backupWallet['txidList'] = DB.instance.get<dynamic>(
337- // boxName: wallet.walletId, key: "cachedTxids") as List?;
338- // the following can cause a deadlock
339- // (await manager.transactionData).getAllTransactions().keys.toList();
333+ // backupWallet['txidList'] = DB.instance.get<dynamic>(
334+ // boxName: wallet.walletId, key: "cachedTxids") as List?;
335+ // the following can cause a deadlock
336+ // (await manager.transactionData).getAllTransactions().keys.toList();
340337
341- backupWallet['restoreHeight' ] = wallet.info.restoreHeight;
338+ backupWallet['restoreHeight' ] = wallet.info.restoreHeight;
342339
343- final isarNotes = await MainDB .instance.isar.transactionNotes
344- .where ()
345- .walletIdEqualTo (wallet.walletId)
346- .findAll ();
340+ final isarNotes = await MainDB .instance.isar.transactionNotes
341+ .where ()
342+ .walletIdEqualTo (wallet.walletId)
343+ .findAll ();
347344
348- final notes = isarNotes.asMap ().map (
349- (key, value) => MapEntry (value.txid, value.value),
350- );
345+ final notes = isarNotes.asMap ().map (
346+ (key, value) => MapEntry (value.txid, value.value),
347+ );
351348
352- backupWallet['notes' ] = notes;
349+ backupWallet['notes' ] = notes;
353350
354- backupWallets.add (backupWallet);
355- } catch (e, s) {
356- Logging .instance.w (
357- "SWB skipping wallet ${wallet .info .name } "
358- "(${wallet .info .coin .identifier })" ,
359- error: e,
360- stackTrace: s,
361- );
362- }
351+ backupWallets.add (backupWallet);
363352 }
364353 backupJson['wallets' ] = backupWallets;
365354
0 commit comments