From 78a256ae3f8e645982e8b3ea1c190734200a6332 Mon Sep 17 00:00:00 2001 From: David Perez Date: Sat, 27 Jan 2024 13:56:41 -0600 Subject: [PATCH] Add biometrics state to UnlockVaultViewModel (#815) --- .../vaultunlock/VaultUnlockViewModel.kt | 23 +++++++++++++------ .../vaultunlock/VaultUnlockScreenTest.kt | 1 + .../vaultunlock/VaultUnlockViewModelTest.kt | 6 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt index fa7df12d6..b7ce27fc4 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt @@ -53,6 +53,7 @@ class VaultUnlockViewModel @Inject constructor( dialog = null, environmentUrl = environmentRepo.environment.label, input = "", + isBiometricEnabled = userState.activeAccount.isBiometricsEnabled, vaultUnlockType = userState.activeAccount.vaultUnlockType, ) }, @@ -87,13 +88,7 @@ class VaultUnlockViewModel @Inject constructor( is VaultUnlockAction.LogoutAccountClick -> handleLogoutAccountClick(action) is VaultUnlockAction.SwitchAccountClick -> handleSwitchAccountClick(action) VaultUnlockAction.UnlockClick -> handleUnlockClick() - is VaultUnlockAction.Internal.ReceiveVaultUnlockResult -> { - handleReceiveVaultUnlockResult(action) - } - - is VaultUnlockAction.Internal.UserStateUpdateReceive -> { - handleUserStateUpdateReceive(action) - } + is VaultUnlockAction.Internal -> handleInternalAction(action) } } @@ -153,6 +148,18 @@ class VaultUnlockViewModel @Inject constructor( } } + private fun handleInternalAction(action: VaultUnlockAction.Internal) { + when (action) { + is VaultUnlockAction.Internal.ReceiveVaultUnlockResult -> { + handleReceiveVaultUnlockResult(action) + } + + is VaultUnlockAction.Internal.UserStateUpdateReceive -> { + handleUserStateUpdateReceive(action) + } + } + } + private fun handleReceiveVaultUnlockResult( action: VaultUnlockAction.Internal.ReceiveVaultUnlockResult, ) { @@ -211,6 +218,7 @@ class VaultUnlockViewModel @Inject constructor( avatarColorString = activeAccountSummary.avatarColorHex, accountSummaries = accountSummaries, email = activeAccountSummary.email, + isBiometricEnabled = userState.activeAccount.isBiometricsEnabled, vaultUnlockType = userState.activeAccount.vaultUnlockType, ) } @@ -229,6 +237,7 @@ data class VaultUnlockState( val environmentUrl: String, val dialog: VaultUnlockDialog?, val input: String, + val isBiometricEnabled: Boolean, val vaultUnlockType: VaultUnlockType, ) : Parcelable { diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt index 629b48168..4dcfc1f9f 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt @@ -377,5 +377,6 @@ private val DEFAULT_STATE: VaultUnlockState = VaultUnlockState( environmentUrl = DEFAULT_ENVIRONMENT_URL, initials = "AU", input = "", + isBiometricEnabled = true, vaultUnlockType = VaultUnlockType.MASTER_PASSWORD, ) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt index a0b9705b0..3125af218 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt @@ -34,7 +34,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() { private val mutableUserStateFlow = MutableStateFlow(DEFAULT_USER_STATE) private val environmentRepository = FakeEnvironmentRepository() - private val authRepository = mockk() { + private val authRepository = mockk { every { activeUserId } answers { mutableUserStateFlow.value?.activeUserId } every { userStateFlow } returns mutableUserStateFlow every { hasPendingAccountAddition } returns false @@ -145,7 +145,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() { isPremium = true, isLoggedIn = true, isVaultUnlocked = false, - isBiometricsEnabled = false, + isBiometricsEnabled = true, organizations = emptyList(), ), ), @@ -168,6 +168,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() { isVaultUnlocked = false, ), ), + isBiometricEnabled = true, ), viewModel.stateFlow.value, ) @@ -557,6 +558,7 @@ private val DEFAULT_STATE: VaultUnlockState = VaultUnlockState( dialog = null, environmentUrl = Environment.Us.label, input = "", + isBiometricEnabled = false, vaultUnlockType = VaultUnlockType.MASTER_PASSWORD, )