- Fix error popup showing multiple times (#1987)

- Improve/generalize error handling
This commit is contained in:
Omar Hatem 2025-01-30 04:29:55 +02:00 committed by GitHub
parent f90b171d9b
commit 1c07048808
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 79 additions and 30 deletions

View file

@ -56,3 +56,13 @@ class CreateAssociatedTokenAccountException implements Exception {
class SignSPLTokenTransactionRentException implements Exception {}
class NoAssociatedTokenAccountException implements Exception {}
/// ==============================================================================
/// ==============================================================================
class RestoreFromSeedException implements Exception {
final String message;
RestoreFromSeedException(this.message);
}

View file

@ -1,3 +1,5 @@
import 'package:cw_core/exceptions.dart';
class ZanoWalletException implements Exception {
final String message;
@ -6,7 +8,7 @@ class ZanoWalletException implements Exception {
String toString() => '${this.runtimeType} (message: $message)';
}
class RestoreFromSeedsException extends ZanoWalletException {
class RestoreFromSeedsException extends RestoreFromSeedException {
RestoreFromSeedsException(String message) : super(message);
}

View file

@ -23,7 +23,51 @@ import 'package:mobx/mobx.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
class WalletRestorePage extends BasePage {
WalletRestorePage(this.walletRestoreViewModel, this.seedSettingsViewModel)
WalletRestorePage(this.walletRestoreViewModel, this.seedSettingsViewModel);
@override
Widget middle(BuildContext context) => Observer(
builder: (_) => Text(
walletRestoreViewModel.mode == WalletRestoreMode.seed
? S.current.restore_title_from_seed
: S.current.restore_title_from_keys,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: titleColor(context)),
));
final WalletRestoreViewModel walletRestoreViewModel;
final SeedSettingsViewModel seedSettingsViewModel;
@override
Function(BuildContext)? get pushToNextWidget => (context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.focusedChild?.unfocus();
}
};
@override
Widget body(BuildContext context) {
return WalletRestorePageBody(walletRestoreViewModel, seedSettingsViewModel);
}
}
class WalletRestorePageBody extends StatefulWidget {
WalletRestorePageBody(this.walletRestoreViewModel, this.seedSettingsViewModel);
final WalletRestoreViewModel walletRestoreViewModel;
final SeedSettingsViewModel seedSettingsViewModel;
@override
State<WalletRestorePageBody> createState() =>
_WalletRestorePageBodyState(walletRestoreViewModel, seedSettingsViewModel);
}
class _WalletRestorePageBodyState extends State<WalletRestorePageBody> {
_WalletRestorePageBodyState(this.walletRestoreViewModel, this.seedSettingsViewModel)
: walletRestoreFromSeedFormKey = GlobalKey<WalletRestoreFromSeedFormState>(),
walletRestoreFromKeysFormKey = GlobalKey<WalletRestoreFromKeysFromState>(),
_pages = [],
@ -54,8 +98,10 @@ class WalletRestorePage extends BasePage {
_validateOnChange(isPolyseed: isPolyseed);
},
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
onPasswordChange: (String password) => walletRestoreViewModel.walletPassword = password,
onRepeatedPasswordChange: (String repeatedPassword) => walletRestoreViewModel.repeatedWalletPassword = repeatedPassword));
onPasswordChange: (String password) =>
walletRestoreViewModel.walletPassword = password,
onRepeatedPasswordChange: (String repeatedPassword) =>
walletRestoreViewModel.repeatedWalletPassword = repeatedPassword));
break;
case WalletRestoreMode.keys:
_pages.add(WalletRestoreFromKeysFrom(
@ -69,8 +115,10 @@ class WalletRestorePage extends BasePage {
},
displayPrivateKeyField: walletRestoreViewModel.hasRestoreFromPrivateKey,
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
onPasswordChange: (String password) => walletRestoreViewModel.walletPassword = password,
onRepeatedPasswordChange: (String repeatedPassword) => walletRestoreViewModel.repeatedWalletPassword = repeatedPassword,
onPasswordChange: (String password) =>
walletRestoreViewModel.walletPassword = password,
onRepeatedPasswordChange: (String repeatedPassword) =>
walletRestoreViewModel.repeatedWalletPassword = repeatedPassword,
onHeightOrDateEntered: (value) => walletRestoreViewModel.isButtonEnabled = value));
break;
default:
@ -79,21 +127,6 @@ class WalletRestorePage extends BasePage {
});
}
bool _formProcessing = false;
@override
Widget middle(BuildContext context) => Observer(
builder: (_) => Text(
walletRestoreViewModel.mode == WalletRestoreMode.seed
? S.current.restore_title_from_seed
: S.current.restore_title_from_keys,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: titleColor(context)),
));
final WalletRestoreViewModel walletRestoreViewModel;
final SeedSettingsViewModel seedSettingsViewModel;
final PageController _controller;
@ -102,20 +135,16 @@ class WalletRestorePage extends BasePage {
final GlobalKey<WalletRestoreFromKeysFromState> walletRestoreFromKeysFormKey;
final FocusNode _blockHeightFocusNode;
bool _formProcessing = false;
// DerivationType derivationType = DerivationType.unknown;
// String? derivationPath = null;
DerivationInfo? derivationInfo;
@override
Function(BuildContext)? get pushToNextWidget => (context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.focusedChild?.unfocus();
}
};
void initState() {
super.initState();
@override
Widget body(BuildContext context) {
reaction((_) => walletRestoreViewModel.state, (ExecutionState state) {
if (state is FailureState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@ -149,7 +178,10 @@ class WalletRestorePage extends BasePage {
.currentState!.blockchainHeightKey.currentState!.dateController.text = '';
walletRestoreFromKeysFormKey.currentState!.nameTextEditingController.text = '';
});
}
@override
Widget build(BuildContext context) {
return KeyboardActions(
config: KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,

View file

@ -10,6 +10,7 @@ import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import 'package:cake_wallet/view_model/seed_settings_view_model.dart';
import 'package:cw_core/exceptions.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
@ -118,7 +119,11 @@ abstract class WalletCreationVMBase with Store {
} catch (e, s) {
printV("error: $e");
printV("stack: $s");
state = FailureState(e.toString());
String message = e.toString();
if (e is RestoreFromSeedException) {
message = e.message;
}
state = FailureState(message);
}
}