Skip to content

Commit

Permalink
Reduce the waiting time when user unlock the wallet with password/pin
Browse files Browse the repository at this point in the history
Fixes #975
  • Loading branch information
Chralu authored and redDwarf03 committed Jun 17, 2024
1 parent 1adf003 commit 24df79b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
16 changes: 13 additions & 3 deletions lib/ui/views/authenticate/password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ class _PasswordScreenState extends ConsumerState<PasswordScreen>
if (!_canBeSubmitted) return;
if (!mounted) return;

// Do not use setState for that [isProcessing] flag : unlock operation stalls UI on web, so it delays setState operation.
isProcessing = true;
setState(() {
isProcessing = true;
});
// wait for next redraw to perform operation.
// that way, we ensure [isProcessing] change is reflecter on the UI
// This is necessary because [setPassword] decyphering operation
// stalls UI on web platform (single-threaded)
await Future.delayed(
const Duration(milliseconds: 5),
() {},
);

final password = enterPasswordController!.text;
final result = await ref
.read(
Expand Down Expand Up @@ -128,7 +138,7 @@ class _PasswordScreenState extends ConsumerState<PasswordScreen>
Dimens.buttonTopDimens,
key: const Key('confirm'),
onPressed: _verifyPassword,
disabled: !_canBeSubmitted,
disabled: !_canBeSubmitted || isProcessing,
),
],
);
Expand Down
18 changes: 15 additions & 3 deletions lib/ui/views/settings/set_password.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class _SetPasswordState extends ConsumerState<SetPassword>
Dimens.buttonTopDimens,
key: const Key('confirm'),
onPressed: _validateRequest,
disabled: isProcessing,
),
],
);
Expand Down Expand Up @@ -237,7 +238,9 @@ class _SetPasswordState extends ConsumerState<SetPassword>
controller: confirmPasswordController,
textInputAction: TextInputAction.done,
autocorrect: false,
onSubmitted: (_) => _validateRequest(),
onSubmitted: (_) async {
await _validateRequest();
},
onChanged: (String newText) {
if (passwordError != null) {
setState(() {
Expand Down Expand Up @@ -326,8 +329,17 @@ class _SetPasswordState extends ConsumerState<SetPassword>
return;
}

// Do not use setState for that [isProcessing] flag : unlock operation stalls UI on web, so it delays setState operation.
isProcessing = true;
setState(() {
isProcessing = true;
});
// wait for next redraw to perfor operation.
// that way, we ensure [isProcessing] change is reflecter on the UI
// This is necessary because [setPassword] decyphering operation
// stalls UI on web platform (single-threaded)
await Future.delayed(
const Duration(milliseconds: 5),
() {},
);
await ref
.read(AuthenticationProviders.passwordAuthentication.notifier)
.setPassword(setPasswordController!.text);
Expand Down
8 changes: 4 additions & 4 deletions test/vault_secure_storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ void main() {
'Should decrypt securedKey with right salt and password',
() async {
final securedKey = Uint8List.fromList([1, 2, 3, 4]);
final encryptedSecureKey = Hive.encryptSecureKey(
final encryptedSecureKey = await Hive.encryptSecureKey(
'salt_ok',
'password_ok',
securedKey,
);
final decryptedSecureKey = Hive.decryptSecureKey(
final decryptedSecureKey = await Hive.decryptSecureKey(
'salt_ok',
'password_ok',
encryptedSecureKey,
Expand All @@ -143,7 +143,7 @@ void main() {
() async => Hive.decryptSecureKey(
'wrong_salt',
'password_ok',
encryptedSecureKey,
await encryptedSecureKey,
),
throwsA(isA<InvalidCipherTextException>()),
);
Expand All @@ -162,7 +162,7 @@ void main() {
() async => Hive.decryptSecureKey(
'salt_ok',
'wrong_password',
encryptedSecuredKey,
await encryptedSecuredKey,
),
throwsA(isA<InvalidCipherTextException>()),
);
Expand Down
13 changes: 12 additions & 1 deletion web_chrome_extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24df79b

Please sign in to comment.