Skip to content

Commit

Permalink
feat: Add new wishes and reducer in key password (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzodhalil committed Dec 25, 2023
1 parent 902c31a commit 90deaed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.spherelabs.passphraseimpl.presentation

sealed interface MasterPasswordEffect {
data class Failure(val message: String) : MasterPasswordEffect

object Home : MasterPasswordEffect
object ShowFingerPrint: MasterPasswordEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class MasterPasswordReducer :
}

MasterPasswordWish.ShowFingerPrint -> {
expect(
stateAction = { currentState.copy(isFingerprintEnabled = currentState.isFingerprintEnabled) },
effectAction = { MasterPasswordEffect.ShowFingerPrint },
)
currentState.showFingerPrint()
}

is MasterPasswordWish.OnPasswordCellChanged -> {
Expand All @@ -60,6 +57,10 @@ class MasterPasswordReducer :
effect { MasterPasswordEffect.Failure(currentWish.message) }
}

is MasterPasswordWish.FingerPrintFailure -> {
effect { MasterPasswordEffect.Failure(currentWish.failureMessage) }
}

else -> {
unexpected { currentState }
}
Expand All @@ -82,3 +83,10 @@ private fun MasterPasswordState.keyPasswordChanged(newPassword: String): Change<
state = this.copy(password = currentPassword),
)
}

private fun MasterPasswordState.showFingerPrint(): Change<MasterPasswordState, MasterPasswordEffect> {
return Change(
state = this.copy(isFingerprintEnabled = this.isFingerprintEnabled),
effect = MasterPasswordEffect.ShowFingerPrint,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ sealed interface MasterPasswordWish {
data class IsNotMatched(val message: String) : MasterPasswordWish

object ShowFingerPrint : MasterPasswordWish
data class FingerPrintFailure(val failureMessage: String) : MasterPasswordWish
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,21 @@ fun KeyPasswordContent(

MasterPasswordEffect.ShowFingerPrint -> {
if (state.isFingerprintEnabled) {
biometryAuthenticatorFactory.createBiometryAuthenticator().biometricAuthentication(
title = "# with your fingerprint?",
description = "Use your fingerprint to # with AnyPass",
failureContext = "Accessing fingerprint is failed",
) { result ->
if (result.isSuccess) {
navigateToHome.invoke()
biometryAuthenticatorFactory.createBiometryAuthenticator()
.biometricAuthentication(
title = "# with your fingerprint?",
description = "Use your fingerprint to # with AnyPass",
failureContext = "Accessing fingerprint is failed",
) { result ->
result.onSuccess { isAccepted ->
if (isAccepted) {
navigateToHome.invoke()
}
}.onFailure {
val failureMessage = it.message ?: "Error is occurred."
wish.invoke(MasterPasswordWish.FingerPrintFailure(failureMessage))
}
}
}
}
}
}
Expand Down Expand Up @@ -154,13 +160,15 @@ fun KeyPasswordContent(
items = keypad,
fontFamily = GoogleSansFontFamily,
) { (type, value) ->
when(type) {
when (type) {
KeypadType.Number -> {
wish.invoke(MasterPasswordWish.OnMasterPasswordChanged(value))
}

KeypadType.FingerPrint -> {
wish.invoke(MasterPasswordWish.ShowFingerPrint)
}

KeypadType.Clear -> {
wish.invoke(MasterPasswordWish.ClearPassword)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ actual class BiometricManager(
callback.invoke(Result.failure(Exception(errString.toString())))
}
}

override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult,
) {
Expand Down

0 comments on commit 90deaed

Please # to comment.