mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
ignore unsupported coins from SWB files on restore
This commit is contained in:
parent
1a078955c9
commit
a3a1ddeeaf
1 changed files with 81 additions and 42 deletions
|
@ -46,7 +46,7 @@ import '../../../../../utilities/format.dart';
|
|||
import '../../../../../utilities/logger.dart';
|
||||
import '../../../../../utilities/prefs.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/isar/models/frost_wallet_info.dart';
|
||||
import '../../../../../wallets/isar/models/wallet_info.dart';
|
||||
|
@ -777,7 +777,11 @@ abstract class SWB {
|
|||
|
||||
final coin = AppConfig.getCryptoCurrencyFor(
|
||||
walletbackup['coinName'] as String,
|
||||
)!;
|
||||
);
|
||||
|
||||
if (coin == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final walletName = walletbackup['name'] as String;
|
||||
final walletId = oldToNewWalletIdMap[walletbackup["id"] as String]!;
|
||||
|
@ -963,14 +967,23 @@ abstract class SWB {
|
|||
// pre restore state has contact
|
||||
if (contact != null) {
|
||||
// ensure this contact's data matches the pre restore state
|
||||
List<ContactAddressEntry> addresses = [];
|
||||
for (var address in (contact['addresses'] as List<dynamic>)) {
|
||||
addresses.add(
|
||||
ContactAddressEntry()
|
||||
final List<ContactAddressEntry> addresses = [];
|
||||
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?,
|
||||
..other = address['other'] as String?;
|
||||
|
||||
try {
|
||||
entry.coin;
|
||||
} catch (_) {
|
||||
// coin not supported so ignore this entry
|
||||
continue;
|
||||
}
|
||||
|
||||
addresses.add(
|
||||
entry,
|
||||
);
|
||||
}
|
||||
await addressBookService.editContact(
|
||||
|
@ -1025,7 +1038,8 @@ abstract class SWB {
|
|||
isDown: nodeData['isDown'] as bool,
|
||||
),
|
||||
nodeData['password'] as String?,
|
||||
true);
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
await nodeService.delete(node.id, true);
|
||||
}
|
||||
|
@ -1036,10 +1050,17 @@ abstract class SWB {
|
|||
if (primaryNodes != null) {
|
||||
for (final node in primaryNodes) {
|
||||
try {
|
||||
await nodeService.setPrimaryNodeFor(
|
||||
coin: AppConfig.getCryptoCurrencyByPrettyName(
|
||||
final CryptoCurrency coin;
|
||||
try {
|
||||
coin = AppConfig.getCryptoCurrencyByPrettyName(
|
||||
node['coinName'] as String,
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await nodeService.setPrimaryNodeFor(
|
||||
coin: coin,
|
||||
node: nodeService.getNodeById(id: node['id'] as String)!,
|
||||
);
|
||||
} catch (e, s) {
|
||||
|
@ -1175,14 +1196,24 @@ abstract class SWB {
|
|||
for (final contact in addressBookEntries) {
|
||||
final List<ContactAddressEntry> addresses = [];
|
||||
for (final address in (contact['addresses'] as List<dynamic>)) {
|
||||
addresses.add(
|
||||
ContactAddressEntry()
|
||||
final entry = ContactAddressEntry()
|
||||
..coinName = address['coin'] as String
|
||||
..address = address['address'] as String
|
||||
..label = address['label'] as String
|
||||
..other = address['other'] as String?,
|
||||
..other = address['other'] as String?;
|
||||
|
||||
try {
|
||||
entry.coin;
|
||||
} catch (_) {
|
||||
// coin not supported so ignore this entry
|
||||
continue;
|
||||
}
|
||||
|
||||
addresses.add(
|
||||
entry,
|
||||
);
|
||||
}
|
||||
if (addresses.isNotEmpty) {
|
||||
await addressBookService.addContact(
|
||||
ContactEntry(
|
||||
emojiChar: contact['emoji'] as String?,
|
||||
|
@ -1194,6 +1225,7 @@ abstract class SWB {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _restoreNodes(
|
||||
List<dynamic>? nodes,
|
||||
|
@ -1225,11 +1257,18 @@ abstract class SWB {
|
|||
}
|
||||
if (primaryNodes != null) {
|
||||
for (final node in primaryNodes) {
|
||||
final CryptoCurrency coin;
|
||||
try {
|
||||
coin = AppConfig.getCryptoCurrencyByPrettyName(
|
||||
node['coinName'] as String,
|
||||
);
|
||||
} catch (_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await nodeService.setPrimaryNodeFor(
|
||||
coin: AppConfig.getCryptoCurrencyByPrettyName(
|
||||
node['coinName'] as String,
|
||||
),
|
||||
coin: coin,
|
||||
node: nodeService.getNodeById(id: node['id'] as String)!,
|
||||
);
|
||||
} catch (e, s) {
|
||||
|
|
Loading…
Reference in a new issue