@@ -32,6 +32,8 @@ import kotlinx.collections.immutable.persistentListOf
3232import to.bitkit.R
3333import to.bitkit.models.PubkyAuthPermission
3434import to.bitkit.models.PubkyProfile
35+ import to.bitkit.ui.appViewModel
36+ import to.bitkit.ui.components.AuthCheckView
3537import to.bitkit.ui.components.BiometricsView
3638import to.bitkit.ui.components.BodyM
3739import to.bitkit.ui.components.BodySSB
@@ -61,8 +63,10 @@ fun PubkyAuthApprovalSheet(
6163) {
6264 val uiState by viewModel.uiState.collectAsStateWithLifecycle()
6365 var showBiometrics by remember { mutableStateOf(false ) }
66+ var showAuthCheck by remember { mutableStateOf(false ) }
6467 var pendingAuthUrl by remember { mutableStateOf<String ?>(null ) }
6568
69+ val app = appViewModel ? : return
6670 val settings = settingsViewModel ? : return
6771 val isPinEnabled by settings.isPinEnabled.collectAsStateWithLifecycle()
6872 val isBiometricEnabled by settings.isBiometricEnabled.collectAsStateWithLifecycle()
@@ -73,12 +77,29 @@ fun PubkyAuthApprovalSheet(
7377 LaunchedEffect (Unit ) {
7478 viewModel.effects.collect {
7579 when (it) {
76- is PubkyAuthApprovalEffect .RequestBiometric -> {
77- if (isPinEnabled && isBiometricEnabled && isBiometrySupported) {
78- pendingAuthUrl = it.authUrl
79- showBiometrics = true
80- } else {
81- viewModel.confirmAuthorize(it.authUrl)
80+ is PubkyAuthApprovalEffect .RequestLocalAuth -> {
81+ pendingAuthUrl = it.authUrl
82+ when (
83+ resolvePubkyApprovalLocalAuthMode(
84+ isPinEnabled = isPinEnabled,
85+ isBiometricEnabled = isBiometricEnabled,
86+ isBiometrySupported = isBiometrySupported,
87+ )
88+ ) {
89+ PubkyApprovalLocalAuthMode .AuthCheck -> {
90+ showBiometrics = false
91+ showAuthCheck = true
92+ }
93+
94+ PubkyApprovalLocalAuthMode .Biometrics -> {
95+ showAuthCheck = false
96+ showBiometrics = true
97+ }
98+
99+ PubkyApprovalLocalAuthMode .None -> {
100+ pendingAuthUrl = null
101+ viewModel.confirmAuthorize(it.authUrl)
102+ }
82103 }
83104 }
84105 PubkyAuthApprovalEffect .Dismiss -> onDismiss()
@@ -94,6 +115,22 @@ fun PubkyAuthApprovalSheet(
94115 onDismiss = { viewModel.dismiss() },
95116 )
96117
118+ if (showAuthCheck) {
119+ AuthCheckView (
120+ appViewModel = app,
121+ settingsViewModel = settings,
122+ onSuccess = {
123+ showAuthCheck = false
124+ pendingAuthUrl?.let { viewModel.confirmAuthorize(it) }
125+ pendingAuthUrl = null
126+ },
127+ onBack = {
128+ showAuthCheck = false
129+ pendingAuthUrl = null
130+ },
131+ )
132+ }
133+
97134 if (showBiometrics) {
98135 BiometricsView (
99136 onSuccess = {
@@ -110,6 +147,22 @@ fun PubkyAuthApprovalSheet(
110147 }
111148}
112149
150+ internal enum class PubkyApprovalLocalAuthMode {
151+ None ,
152+ Biometrics ,
153+ AuthCheck ,
154+ }
155+
156+ internal fun resolvePubkyApprovalLocalAuthMode (
157+ isPinEnabled : Boolean ,
158+ isBiometricEnabled : Boolean ,
159+ isBiometrySupported : Boolean ,
160+ ): PubkyApprovalLocalAuthMode = when {
161+ isPinEnabled -> PubkyApprovalLocalAuthMode .AuthCheck
162+ isBiometricEnabled && isBiometrySupported -> PubkyApprovalLocalAuthMode .Biometrics
163+ else -> PubkyApprovalLocalAuthMode .None
164+ }
165+
113166@Composable
114167private fun Content (
115168 uiState : PubkyAuthApprovalUiState ,
0 commit comments