-
Notifications
You must be signed in to change notification settings - Fork 20
/
GetE2EICertificateUI.kt
56 lines (51 loc) 路 2.21 KB
/
GetE2EICertificateUI.kt
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
55
56
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.e2eiEnrollment
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import com.wire.android.feature.e2ei.OAuthUseCase
import com.wire.android.util.extension.getActivity
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.functional.Either
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@Composable
fun GetE2EICertificateUI(
enrollmentResultHandler: (Either<CoreFailure, E2EIEnrollmentResult>) -> Unit,
isNewClient: Boolean,
viewModel: GetE2EICertificateViewModel = hiltViewModel()
) {
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
// FIXME issue happens when this UI is called from WireActivity: WebView is just canceled by itself
LaunchedEffect(Unit) {
viewModel.requestOAuthFlow.onEach {
OAuthUseCase(context, it.target, it.oAuthClaims, it.oAuthState).launch(
context.getActivity()!!.activityResultRegistry, forceLoginFlow = true
) { result -> viewModel.handleOAuthResult(result, it) }
}.launchIn(coroutineScope)
}
LaunchedEffect(Unit) {
viewModel.enrollmentResultFlow.onEach { enrollmentResultHandler(it) }.launchIn(coroutineScope)
}
viewModel.getCertificate(isNewClient)
}