Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PrimaryButtonUiStateMapper to return state flow. #8394

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import com.stripe.android.paymentsheet.viewmodels.PrimaryButtonUiStateMapper
import com.stripe.android.uicore.utils.combineAsStateFlow
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.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down Expand Up @@ -79,7 +79,7 @@ internal class PaymentOptionsViewModel @Inject constructor(
isProcessingPayment = args.state.stripeIntent is PaymentIntent,
currentScreenFlow = currentScreen,
buttonsEnabledFlow = buttonsEnabled,
amountFlow = paymentMethodMetadata.map { it?.amount() },
amountFlow = paymentMethodMetadata.mapAsStateFlow { it?.amount() },
selectionFlow = selection,
customPrimaryButtonUiStateFlow = customPrimaryButtonUiState,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -128,7 +127,7 @@ internal class PaymentSheetViewModel @Inject internal constructor(
isProcessingPayment = isProcessingPaymentIntent,
currentScreenFlow = currentScreen,
buttonsEnabledFlow = buttonsEnabled,
amountFlow = paymentMethodMetadata.map { it?.amount() },
amountFlow = paymentMethodMetadata.mapAsStateFlow { it?.amount() },
selectionFlow = selection,
customPrimaryButtonUiStateFlow = customPrimaryButtonUiState,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import com.stripe.android.paymentsheet.navigation.PaymentSheetScreen
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.ui.core.Amount
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(
private val context: Context,
private val config: PaymentSheet.Configuration,
private val isProcessingPayment: Boolean,
private val currentScreenFlow: Flow<PaymentSheetScreen>,
private val buttonsEnabledFlow: Flow<Boolean>,
private val amountFlow: Flow<Amount?>,
private val selectionFlow: Flow<PaymentSelection?>,
private val customPrimaryButtonUiStateFlow: Flow<PrimaryButton.UIState?>,
private val currentScreenFlow: StateFlow<PaymentSheetScreen>,
private val buttonsEnabledFlow: StateFlow<Boolean>,
private val amountFlow: StateFlow<Amount?>,
private val selectionFlow: StateFlow<PaymentSelection?>,
private val customPrimaryButtonUiStateFlow: StateFlow<PrimaryButton.UIState?>,
private val onClick: () -> Unit,
) {

Expand Down