Skip to content

Commit

Permalink
Add more reliable bank label rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Nov 12, 2024
1 parent eeaa86a commit 4876c86
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ internal data class BankFormScreenState(
val financialConnectionsSessionId: String?,
val mandateText: ResolvableString,
val isVerifyingWithMicrodeposits: Boolean,
) : Parcelable
) : Parcelable {

val label: String
get() = buildString {
bankName?.let { append("$it ") }
append("••••")
last4?.let { append(" $it") }
}
}

sealed interface ResultIdentifier : Parcelable {
@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ internal fun BankAccountForm(
isProcessing = state.isProcessing,
bankName = linkedBankAccount.bankName,
last4 = linkedBankAccount.last4,
label = linkedBankAccount.label,
saveForFutureUseElement = saveForFutureUseElement,
onRemoveAccount = onRemoveAccount,
)
Expand Down Expand Up @@ -336,6 +337,7 @@ private fun AccountDetailsForm(
isProcessing: Boolean,
bankName: String?,
last4: String?,
label: String,
saveForFutureUseElement: SaveForFutureUseElement,
onRemoveAccount: () -> Unit,
) {
Expand Down Expand Up @@ -375,7 +377,7 @@ private fun AccountDetailsForm(
)

Text(
text = "$bankName •••• $last4",
text = label,
modifier = Modifier.alpha(if (isProcessing) 0.5f else 1f),
color = MaterialTheme.stripeColors.onComponent,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,79 @@ internal class AccountPreviewScreenshotTest {
}
}

@Test
fun testWithMissingLast4() {
paparazzi.snapshot {
BankAccountForm(
state = BankFormScreenStateFactory.createWithSession(
sessionId = "session_1234",
last4 = null,
),
instantDebits = false,
isPaymentFlow = true,
formArgs = formArguments,
nameController = createNameController(),
emailController = createEmailController(),
phoneController = createPhoneNumberController(),
addressController = createAddressController(),
sameAsShippingElement = sameAsShippingElement,
saveForFutureUseElement = saveForFutureUseElement,
showCheckbox = false,
lastTextFieldIdentifier = null,
onRemoveAccount = {},
)
}
}

@Test
fun testWithMissingBankName() {
paparazzi.snapshot {
BankAccountForm(
state = BankFormScreenStateFactory.createWithSession(
sessionId = "session_1234",
bankName = null,
),
instantDebits = false,
isPaymentFlow = true,
formArgs = formArguments,
nameController = createNameController(),
emailController = createEmailController(),
phoneController = createPhoneNumberController(),
addressController = createAddressController(),
sameAsShippingElement = sameAsShippingElement,
saveForFutureUseElement = saveForFutureUseElement,
showCheckbox = false,
lastTextFieldIdentifier = null,
onRemoveAccount = {},
)
}
}

@Test
fun testWithMissingBankNameAndLast4() {
paparazzi.snapshot {
BankAccountForm(
state = BankFormScreenStateFactory.createWithSession(
sessionId = "session_1234",
bankName = null,
last4 = null,
),
instantDebits = false,
isPaymentFlow = true,
formArgs = formArguments,
nameController = createNameController(),
emailController = createEmailController(),
phoneController = createPhoneNumberController(),
addressController = createAddressController(),
sameAsShippingElement = sameAsShippingElement,
saveForFutureUseElement = saveForFutureUseElement,
showCheckbox = false,
lastTextFieldIdentifier = null,
onRemoveAccount = {},
)
}
}

private fun createNameController(): TextFieldController {
return NameConfig.createController("John Doe")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ internal object BankFormScreenStateFactory {
sessionId: String,
isVerifyingWithMicrodeposits: Boolean = false,
mandateText: ResolvableString = "Some legal text".resolvableString,
bankName: String? = "Stripe Bank",
last4: String? = "6789",
): BankFormScreenState {
return create(
resultIdentifier = BankFormScreenState.ResultIdentifier.Session(sessionId),
isVerifyingWithMicrodeposits = isVerifyingWithMicrodeposits,
mandateText = mandateText,
bankName = bankName,
last4 = last4,
)
}

Expand All @@ -28,21 +32,25 @@ internal object BankFormScreenStateFactory {
resultIdentifier = BankFormScreenState.ResultIdentifier.PaymentMethod(paymentMethod),
isVerifyingWithMicrodeposits = isVerifyingWithMicrodeposits,
mandateText = mandateText,
bankName = "Stripe Bank",
last4 = "6789",
)
}

private fun create(
resultIdentifier: BankFormScreenState.ResultIdentifier,
isVerifyingWithMicrodeposits: Boolean,
mandateText: ResolvableString,
bankName: String?,
last4: String?,
): BankFormScreenState {
return BankFormScreenState(
linkedBankAccount = BankFormScreenState.LinkedBankAccount(
resultIdentifier = resultIdentifier,
financialConnectionsSessionId = "session_1234",
intentId = "intent_1234",
bankName = "Stripe Bank",
last4 = "6789",
bankName = bankName,
last4 = last4,
mandateText = mandateText,
isVerifyingWithMicrodeposits = isVerifyingWithMicrodeposits,
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4876c86

Please sign in to comment.