Skip to content

Commit

Permalink
Fix auth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Aug 28, 2024
1 parent 5f76676 commit fc524c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ fun AuthScreen(
AuthScreen(
modifier = modifier,
code = code,
onNumberAdd = {
if (viewModel.insertNumber(it)) {
onAuthSuccess()
}
},
onNumberAdd = viewModel::insertNumber,
onNumberDelete = viewModel::deleteNumber,
onClear = viewModel::clear,
showFingerprint = canUseBiometrics,
Expand Down
14 changes: 4 additions & 10 deletions app/src/main/java/com/xinto/mauth/ui/screen/auth/AuthViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import com.xinto.mauth.domain.SettingsRepository
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.getAndUpdate
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.runBlocking

class AuthViewModel(
private val authRepository: AuthRepository,
Expand All @@ -27,10 +25,8 @@ class AuthViewModel(
initialValue = false
)

fun insertNumber(number: Char): Boolean {
return _code.getAndUpdate {
it + number
} == "5746"
fun insertNumber(number: Char) {
_code.update { it + number }
}

fun deleteNumber() {
Expand All @@ -41,9 +37,7 @@ class AuthViewModel(
_code.value = ""
}

fun validate(code: String): Boolean {
return runBlocking {
authRepository.validate(code)
}
suspend fun validate(code: String): Boolean {
return authRepository.validate(code)
}
}

0 comments on commit fc524c0

Please sign in to comment.