mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
add mutex around _confirmForm to prevent the wallets from breaking (#1602)
Some checks are pending
Cache Dependencies / test (push) Waiting to run
Some checks are pending
Cache Dependencies / test (push) Waiting to run
* add mutex around _confirmForm to prevent the wallets from breaking * add async * drop mutex for a boolean * don't make the variable global
This commit is contained in:
parent
2949299821
commit
4b69277858
2 changed files with 106 additions and 82 deletions
|
@ -25,6 +25,7 @@ import 'package:cake_wallet/themes/extensions/new_wallet_theme.dart';
|
|||
import 'package:cake_wallet/themes/extensions/send_page_theme.dart';
|
||||
import 'package:cake_wallet/entities/seed_type.dart';
|
||||
|
||||
|
||||
class NewWalletPage extends BasePage {
|
||||
NewWalletPage(this._walletNewVM, this._seedTypeViewModel);
|
||||
|
||||
|
@ -74,6 +75,7 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
_walletNewVM.hasWalletPassword ? TextEditingController() : null;
|
||||
|
||||
static const aspectRatioImage = 1.22;
|
||||
static bool formProcessing = false;
|
||||
|
||||
final GlobalKey<FormState> _formKey;
|
||||
final GlobalKey<SeedLanguageSelectorState> _languageSelectorKey;
|
||||
|
@ -347,12 +349,16 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
);
|
||||
}
|
||||
|
||||
void _confirmForm() {
|
||||
void _confirmForm() async {
|
||||
if (formProcessing) return;
|
||||
formProcessing = true;
|
||||
try {
|
||||
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
||||
formProcessing = false;
|
||||
return;
|
||||
}
|
||||
if (_walletNewVM.nameExists(_walletNewVM.name)) {
|
||||
showPopUp<void>(
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return AlertWithOneAction(
|
||||
|
@ -362,11 +368,16 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
|||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
} else {
|
||||
_walletNewVM.create(
|
||||
await _walletNewVM.create(
|
||||
options: _walletNewVM.hasLanguageSelector
|
||||
? [_languageSelectorKey.currentState!.selected, isPolyseed]
|
||||
: null);
|
||||
}
|
||||
} catch (e) {
|
||||
formProcessing = false;
|
||||
rethrow;
|
||||
}
|
||||
formProcessing = false;
|
||||
}
|
||||
|
||||
bool get isPolyseed => widget._seedTypeViewModel.moneroSeedType == SeedType.polyseed;
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:cake_wallet/core/execution_state.dart';
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/new_wallet/new_wallet_page.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_from_keys_form.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_from_seed_form.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
|
@ -80,6 +81,8 @@ class WalletRestorePage extends BasePage {
|
|||
});
|
||||
}
|
||||
|
||||
static bool formProcessing = false;
|
||||
|
||||
@override
|
||||
Widget middle(BuildContext context) => Observer(
|
||||
builder: (_) => Text(
|
||||
|
@ -350,6 +353,9 @@ class WalletRestorePage extends BasePage {
|
|||
}
|
||||
|
||||
Future<void> _confirmForm(BuildContext context) async {
|
||||
if (formProcessing) return;
|
||||
formProcessing = true;
|
||||
try {
|
||||
// Dismissing all visible keyboard to provide context for navigation
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
|
||||
|
@ -367,11 +373,13 @@ class WalletRestorePage extends BasePage {
|
|||
}
|
||||
|
||||
if (!formKey!.currentState!.validate()) {
|
||||
formProcessing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (walletRestoreViewModel.nameExists(name)) {
|
||||
showNameExistsAlert(formContext!);
|
||||
formProcessing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -418,7 +426,12 @@ class WalletRestorePage extends BasePage {
|
|||
this.derivationInfo = walletRestoreViewModel.getDefaultDerivation();
|
||||
}
|
||||
|
||||
walletRestoreViewModel.create(options: _credentials());
|
||||
await walletRestoreViewModel.create(options: _credentials());
|
||||
} catch (e) {
|
||||
formProcessing = false;
|
||||
rethrow;
|
||||
}
|
||||
formProcessing = false;
|
||||
}
|
||||
|
||||
Future<void> showNameExistsAlert(BuildContext context) {
|
||||
|
|
Loading…
Reference in a new issue