Skip to content

Commit

Permalink
Small reverts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe committed May 3, 2024
1 parent df4a25b commit f5493dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import com.stripe.android.uicore.utils.mapAsStateFlow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -127,7 +129,11 @@ internal class PaymentOptionsViewModel @Inject constructor(
override var newPaymentSelection: PaymentSelection.New? =
args.state.paymentSelection as? PaymentSelection.New

override val primaryButtonUiState = primaryButtonUiStateMapper.forCustomFlow()
override val primaryButtonUiState = primaryButtonUiStateMapper.forCustomFlow().stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = null,
)

init {
SessionSavedStateHandler.attachTo(this, savedStateHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull
Expand Down Expand Up @@ -199,7 +201,11 @@ internal class PaymentSheetViewModel @Inject internal constructor(
}
}

override val primaryButtonUiState = primaryButtonUiStateMapper.forCompleteFlow()
override val primaryButtonUiState = primaryButtonUiStateMapper.forCompleteFlow().stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = null,
)

override val error: StateFlow<String?> = buyButtonState.mapAsStateFlow { it?.errorMessage?.message }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.ui.core.Amount
import com.stripe.android.uicore.utils.combineAsStateFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import com.stripe.android.ui.core.R as StripeUiCoreR

internal class PrimaryButtonUiStateMapper(
Expand All @@ -23,8 +24,8 @@ internal class PrimaryButtonUiStateMapper(
private val onClick: () -> Unit,
) {

fun forCompleteFlow(): StateFlow<PrimaryButton.UIState?> {
return combineAsStateFlow(
fun forCompleteFlow(): Flow<PrimaryButton.UIState?> {
return combine(
currentScreenFlow,
buttonsEnabledFlow,
amountFlow,
Expand All @@ -40,8 +41,8 @@ internal class PrimaryButtonUiStateMapper(
}
}

fun forCustomFlow(): StateFlow<PrimaryButton.UIState?> {
return combineAsStateFlow(
fun forCustomFlow(): Flow<PrimaryButton.UIState?> {
return combine(
currentScreenFlow,
buttonsEnabledFlow,
selectionFlow,
Expand Down

0 comments on commit f5493dc

Please sign in to comment.