From 8a6729f90230ac95da591e6936d9db79770760ae Mon Sep 17 00:00:00 2001 From: mtgriego Date: Tue, 18 Jun 2024 09:39:07 -0700 Subject: [PATCH] separate selectedOption and onOptionSelected to fix bug with stripe link cards not selecting (#2058) --- .../activities/compose/projectpage/CheckoutScreen.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt index f2fd63c9f1..ac291b2b80 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt @@ -142,7 +142,7 @@ fun CheckoutScreen( onDisclaimerItemClicked: (disclaimerItem: DisclaimerItems) -> Unit, onAccountabilityLinkClicked: () -> Unit ) { - var (selectedOption, onOptionSelected) = remember { + val selectedOption = remember { mutableStateOf( storedCards.firstOrNull { project.acceptedCardType(it.type()) || it.isFromPaymentSheet() @@ -150,6 +150,10 @@ fun CheckoutScreen( ) } + val onOptionSelected: (StoredCard?) -> Unit = { + selectedOption.value = it + } + // - After adding new payment method, selected card should be updated to the newly added UpdateSelectedCardIfNewCardAdded(remember { mutableStateOf(storedCards.size) }, storedCards, onOptionSelected) @@ -189,8 +193,8 @@ fun CheckoutScreen( modifier = Modifier .padding(bottom = dimensions.paddingMediumSmall) .fillMaxWidth(), - onClickAction = { onPledgeCtaClicked(selectedOption) }, - isEnabled = project.acceptedCardType(selectedOption?.type()) || selectedOption?.isFromPaymentSheet() ?: false, + onClickAction = { onPledgeCtaClicked(selectedOption.value) }, + isEnabled = project.acceptedCardType(selectedOption.value?.type()) || selectedOption.value?.isFromPaymentSheet() ?: false, text = if (pledgeReason == PledgeReason.PLEDGE) stringResource(id = R.string.Pledge) else stringResource( id = R.string.Confirm ) @@ -338,7 +342,7 @@ fun CheckoutScreen( ) { KSRadioButton( - selected = card == selectedOption, + selected = card == selectedOption.value, onClick = { onOptionSelected(card) }, enabled = isAvailable )