-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAuthCheckScreen.kt
More file actions
54 lines (47 loc) · 1.77 KB
/
AuthCheckScreen.kt
File metadata and controls
54 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package to.bitkit.ui.components
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import to.bitkit.ui.Routes
import to.bitkit.ui.appViewModel
import to.bitkit.ui.settingsViewModel
@Composable
fun AuthCheckScreen(
navController: NavController,
route: Routes.AuthCheck,
) {
val app = appViewModel ?: return
val settings = settingsViewModel ?: return
val isBiometricEnabled by settings.isBiometricEnabled.collectAsStateWithLifecycle()
val isPinForPaymentsEnabled by settings.isPinForPaymentsEnabled.collectAsStateWithLifecycle()
AuthCheckView(
showLogoOnPin = route.showLogoOnPin,
appViewModel = app,
settingsViewModel = settings,
requireBiometrics = route.requireBiometrics,
requirePin = route.requirePin,
onSuccess = {
when (route.onSuccessActionId) {
AuthCheckAction.TOGGLE_BIOMETRICS -> {
settings.setIsBiometricEnabled(!isBiometricEnabled)
navController.popBackStack()
}
AuthCheckAction.TOGGLE_PIN_FOR_PAYMENTS -> {
settings.setIsPinForPaymentsEnabled(!isPinForPaymentsEnabled)
navController.popBackStack()
}
AuthCheckAction.DISABLE_PIN -> {
app.removePin()
navController.popBackStack()
}
}
},
onBack = { navController.popBackStack() },
)
}
object AuthCheckAction {
const val TOGGLE_BIOMETRICS = "TOGGLE_BIOMETRICS"
const val TOGGLE_PIN_FOR_PAYMENTS = "TOGGLE_PIN_FOR_PAYMENTS"
const val DISABLE_PIN = "DISABLE_PIN"
}