Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe committed Oct 27, 2023
1 parent 0c6357d commit 6e9642e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ internal sealed class USBankAccountFormScreenState(
abstract val isProcessing: Boolean

fun copy(
error: Int? = null,
primaryButtonText: String? = null,
mandateText: String? = null,
isProcessing: Boolean? = null,
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 ?: this.error,
primaryButtonText = primaryButtonText ?: this.primaryButtonText,
isProcessing = isProcessing ?: this.isProcessing,
error = error,
primaryButtonText = primaryButtonText,
isProcessing = isProcessing,
)
}
is MandateCollection -> {
MandateCollection(
paymentAccount = paymentAccount,
financialConnectionsSessionId = financialConnectionsSessionId,
intentId = intentId,
isProcessing = isProcessing ?: this.isProcessing,
primaryButtonText = primaryButtonText ?: this.primaryButtonText,
mandateText = mandateText ?: this.mandateText,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
is VerifyWithMicrodeposits -> {
VerifyWithMicrodeposits(
paymentAccount = paymentAccount,
financialConnectionsSessionId = financialConnectionsSessionId,
intentId = intentId,
isProcessing = isProcessing ?: this.isProcessing,
primaryButtonText = primaryButtonText ?: this.primaryButtonText,
mandateText = mandateText ?: this.mandateText,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
is SavedAccount -> {
Expand All @@ -53,9 +53,9 @@ internal sealed class USBankAccountFormScreenState(
intentId = intentId,
bankName = bankName,
last4 = last4,
isProcessing = isProcessing ?: this.isProcessing,
primaryButtonText = primaryButtonText ?: this.primaryButtonText,
mandateText = mandateText ?: this.mandateText,
isProcessing = isProcessing,
primaryButtonText = primaryButtonText,
mandateText = mandateText,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
}

fun handlePrimaryButtonClick(screenState: USBankAccountFormScreenState) {
handlePrimaryButtonStateChanged(PrimaryButton.State.StartProcessing)
when (screenState) {
is USBankAccountFormScreenState.BillingDetailsCollection -> {
setProcessingState(PrimaryButton.State.StartProcessing)
collectBankAccount(args.clientSecret)
}
is USBankAccountFormScreenState.MandateCollection ->
Expand All @@ -338,7 +338,7 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
}
}

private fun handlePrimaryButtonStateChanged(primaryButtonState: PrimaryButton.State) {
private fun setProcessingState(primaryButtonState: PrimaryButton.State) {
_currentScreenState.update {
it.copy(isProcessing = primaryButtonState.isProcessing)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class USBankAccountFormViewModelTest {
val currentScreenState = viewModel.currentScreenState.stateIn(viewModel.viewModelScope).value
viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.VerifyWithMicrodeposits)

assertThat(awaitItem().screenState).isEqualTo(currentScreenState.copy(isProcessing = true))
assertThat(awaitItem().screenState).isEqualTo(currentScreenState)
}
}

Expand All @@ -163,7 +163,7 @@ class USBankAccountFormViewModelTest {
val currentScreenState = viewModel.currentScreenState.stateIn(viewModel.viewModelScope).value
viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.MandateCollection)

assertThat(awaitItem().screenState).isEqualTo(currentScreenState.copy(isProcessing = true))
assertThat(awaitItem().screenState).isEqualTo(currentScreenState)
}
}

Expand All @@ -178,7 +178,7 @@ class USBankAccountFormViewModelTest {
val currentScreenState = viewModel.currentScreenState.stateIn(viewModel.viewModelScope).value
viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.VerifyWithMicrodeposits)

assertThat(awaitItem().screenState).isEqualTo(currentScreenState.copy(isProcessing = true))
assertThat(awaitItem().screenState).isEqualTo(currentScreenState)
}
}

Expand All @@ -193,7 +193,7 @@ class USBankAccountFormViewModelTest {
val currentScreenState = viewModel.currentScreenState.stateIn(viewModel.viewModelScope).value
viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.MandateCollection)

assertThat(awaitItem().screenState).isEqualTo(currentScreenState.copy(isProcessing = true))
assertThat(awaitItem().screenState).isEqualTo(currentScreenState)
}
}

Expand Down

0 comments on commit 6e9642e

Please sign in to comment.