ignore unsupported coins from SWB files on restore

This commit is contained in:
julian 2024-05-24 12:10:13 -06:00
parent 1a078955c9
commit a3a1ddeeaf

View file

@ -46,7 +46,7 @@ import '../../../../../utilities/format.dart';
import '../../../../../utilities/logger.dart'; import '../../../../../utilities/logger.dart';
import '../../../../../utilities/prefs.dart'; import '../../../../../utilities/prefs.dart';
import '../../../../../utilities/util.dart'; import '../../../../../utilities/util.dart';
import '../../../../../wallets/crypto_currency/coins/firo.dart'; import '../../../../../wallets/crypto_currency/crypto_currency.dart';
import '../../../../../wallets/crypto_currency/intermediate/frost_currency.dart'; import '../../../../../wallets/crypto_currency/intermediate/frost_currency.dart';
import '../../../../../wallets/isar/models/frost_wallet_info.dart'; import '../../../../../wallets/isar/models/frost_wallet_info.dart';
import '../../../../../wallets/isar/models/wallet_info.dart'; import '../../../../../wallets/isar/models/wallet_info.dart';
@ -777,7 +777,11 @@ abstract class SWB {
final coin = AppConfig.getCryptoCurrencyFor( final coin = AppConfig.getCryptoCurrencyFor(
walletbackup['coinName'] as String, walletbackup['coinName'] as String,
)!; );
if (coin == null) {
continue;
}
final walletName = walletbackup['name'] as String; final walletName = walletbackup['name'] as String;
final walletId = oldToNewWalletIdMap[walletbackup["id"] as String]!; final walletId = oldToNewWalletIdMap[walletbackup["id"] as String]!;
@ -963,14 +967,23 @@ abstract class SWB {
// pre restore state has contact // pre restore state has contact
if (contact != null) { if (contact != null) {
// ensure this contact's data matches the pre restore state // ensure this contact's data matches the pre restore state
List<ContactAddressEntry> addresses = []; final List<ContactAddressEntry> addresses = [];
for (var address in (contact['addresses'] as List<dynamic>)) { for (final address in (contact['addresses'] as List<dynamic>)) {
final entry = ContactAddressEntry()
..coinName = address['coin'] as String
..address = address['address'] as String
..label = address['label'] as String
..other = address['other'] as String?;
try {
entry.coin;
} catch (_) {
// coin not supported so ignore this entry
continue;
}
addresses.add( addresses.add(
ContactAddressEntry() entry,
..coinName = address['coin'] as String
..address = address['address'] as String
..label = address['label'] as String
..other = address['other'] as String?,
); );
} }
await addressBookService.editContact( await addressBookService.editContact(
@ -1013,19 +1026,20 @@ abstract class SWB {
// node existed before restore attempt // node existed before restore attempt
// revert to pre restore node // revert to pre restore node
await nodeService.edit( await nodeService.edit(
node.copyWith( node.copyWith(
host: nodeData['host'] as String, host: nodeData['host'] as String,
port: nodeData['port'] as int, port: nodeData['port'] as int,
name: nodeData['name'] as String, name: nodeData['name'] as String,
useSSL: nodeData['useSSL'] == "false" ? false : true, useSSL: nodeData['useSSL'] == "false" ? false : true,
enabled: nodeData['enabled'] == "false" ? false : true, enabled: nodeData['enabled'] == "false" ? false : true,
coinName: nodeData['coinName'] as String, coinName: nodeData['coinName'] as String,
loginName: nodeData['loginName'] as String?, loginName: nodeData['loginName'] as String?,
isFailover: nodeData['isFailover'] as bool, isFailover: nodeData['isFailover'] as bool,
isDown: nodeData['isDown'] as bool, isDown: nodeData['isDown'] as bool,
), ),
nodeData['password'] as String?, nodeData['password'] as String?,
true); true,
);
} else { } else {
await nodeService.delete(node.id, true); await nodeService.delete(node.id, true);
} }
@ -1036,10 +1050,17 @@ abstract class SWB {
if (primaryNodes != null) { if (primaryNodes != null) {
for (final node in primaryNodes) { for (final node in primaryNodes) {
try { try {
await nodeService.setPrimaryNodeFor( final CryptoCurrency coin;
coin: AppConfig.getCryptoCurrencyByPrettyName( try {
coin = AppConfig.getCryptoCurrencyByPrettyName(
node['coinName'] as String, node['coinName'] as String,
), );
} catch (_) {
continue;
}
await nodeService.setPrimaryNodeFor(
coin: coin,
node: nodeService.getNodeById(id: node['id'] as String)!, node: nodeService.getNodeById(id: node['id'] as String)!,
); );
} catch (e, s) { } catch (e, s) {
@ -1175,23 +1196,34 @@ abstract class SWB {
for (final contact in addressBookEntries) { for (final contact in addressBookEntries) {
final List<ContactAddressEntry> addresses = []; final List<ContactAddressEntry> addresses = [];
for (final address in (contact['addresses'] as List<dynamic>)) { for (final address in (contact['addresses'] as List<dynamic>)) {
final entry = ContactAddressEntry()
..coinName = address['coin'] as String
..address = address['address'] as String
..label = address['label'] as String
..other = address['other'] as String?;
try {
entry.coin;
} catch (_) {
// coin not supported so ignore this entry
continue;
}
addresses.add( addresses.add(
ContactAddressEntry() entry,
..coinName = address['coin'] as String );
..address = address['address'] as String }
..label = address['label'] as String if (addresses.isNotEmpty) {
..other = address['other'] as String?, await addressBookService.addContact(
ContactEntry(
emojiChar: contact['emoji'] as String?,
name: contact['name'] as String,
addresses: addresses,
isFavorite: contact['isFavorite'] as bool,
customId: contact['id'] as String,
),
); );
} }
await addressBookService.addContact(
ContactEntry(
emojiChar: contact['emoji'] as String?,
name: contact['name'] as String,
addresses: addresses,
isFavorite: contact['isFavorite'] as bool,
customId: contact['id'] as String,
),
);
} }
} }
@ -1225,11 +1257,18 @@ abstract class SWB {
} }
if (primaryNodes != null) { if (primaryNodes != null) {
for (final node in primaryNodes) { for (final node in primaryNodes) {
final CryptoCurrency coin;
try {
coin = AppConfig.getCryptoCurrencyByPrettyName(
node['coinName'] as String,
);
} catch (_) {
continue;
}
try { try {
await nodeService.setPrimaryNodeFor( await nodeService.setPrimaryNodeFor(
coin: AppConfig.getCryptoCurrencyByPrettyName( coin: coin,
node['coinName'] as String,
),
node: nodeService.getNodeById(id: node['id'] as String)!, node: nodeService.getNodeById(id: node['id'] as String)!,
); );
} catch (e, s) { } catch (e, s) {