Skip to content

fix: only fire APP_OPENED on background → active transition#27463

Open
vinnyhoward wants to merge 10 commits intomainfrom
fix-tmcu-256-inaccurate-app-opens-qr-scanner
Open

fix: only fire APP_OPENED on background → active transition#27463
vinnyhoward wants to merge 10 commits intomainfrom
fix-tmcu-256-inaccurate-app-opens-qr-scanner

Conversation

@vinnyhoward
Copy link
Copy Markdown
Contributor

@vinnyhoward vinnyhoward commented Mar 13, 2026

Description

When the QR scanner on iPhone prompts the user to grant camera access, iOS transitions the app to inactive (not background). If the user taps "Cancel" on the permission dialog, the app returns to active, which was incorrectly triggering the App Opened analytics event.

The fix tightens the condition in AppStateEventListener to only fire APP_OPENED when transitioning from background → active, which represents the user genuinely re-opening the app. Transitions from inactive → active (system dialogs, incoming calls, etc.) are now correctly ignored.

Changelog

CHANGELOG entry:null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TMCU-256

Manual testing steps

Feature: App Opened analytics event

  Scenario: user dismisses camera permission dialog from QR scanner
    Given the user has not granted camera access to MetaMask
    And the user is on any screen in the app

    When user taps the QR scanner icon
    And the iOS camera permission dialog appears
    And user taps "Cancel" on the dialog

    Then the App Opened analytics event is NOT fired

  Scenario: user opens the app from the background
    Given the user has backgrounded the app

    When user returns to the app from the app switcher or home screen

    Then the App Opened analytics event IS fired

Screenshots/Recordings

Screen.Recording.2026-03-30.at.11.08.20.AM.mov

Before

Observe that the app opened event fires after pressing cancel

Screen.Recording.2026-03-30.at.11.08.20.AM.mov

After

Observe that the app opened event does not fire after pressing cancel

Screen.Recording.2026-03-30.at.11.22.19.AM.mov

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

Low Risk
Low risk: narrows when the APP_OPENED analytics event is emitted and adds targeted tests, with no changes to auth, funds, or persistence logic.

Overview
Prevents false-positive APP_OPENED analytics by only triggering the event when the app transitions from background to active, ignoring inactive → active transitions (e.g., iOS permission dialogs/calls).

Updates app-state tracking to preserve background across the iOS intermediate inactive state so the subsequent active transition still counts as an app open. Tests are adjusted to include explicit background setup and new cases covering background → inactive → active, repeated active, and inactive → active not firing.

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

@github-actions
Copy link
Copy Markdown
Contributor

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-mobile-ux Mobile UX team label Mar 13, 2026
@github-actions github-actions bot added the risk-low Low testing needed · Low bug introduction risk label Mar 30, 2026
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.

@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 30, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 30, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.64%. Comparing base (e2bb36a) to head (a5410aa).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #27463    +/-   ##
========================================
  Coverage   82.63%   82.64%            
========================================
  Files        4854     4859     +5     
  Lines      125092   125393   +301     
  Branches    27919    28069   +150     
========================================
+ Hits       103376   103637   +261     
+ Misses      14600    14594     -6     
- Partials     7116     7162    +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 2, 2026
@github-actions github-actions bot added risk-low Low testing needed · Low bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Apr 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are a targeted bug fix in AppStateEventListener.ts that corrects when the APP_OPENED analytics event fires:

  1. Before: APP_OPENED fired on any transition to 'active' state (including from 'inactive', e.g., when dismissing system permission dialogs)
  2. After: APP_OPENED only fires when transitioning from 'background' to 'active', with special iOS handling to preserve 'background' state through the intermediate 'inactive' state

Why no E2E tags are needed:

  • This is a pure analytics/event-firing fix with no UI changes
  • No navigation, controller, or user-facing flow changes
  • The core deeplink processing behavior is preserved (still fires when returning from background)
  • The fix makes behavior more correct by eliminating false positive APP_OPENED events
  • Comprehensive unit tests cover all the new scenarios (iOS background→inactive→active, system dialog inactive→active)
  • The change is isolated to AppStateEventListener.ts which handles app state transitions internally
  • No shared components (TabBar, Modals, Confirmations, Browser) are affected

Risk assessment: Low - well-tested unit-level fix that corrects analytics event firing logic without changing any user-visible behavior or E2E-testable flows.

Performance Test Selection:
The change only affects when the APP_OPENED analytics event fires (state transition logic). It does not impact UI rendering, data loading, account/network lists, critical user flows, or app startup performance. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-low Low testing needed · Low bug introduction risk size-S team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants