Skip to content

fix(deposit): hydrate provider token on Deposit root entry cp-7.72.0#28288

Merged
wachunei merged 2 commits intomainfrom
fix/deposit-root-auth-token-hydration
Apr 1, 2026
Merged

fix(deposit): hydrate provider token on Deposit root entry cp-7.72.0#28288
wachunei merged 2 commits intomainfrom
fix/deposit-root-auth-token-hydration

Conversation

@wachunei
Copy link
Copy Markdown
Member

@wachunei wachunei commented Apr 1, 2026

Description

Deposit Root previously called checkExistingToken() only when a fiat order in CREATED state existed in Redux. If the user had completed Verify / Email / OTP and stored a provider token, then closed Deposit and reopened it without an in-progress CREATED order, the vault was never read and isAuthenticated stayed false—so Build Quote sent them through the login flow again.

This change always runs checkExistingToken() (with the existing timeout) before branching to Build Quote, Enter Email, or Bank Details, so the stored token hydrates the SDK on every Deposit entry. initializeFlow is reorganized to match that order (guard → default auth → attempt vault read → finally mark token check complete → branch on createdOrder).

Changelog

CHANGELOG entry: Fixed Deposit prompting for login again after closing and reopening the flow when a stored session was still valid.

Related issues

Fixes:

Manual testing steps

Feature: Deposit session persists after closing and reopening

  Scenario: Continue deposit without repeating Verify / Email / OTP
    Given the user completed Deposit authentication (Verify, Email, OTP) and has a valid stored provider token
    And there is no in-progress deposit order in CREATED state
    When the user closes the Deposit flow and opens Deposit again
    And the user enters an amount and taps Continue on Build Quote
    Then the user is not sent to Verify / Email / OTP again
    And the post-quote flow proceeds as an authenticated user

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Changes Deposit root initialization to always attempt stored-token hydration and to gate navigation decisions on that result, which can affect authentication and routing behavior. Adds re-entrancy guards to avoid duplicate async initialization, reducing race-condition risk but making flow control more complex.

Overview
Ensures Deposit Root always runs checkExistingToken() (with timeout/error handling) on entry before deciding whether to route to Build Quote, Enter Email, or Bank Details, fixing cases where users were re-prompted to authenticate despite a valid stored provider token.

Reworks initialization flow to be idempotent and single-flight via hasCheckedToken plus a new initializationInFlight guard, and updates the Root test to assert token hydration occurs even when there is no CREATED order before redirecting to BUILD_QUOTE.

Written by Cursor Bugbot for commit 513271a. This will update automatically on new commits. Configure here.

Always run checkExistingToken before branching so stored auth is restored
when reopening Deposit without a CREATED order. Reorganize initializeFlow
for clarity. Update Root tests.
@wachunei wachunei self-assigned this Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-money-movement issues related to Money Movement features label Apr 1, 2026
@github-actions github-actions bot added the size-S label Apr 1, 2026
@wachunei wachunei marked this pull request as ready for review April 1, 2026 19:56
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Prevent duplicate checkExistingToken and navigation when the effect
re-runs while the async token check is in flight (e.g. orders update).
initializationInFlight is set synchronously; hasCheckedToken remains
set after the token attempt completes.
@github-actions github-actions bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk and removed size-S labels Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeRamps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are scoped to app/components/UI/Ramp/Deposit/Views/Root/Root.tsx and its test file. The modification fixes a race condition in the Deposit flow initialization:

  1. Race condition fix: Adds initializationInFlight ref to prevent duplicate checkExistingToken calls when the effect re-runs while the async operation is in flight.
  2. Logic reorder: Previously, the code would skip checkExistingToken entirely when no created order existed (navigating to default route immediately). Now, checkExistingToken is always called first to hydrate the SDK/vault, and THEN the routing decision is made based on whether a created order exists.
  3. Test update: Reflects the new behavior - checkExistingToken is now always called, even when no created order exists.

This is a behavioral change in the Deposit/Ramp flow initialization that could affect how users enter the deposit flow. The SmokeRamps tag covers fiat on-ramp/off-ramp features and is the appropriate tag to validate this change. No other features are impacted - the change is entirely contained within the Deposit Root component.

Performance Test Selection:
The changes are limited to initialization logic using React refs (no rendering changes, no list components, no state management changes that would affect performance). The fix prevents duplicate async calls which could marginally improve performance, but no performance test coverage is needed for this type of change.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@wachunei wachunei changed the title fix(deposit): hydrate provider token on Deposit root entry fix(deposit): hydrate provider token on Deposit root entry cp-7.72.0 Apr 1, 2026
@wachunei wachunei added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit c2942e0 Apr 1, 2026
95 checks passed
@wachunei wachunei deleted the fix/deposit-root-auth-token-hydration branch April 1, 2026 21:21
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2026
@metamaskbot metamaskbot added the release-7.73.0 Issue or pull request that will be included in release 7.73.0 label Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.73.0 Issue or pull request that will be included in release 7.73.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-money-movement issues related to Money Movement features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants