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 )