Skip to content

Commit

Permalink
Removed Konbini refresh state stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AmniX committed Oct 21, 2024
1 parent 8075a8a commit 6fc44a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import com.komoju.mobile.sdk.entities.PaymentStatus
internal data class KonbiniAwaitingPaymentScreen(val route: KomojuPaymentRoute.KonbiniAwaitingPayment) : Screen {
@Composable
override fun Content() {
val screenModel = rememberScreenModel { KonbiniAwaitingPaymentScreenModel(route.configuration, route.payment) }
val screenModel = rememberScreenModel { KonbiniAwaitingPaymentScreenModel(route.payment) }
val uiState by screenModel.state.collectAsStateWithLifecycle()
RouterEffect(screenModel.router.collectAsStateWithLifecycle(), screenModel::onRouteConsumed)
uiState.payment?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.komoju.android.sdk.ui.screens.awating

import cafe.adriel.voyager.core.model.screenModelScope
import com.komoju.android.sdk.KomojuSDK
import com.komoju.android.sdk.navigation.RouterStateScreenModel
import com.komoju.android.sdk.ui.screens.KomojuPaymentRoute
import com.komoju.android.sdk.ui.screens.Router
import com.komoju.mobile.sdk.entities.Payment
import com.komoju.mobile.sdk.remote.apis.KomojuRemoteApi
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

internal class KonbiniAwaitingPaymentScreenModel(private val config: KomojuSDK.Configuration, private val payment: Payment? = null) :
RouterStateScreenModel<KonbiniAwaitingPaymentUiState>(KonbiniAwaitingPaymentUiState(payment)) {
private val komojuApi = KomojuRemoteApi(config.publishableKey, config.language.languageCode)
internal class KonbiniAwaitingPaymentScreenModel(payment: Payment? = null) :
RouterStateScreenModel<KonbiniAwaitingPaymentUiState>(
KonbiniAwaitingPaymentUiState(payment),
) {

fun onPrimaryButtonClicked() {
when (val payment = state.value.payment) {
Expand All @@ -22,28 +18,6 @@ internal class KonbiniAwaitingPaymentScreenModel(private val config: KomojuSDK.C
}

fun onSecondaryButtonClicked() {
// when (state.value.payment) {
// is Payment.Konbini -> refreshPayment()
// else -> Unit
// }
mutableRouter.value = Router.Pop
}

fun refreshPayment() {
screenModelScope.launch {
val sessionId = config.sessionId ?: return@launch
mutableState.update {
it.copy(isLoading = true)
}
komojuApi.sessions.verifyPaymentBySessionID(sessionId).onSuccess { payment ->
mutableState.update {
it.copy(payment = payment, isLoading = false)
}
}.onFailure {
mutableState.update {
it.copy(isLoading = false)
}
}
}
}
}

0 comments on commit 6fc44a7

Please sign in to comment.