Skip to content

Commit

Permalink
separate selectedOption and onOptionSelected to fix bug with stripe l…
Browse files Browse the repository at this point in the history
…ink cards not selecting (#2058)
  • Loading branch information
mtgriego authored Jun 18, 2024
1 parent 01caceb commit 8a6729f
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ fun CheckoutScreen(
onDisclaimerItemClicked: (disclaimerItem: DisclaimerItems) -> Unit,
onAccountabilityLinkClicked: () -> Unit
) {
var (selectedOption, onOptionSelected) = remember {
val selectedOption = remember {
mutableStateOf(
storedCards.firstOrNull {
project.acceptedCardType(it.type()) || it.isFromPaymentSheet()
}
)
}

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)

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -338,7 +342,7 @@ fun CheckoutScreen(
) {

KSRadioButton(
selected = card == selectedOption,
selected = card == selectedOption.value,
onClick = { onOptionSelected(card) },
enabled = isAvailable
)
Expand Down

0 comments on commit 8a6729f

Please sign in to comment.