Skip to content

Commit

Permalink
Fix issue where multiple accounts are selected for single select (#4187)
Browse files Browse the repository at this point in the history
## Summary

This fixes an issue in the account picker pane where multiple account
could be selected when both `skipAccountSelection` and
`manifest.singleAccount` is `true`. Instead, we select the first
selectable account.

## Motivation

Fixes bug reported by Doordash.

## Testing

Manual testing via latest Testflight build on this branch.
@carlosmuvi-stripe confirmed this fixes the issue!

## Changelog

N/a
  • Loading branch information
mats-stripe authored Nov 1, 2024
1 parent 235d85d commit 1869bbe
Showing 1 changed file with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,21 @@ final class AccountPickerViewController: UIViewController {
// AND `authSession.skipAccountSelection` is true
let skipAccountSelection = (accountsPayload.skipAccountSelection ?? self.dataSource.authSession.skipAccountSelection ?? false)
if skipAccountSelection {
self.dataSource.updateSelectedAccounts(accounts)
let selectableAccounts = accounts.filter(\.allowSelectionNonOptional)
if self.dataSource.manifest.singleAccount {
if let firstEnabledAccount = selectableAccounts.first {
self.dataSource.updateSelectedAccounts([firstEnabledAccount])
} else {
self.showNoEligibleAccountsErrorView(
numberOfIneligibleAccounts: accounts.count,
error: FinancialConnectionsSheetError.unknown(
debugDescription: "No eligible accounts found"
)
)
}
} else {
self.dataSource.updateSelectedAccounts(selectableAccounts)
}
self.didSelectLinkAccounts(isSkipAccountSelection: true)
} else if
self.dataSource.manifest.singleAccount,
Expand Down Expand Up @@ -228,26 +242,10 @@ final class AccountPickerViewController: UIViewController {
// show "AccountLoadErrorView."
numberOfIneligibleAccounts > 0
{
let errorView = AccountPickerNoAccountEligibleErrorView(
institution: self.dataSource.institution,
bussinessName: self.businessName,
institutionSkipAccountSelection: self.dataSource.authSession.institutionSkipAccountSelection
?? false,
self.showNoEligibleAccountsErrorView(
numberOfIneligibleAccounts: numberOfIneligibleAccounts,
paymentMethodType: self.dataSource.manifest.paymentMethodType ?? .usBankAccount,
theme: self.dataSource.manifest.theme,
didSelectAnotherBank: self.didSelectAnotherBank
error: error
)
// the user will never enter this instance of `AccountPickerViewController`
// again...they can only choose manual entry or go through "ResetFlow"
self.showErrorView(errorView)
self.dataSource
.analyticsClient
.logExpectedError(
error,
errorName: "AccountNoneEligibleForPaymentMethodError",
pane: .accountPicker
)
} else {
// if we didn't get that specific error back, we don't know what's wrong. could the be
// aggregator, could be Stripe.
Expand All @@ -258,6 +256,29 @@ final class AccountPickerViewController: UIViewController {
}
}

private func showNoEligibleAccountsErrorView(numberOfIneligibleAccounts: Int, error: Error) {
let errorView = AccountPickerNoAccountEligibleErrorView(
institution: self.dataSource.institution,
bussinessName: self.businessName,
institutionSkipAccountSelection: self.dataSource.authSession.institutionSkipAccountSelection
?? false,
numberOfIneligibleAccounts: numberOfIneligibleAccounts,
paymentMethodType: self.dataSource.manifest.paymentMethodType ?? .usBankAccount,
theme: self.dataSource.manifest.theme,
didSelectAnotherBank: self.didSelectAnotherBank
)
// the user will never enter this instance of `AccountPickerViewController`
// again...they can only choose manual entry or go through "ResetFlow"
self.showErrorView(errorView)
self.dataSource
.analyticsClient
.logExpectedError(
error,
errorName: "AccountNoneEligibleForPaymentMethodError",
pane: .accountPicker
)
}

private func displayAccounts(
_ enabledAccounts: [FinancialConnectionsPartnerAccount],
_ disabledAccounts: [FinancialConnectionsPartnerAccount]
Expand Down

0 comments on commit 1869bbe

Please sign in to comment.