Skip to content

Commit

Permalink
Fix navigation issue in Link account picker (#10029)
Browse files Browse the repository at this point in the history
* Fix navigation issue in Link account picker

* Add unit test
  • Loading branch information
tillh-stripe authored Jan 29, 2025
1 parent 36d226c commit 1b6fa8e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ internal class LinkAccountPickerViewModel @AssistedInject constructor(
selectedAccountIds = accountIds,
consentAcquired = acquireConsentOnPrimaryCtaClick,
)
val nextPane = response.nextPane ?: SUCCESS

FinancialConnections.emitEvent(name = Name.ACCOUNTS_SELECTED)
navigationManager.tryNavigateTo(
(response.nextPane ?: SUCCESS).destination(referrer = PANE)
)
navigationManager.tryNavigateTo(nextPane.destination(referrer = PANE))
}

private suspend fun handleNonSuccessNextPane(payload: LinkAccountPickerState.Payload, nextPane: Pane?) {
Expand Down Expand Up @@ -313,9 +313,22 @@ internal class LinkAccountPickerViewModel @AssistedInject constructor(
// Nothing to log here
}
}
if (payload.acquireConsentOnPrimaryCtaClick) acceptConsent()
// Fall back to the institution picker
val destination = nextPane?.destination?.invoke(referrer = PANE) ?: InstitutionPicker(referrer = PANE)

if (payload.acquireConsentOnPrimaryCtaClick) {
acceptConsent()
}

val overrideNextPane = when (nextPane) {
PARTNER_AUTH,
BANK_AUTH_REPAIR -> {
// We don't support these panes here.
INSTITUTION_PICKER
}
null -> INSTITUTION_PICKER
else -> nextPane
}

val destination = overrideNextPane.destination(referrer = PANE)
navigationManager.tryNavigateTo(destination)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,35 @@ class LinkAccountPickerViewModelTest {
)
}

@Test
fun `onSelectAccountsClick - falls back to institution picker if next pane isn't supported`() = runTest {
val accounts = NetworkedAccountsList(
acquireConsentOnPrimaryCtaClick = false,
data = listOf(
partnerAccount().copy(id = "id1", nextPaneOnSelection = Pane.PARTNER_AUTH)
),
display = display(
listOf(
NetworkedAccount(id = "id1", allowSelection = true)
)
)
)
val selectedAccount = accounts.data.first()
whenever(getSync()).thenReturn(syncResponse())
whenever(fetchNetworkedAccounts(any())).thenReturn(accounts)

val viewModel = buildViewModel(LinkAccountPickerState())

viewModel.onAccountClick(selectedAccount)
viewModel.onSelectAccountsClick()

navigationManager.assertNavigatedTo(
destination = Pane.INSTITUTION_PICKER.destination,
pane = Pane.LINK_ACCOUNT_PICKER,
popUpTo = null,
)
}

@Test
fun `onAccountClick - do not present drawer on click if acquireConsentOnCta is true`() = runTest {
val accounts = NetworkedAccountsList(
Expand Down

0 comments on commit 1b6fa8e

Please sign in to comment.