Skip to content

Commit

Permalink
Simplify things
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe committed Oct 27, 2023
1 parent 3709974 commit c2e0754
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,11 @@ import com.stripe.android.financialconnections.model.FinancialConnectionsAccount
import kotlinx.parcelize.Parcelize

internal sealed class USBankAccountFormScreenState(
@StringRes open val error: Int? = null
@StringRes open val error: Int? = null,
open val isProcessing: Boolean = false
) : Parcelable {
abstract val primaryButtonText: String
abstract val mandateText: String?
abstract val isProcessing: Boolean

fun copy(
error: Int? = this.error,
primaryButtonText: String = this.primaryButtonText,
mandateText: String? = this.mandateText,
isProcessing: Boolean = this.isProcessing,
): USBankAccountFormScreenState {
return when (this) {
is BillingDetailsCollection -> {
BillingDetailsCollection(
error = error,
primaryButtonText = primaryButtonText,
isProcessing = isProcessing,
)
}
is MandateCollection -> {
MandateCollection(
paymentAccount = paymentAccount,
financialConnectionsSessionId = financialConnectionsSessionId,
intentId = intentId,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
is VerifyWithMicrodeposits -> {
VerifyWithMicrodeposits(
paymentAccount = paymentAccount,
financialConnectionsSessionId = financialConnectionsSessionId,
intentId = intentId,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
is SavedAccount -> {
SavedAccount(
financialConnectionsSessionId = financialConnectionsSessionId,
intentId = intentId,
bankName = bankName,
last4 = last4,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
}
}

@Parcelize
data class BillingDetailsCollection(
Expand All @@ -77,7 +29,6 @@ internal sealed class USBankAccountFormScreenState(
val paymentAccount: FinancialConnectionsAccount,
val financialConnectionsSessionId: String,
val intentId: String?,
override val isProcessing: Boolean,
override val primaryButtonText: String,
override val mandateText: String?,
) : USBankAccountFormScreenState()
Expand All @@ -87,7 +38,6 @@ internal sealed class USBankAccountFormScreenState(
val paymentAccount: BankAccount,
val financialConnectionsSessionId: String,
val intentId: String?,
override val isProcessing: Boolean,
override val primaryButtonText: String,
override val mandateText: String?,
) : USBankAccountFormScreenState()
Expand All @@ -98,7 +48,6 @@ internal sealed class USBankAccountFormScreenState(
val intentId: String?,
val bankName: String,
val last4: String?,
override val isProcessing: Boolean,
override val primaryButtonText: String,
override val mandateText: String?,
) : USBankAccountFormScreenState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.stripe.android.paymentsheet.addresselement.toIdentifierMap
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.paymentdatacollection.FormArguments
import com.stripe.android.paymentsheet.paymentdatacollection.ach.di.DaggerUSBankAccountFormComponent
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.ui.core.elements.SaveForFutureUseElement
import com.stripe.android.ui.core.elements.SaveForFutureUseSpec
import com.stripe.android.uicore.address.AddressRepository
Expand Down Expand Up @@ -310,7 +309,9 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
fun handlePrimaryButtonClick(screenState: USBankAccountFormScreenState) {
when (screenState) {
is USBankAccountFormScreenState.BillingDetailsCollection -> {
setProcessingState(PrimaryButton.State.StartProcessing)
_currentScreenState.update {
screenState.copy(isProcessing = true)
}
collectBankAccount(args.clientSecret)
}
is USBankAccountFormScreenState.MandateCollection ->
Expand All @@ -337,12 +338,6 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
}
}

private fun setProcessingState(primaryButtonState: PrimaryButton.State) {
_currentScreenState.update {
it.copy(isProcessing = primaryButtonState.isProcessing)
}
}

fun reset(@StringRes error: Int? = null) {
hasLaunched = false
saveForFutureUseElement.controller.onValueChange(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,6 @@ class CustomerSheetViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)
val viewModel = createViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,6 @@ internal class PaymentSheetViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)

Expand Down Expand Up @@ -1534,7 +1533,6 @@ internal class PaymentSheetViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)
viewModel.updateSelection(usBankAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class PaymentSelectionTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class USBankAccountFormViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)
)
Expand Down Expand Up @@ -313,7 +312,6 @@ class USBankAccountFormViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)
)
Expand Down Expand Up @@ -369,7 +367,6 @@ class USBankAccountFormViewModelTest {
),
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
USBankAccountFormScreenState.VerifyWithMicrodeposits(
financialConnectionsSessionId = "session_1234",
Expand All @@ -380,7 +377,6 @@ class USBankAccountFormViewModelTest {
),
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
USBankAccountFormScreenState.SavedAccount(
financialConnectionsSessionId = "session_1234",
Expand All @@ -389,7 +385,6 @@ class USBankAccountFormViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)

Expand Down Expand Up @@ -441,7 +436,6 @@ class USBankAccountFormViewModelTest {
last4 = "6789",
primaryButtonText = "Continue",
mandateText = null,
isProcessing = false,
),
)
)
Expand Down

0 comments on commit c2e0754

Please sign in to comment.