mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
show loading and ensure desktop password functions aren't doubled called with a lock
This commit is contained in:
parent
744107b3eb
commit
676ab60c6f
2 changed files with 85 additions and 62 deletions
|
@ -23,6 +23,7 @@ import '../../themes/stack_colors.dart';
|
|||
import '../../utilities/assets.dart';
|
||||
import '../../utilities/constants.dart';
|
||||
import '../../utilities/flutter_secure_storage_interface.dart';
|
||||
import '../../utilities/show_loading.dart';
|
||||
import '../../utilities/text_styles.dart';
|
||||
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
import '../../widgets/desktop/desktop_app_bar.dart';
|
||||
|
@ -68,12 +69,7 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
|
||||
bool _nextLock = false;
|
||||
|
||||
void onNextPressed() async {
|
||||
if (_nextLock) {
|
||||
return;
|
||||
}
|
||||
_nextLock = true;
|
||||
|
||||
Future<void> _onNextPressed() async {
|
||||
final String passphrase = passwordController.text;
|
||||
final String repeatPassphrase = passwordRepeatController.text;
|
||||
|
||||
|
@ -85,7 +81,6 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
_nextLock = false;
|
||||
return;
|
||||
}
|
||||
if (passphrase != repeatPassphrase) {
|
||||
|
@ -96,11 +91,11 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
_nextLock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
whileFuture() async {
|
||||
if (await ref.read(storageCryptoHandlerProvider).hasPassword()) {
|
||||
throw Exception(
|
||||
"Tried creating a new password and attempted to overwrite an existing entry!",
|
||||
|
@ -108,7 +103,19 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
}
|
||||
|
||||
await ref.read(storageCryptoHandlerProvider).initFromNew(passphrase);
|
||||
await (ref.read(secureStoreProvider).store as DesktopSecureStore).init();
|
||||
await (ref.read(secureStoreProvider).store as DesktopSecureStore)
|
||||
.init();
|
||||
}
|
||||
|
||||
await showLoading(
|
||||
whileFuture: whileFuture(),
|
||||
context: context,
|
||||
message: "Initializing...",
|
||||
rootNavigator: true,
|
||||
onException: (e) {
|
||||
throw e;
|
||||
},
|
||||
);
|
||||
|
||||
// load default nodes now as node service requires storage handler to exist
|
||||
|
||||
|
@ -116,6 +123,7 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
await ref.read(nodeServiceChangeNotifierProvider).updateDefaults();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
|
@ -123,7 +131,7 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
_nextLock = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -152,8 +160,20 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _onNextPressedWrapper() async {
|
||||
if (_nextLock) {
|
||||
return;
|
||||
}
|
||||
_nextLock = true;
|
||||
|
||||
try {
|
||||
await _onNextPressed();
|
||||
} finally {
|
||||
_nextLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -464,7 +484,7 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
|||
: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.getPrimaryDisabledButtonStyle(context),
|
||||
onPressed: nextEnabled ? onNextPressed : null,
|
||||
onPressed: nextEnabled ? _onNextPressedWrapper : null,
|
||||
child: Text(
|
||||
"Next",
|
||||
style: nextEnabled
|
||||
|
|
|
@ -21,6 +21,7 @@ import '../../../providers/desktop/storage_crypto_handler_provider.dart';
|
|||
import '../../../themes/stack_colors.dart';
|
||||
import '../../../utilities/assets.dart';
|
||||
import '../../../utilities/constants.dart';
|
||||
import '../../../utilities/show_loading.dart';
|
||||
import '../../../utilities/text_styles.dart';
|
||||
import '../../../widgets/desktop/primary_button.dart';
|
||||
import '../../../widgets/progress_bar.dart';
|
||||
|
@ -62,7 +63,8 @@ class _SecuritySettings extends ConsumerState<SecuritySettings> {
|
|||
String passwordFeedback =
|
||||
"Add another word or two. Uncommon words are better. Use a few words, avoid common phrases. No need for symbols, digits, or uppercase letters.";
|
||||
|
||||
Future<bool> attemptChangePW() async {
|
||||
bool _changePWLock = false;
|
||||
Future<(bool, FlushBarType, String)> _attemptChangePW() async {
|
||||
final String pw = passwordCurrentController.text;
|
||||
final String pwNew = passwordController.text;
|
||||
final String pwNewRepeat = passwordRepeatController.text;
|
||||
|
@ -74,14 +76,7 @@ class _SecuritySettings extends ConsumerState<SecuritySettings> {
|
|||
if (pwNew != pwNewRepeat) {
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "New passphrase does not match!",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
return (false, FlushBarType.warning, "New passphrase does not match!");
|
||||
} else {
|
||||
final success =
|
||||
await ref.read(storageCryptoHandlerProvider).changePassphrase(
|
||||
|
@ -92,38 +87,21 @@ class _SecuritySettings extends ConsumerState<SecuritySettings> {
|
|||
if (success) {
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.success,
|
||||
message: "Passphrase successfully changed",
|
||||
context: context,
|
||||
),
|
||||
return (
|
||||
true,
|
||||
FlushBarType.success,
|
||||
"Passphrase successfully changed"
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "Passphrase change failed",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
return (false, FlushBarType.warning, "Passphrase change failed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.warning,
|
||||
message: "Current passphrase is not valid!",
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
return (false, FlushBarType.warning, "Current passphrase is not valid!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -522,13 +500,38 @@ class _SecuritySettings extends ConsumerState<SecuritySettings> {
|
|||
enabled: shouldEnableSave,
|
||||
label: "Save changes",
|
||||
onPressed: () async {
|
||||
final didChangePW =
|
||||
await attemptChangePW();
|
||||
if (didChangePW) {
|
||||
if (_changePWLock) {
|
||||
return;
|
||||
}
|
||||
_changePWLock = true;
|
||||
|
||||
try {
|
||||
final (didChangePW, type, message) =
|
||||
(await showLoading(
|
||||
whileFuture: _attemptChangePW(),
|
||||
context: context,
|
||||
message: "Updating...",
|
||||
rootNavigator: true,
|
||||
))!;
|
||||
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: type,
|
||||
message: message,
|
||||
context: context,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (didChangePW == true) {
|
||||
setState(() {
|
||||
changePassword = false;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
_changePWLock = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue