mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
- Fix error popup showing multiple times (#1987)
- Improve/generalize error handling
This commit is contained in:
parent
f90b171d9b
commit
1c07048808
4 changed files with 79 additions and 30 deletions
|
@ -56,3 +56,13 @@ class CreateAssociatedTokenAccountException implements Exception {
|
||||||
class SignSPLTokenTransactionRentException implements Exception {}
|
class SignSPLTokenTransactionRentException implements Exception {}
|
||||||
|
|
||||||
class NoAssociatedTokenAccountException implements Exception {}
|
class NoAssociatedTokenAccountException implements Exception {}
|
||||||
|
|
||||||
|
|
||||||
|
/// ==============================================================================
|
||||||
|
/// ==============================================================================
|
||||||
|
|
||||||
|
class RestoreFromSeedException implements Exception {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
RestoreFromSeedException(this.message);
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:cw_core/exceptions.dart';
|
||||||
|
|
||||||
class ZanoWalletException implements Exception {
|
class ZanoWalletException implements Exception {
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
|
@ -6,7 +8,7 @@ class ZanoWalletException implements Exception {
|
||||||
String toString() => '${this.runtimeType} (message: $message)';
|
String toString() => '${this.runtimeType} (message: $message)';
|
||||||
}
|
}
|
||||||
|
|
||||||
class RestoreFromSeedsException extends ZanoWalletException {
|
class RestoreFromSeedsException extends RestoreFromSeedException {
|
||||||
RestoreFromSeedsException(String message) : super(message);
|
RestoreFromSeedsException(String message) : super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,51 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||||
|
|
||||||
class WalletRestorePage extends BasePage {
|
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>(),
|
: walletRestoreFromSeedFormKey = GlobalKey<WalletRestoreFromSeedFormState>(),
|
||||||
walletRestoreFromKeysFormKey = GlobalKey<WalletRestoreFromKeysFromState>(),
|
walletRestoreFromKeysFormKey = GlobalKey<WalletRestoreFromKeysFromState>(),
|
||||||
_pages = [],
|
_pages = [],
|
||||||
|
@ -54,8 +98,10 @@ class WalletRestorePage extends BasePage {
|
||||||
_validateOnChange(isPolyseed: isPolyseed);
|
_validateOnChange(isPolyseed: isPolyseed);
|
||||||
},
|
},
|
||||||
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
|
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
|
||||||
onPasswordChange: (String password) => walletRestoreViewModel.walletPassword = password,
|
onPasswordChange: (String password) =>
|
||||||
onRepeatedPasswordChange: (String repeatedPassword) => walletRestoreViewModel.repeatedWalletPassword = repeatedPassword));
|
walletRestoreViewModel.walletPassword = password,
|
||||||
|
onRepeatedPasswordChange: (String repeatedPassword) =>
|
||||||
|
walletRestoreViewModel.repeatedWalletPassword = repeatedPassword));
|
||||||
break;
|
break;
|
||||||
case WalletRestoreMode.keys:
|
case WalletRestoreMode.keys:
|
||||||
_pages.add(WalletRestoreFromKeysFrom(
|
_pages.add(WalletRestoreFromKeysFrom(
|
||||||
|
@ -69,8 +115,10 @@ class WalletRestorePage extends BasePage {
|
||||||
},
|
},
|
||||||
displayPrivateKeyField: walletRestoreViewModel.hasRestoreFromPrivateKey,
|
displayPrivateKeyField: walletRestoreViewModel.hasRestoreFromPrivateKey,
|
||||||
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
|
displayWalletPassword: walletRestoreViewModel.hasWalletPassword,
|
||||||
onPasswordChange: (String password) => walletRestoreViewModel.walletPassword = password,
|
onPasswordChange: (String password) =>
|
||||||
onRepeatedPasswordChange: (String repeatedPassword) => walletRestoreViewModel.repeatedWalletPassword = repeatedPassword,
|
walletRestoreViewModel.walletPassword = password,
|
||||||
|
onRepeatedPasswordChange: (String repeatedPassword) =>
|
||||||
|
walletRestoreViewModel.repeatedWalletPassword = repeatedPassword,
|
||||||
onHeightOrDateEntered: (value) => walletRestoreViewModel.isButtonEnabled = value));
|
onHeightOrDateEntered: (value) => walletRestoreViewModel.isButtonEnabled = value));
|
||||||
break;
|
break;
|
||||||
default:
|
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 WalletRestoreViewModel walletRestoreViewModel;
|
||||||
final SeedSettingsViewModel seedSettingsViewModel;
|
final SeedSettingsViewModel seedSettingsViewModel;
|
||||||
final PageController _controller;
|
final PageController _controller;
|
||||||
|
@ -102,20 +135,16 @@ class WalletRestorePage extends BasePage {
|
||||||
final GlobalKey<WalletRestoreFromKeysFromState> walletRestoreFromKeysFormKey;
|
final GlobalKey<WalletRestoreFromKeysFromState> walletRestoreFromKeysFormKey;
|
||||||
final FocusNode _blockHeightFocusNode;
|
final FocusNode _blockHeightFocusNode;
|
||||||
|
|
||||||
|
bool _formProcessing = false;
|
||||||
|
|
||||||
// DerivationType derivationType = DerivationType.unknown;
|
// DerivationType derivationType = DerivationType.unknown;
|
||||||
// String? derivationPath = null;
|
// String? derivationPath = null;
|
||||||
DerivationInfo? derivationInfo;
|
DerivationInfo? derivationInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Function(BuildContext)? get pushToNextWidget => (context) {
|
void initState() {
|
||||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
super.initState();
|
||||||
if (!currentFocus.hasPrimaryFocus) {
|
|
||||||
currentFocus.focusedChild?.unfocus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget body(BuildContext context) {
|
|
||||||
reaction((_) => walletRestoreViewModel.state, (ExecutionState state) {
|
reaction((_) => walletRestoreViewModel.state, (ExecutionState state) {
|
||||||
if (state is FailureState) {
|
if (state is FailureState) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
@ -149,7 +178,10 @@ class WalletRestorePage extends BasePage {
|
||||||
.currentState!.blockchainHeightKey.currentState!.dateController.text = '';
|
.currentState!.blockchainHeightKey.currentState!.dateController.text = '';
|
||||||
walletRestoreFromKeysFormKey.currentState!.nameTextEditingController.text = '';
|
walletRestoreFromKeysFormKey.currentState!.nameTextEditingController.text = '';
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return KeyboardActions(
|
return KeyboardActions(
|
||||||
config: KeyboardActionsConfig(
|
config: KeyboardActionsConfig(
|
||||||
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/settings_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/restore/restore_wallet.dart';
|
||||||
import 'package:cake_wallet/view_model/seed_settings_view_model.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/pathForWallet.dart';
|
||||||
import 'package:cw_core/utils/print_verbose.dart';
|
import 'package:cw_core/utils/print_verbose.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
@ -118,7 +119,11 @@ abstract class WalletCreationVMBase with Store {
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
printV("error: $e");
|
printV("error: $e");
|
||||||
printV("stack: $s");
|
printV("stack: $s");
|
||||||
state = FailureState(e.toString());
|
String message = e.toString();
|
||||||
|
if (e is RestoreFromSeedException) {
|
||||||
|
message = e.message;
|
||||||
|
}
|
||||||
|
state = FailureState(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue