Merge pull request #764 from cypherstack/null-wallet

Do not trap user in "restore failed" dialog if serverside issues lead to failure
This commit is contained in:
Diego Salazar 2024-02-20 16:40:40 -07:00 committed by GitHub
commit d6710166f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 8 deletions

View file

@ -13,6 +13,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/providers/global/secure_store_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
@ -65,13 +66,21 @@ class _RestoreFailedDialogState extends ConsumerState<RestoreFailedDialog> {
style: STextStyles.itemSubtitle12(context),
),
onPressed: () async {
await ref.read(pWallets).deleteWallet(
ref.read(pWalletInfo(walletId)),
ref.read(secureStoreProvider),
);
if (mounted) {
Navigator.of(context).pop();
try {
await ref.read(pWallets).deleteWallet(
ref.read(pWalletInfo(walletId)),
ref.read(secureStoreProvider),
);
} catch (e, s) {
Logging.instance.log(
"Error while getting wallet info in restore failed dialog\n"
"Error: $e\nStack trace: $s",
level: LogLevel.Error,
);
} finally {
if (mounted) {
Navigator.of(context).pop();
}
}
},
),

View file

@ -42,7 +42,13 @@ class Wallets {
final Map<String, Wallet> _wallets = {};
Wallet getWallet(String walletId) => _wallets[walletId]!;
Wallet getWallet(String walletId) {
if (_wallets[walletId] != null) {
return _wallets[walletId]!;
} else {
throw Exception("Wallet with id $walletId not found");
}
}
void addWallet(Wallet wallet) {
if (_wallets[wallet.walletId] != null) {