diff --git a/src/Core/Pages/Accounts/LockPageViewModel.cs b/src/Core/Pages/Accounts/LockPageViewModel.cs index f259a382b..052963bac 100644 --- a/src/Core/Pages/Accounts/LockPageViewModel.cs +++ b/src/Core/Pages/Accounts/LockPageViewModel.cs @@ -285,6 +285,8 @@ namespace Bit.App.Pages var failed = true; try { + await MainThread.InvokeOnMainThreadAsync(() => _deviceActionService.ShowLoadingAsync(AppResources.Loading)); + EncString userKeyPin; EncString oldPinProtected; switch (_pinStatus) @@ -333,21 +335,26 @@ namespace Bit.App.Pages { Pin = string.Empty; await AppHelpers.ResetInvalidUnlockAttemptsAsync(); - await SetUserKeyAndContinueAsync(userKey); + await SetUserKeyAndContinueAsync(userKey, shouldHandleHideLoading: true); await Task.Delay(150); //Workaround Delay to avoid "duplicate" execution of SubmitAsync on Android when invoked from the ReturnCommand } } catch (LegacyUserException) { + await MainThread.InvokeOnMainThreadAsync(_deviceActionService.HideLoadingAsync); throw; } - catch + catch (Exception ex) { + _logger.Exception(ex); failed = true; } if (failed) { var invalidUnlockAttempts = await AppHelpers.IncrementInvalidUnlockAttemptsAsync(); + + await MainThread.InvokeOnMainThreadAsync(_deviceActionService.HideLoadingAsync); + if (invalidUnlockAttempts >= 5) { _messagingService.Send("logout"); @@ -536,7 +543,7 @@ namespace Bit.App.Pages } } - private async Task SetUserKeyAndContinueAsync(UserKey key) + private async Task SetUserKeyAndContinueAsync(UserKey key, bool shouldHandleHideLoading = false) { var hasKey = await _cryptoService.HasUserKeyAsync(); if (!hasKey) @@ -544,14 +551,18 @@ namespace Bit.App.Pages await _cryptoService.SetUserKeyAsync(key); } await _deviceTrustCryptoService.TrustDeviceIfNeededAsync(); - await DoContinueAsync(); + await DoContinueAsync(shouldHandleHideLoading); } - private async Task DoContinueAsync() + private async Task DoContinueAsync(bool shouldHandleHideLoading = false) { _syncService.FullSyncAsync(false).FireAndForget(); await _stateService.SetBiometricLockedAsync(false); _watchDeviceService.SyncDataToWatchAsync().FireAndForget(); + if (shouldHandleHideLoading) + { + await MainThread.InvokeOnMainThreadAsync(_deviceActionService.HideLoadingAsync); + } _messagingService.Send("unlocked"); UnlockedAction?.Invoke(); }