Skip to content

fix(Rewards): error when visiting rewards tab cp-7.76.0#29823

Merged
Montoya merged 2 commits into
mainfrom
RWDS-1267-error-when-visiting-rewards-tab
May 7, 2026
Merged

fix(Rewards): error when visiting rewards tab cp-7.76.0#29823
Montoya merged 2 commits into
mainfrom
RWDS-1267-error-when-visiting-rewards-tab

Conversation

@sophieqgu

@sophieqgu sophieqgu commented May 6, 2026

Copy link
Copy Markdown
Contributor

Description

https://consensyssoftware.atlassian.net/browse/RWDS-1267
The Rewards crash likely came from an older persisted Rewards Redux state that did not have newer array fields, especially campaigns. On affected devices, selectCampaigns could return undefined.

It was account/device dependent because persisted state differs per user/install.

Fix Applied: hardened both the restore path and selector path to fallback to initial state (empty array or object instead of undefined)

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/RWDS-1267

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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: changes are defensive fallbacks for missing/undefined persisted state and selector inputs, with added tests; behavior should only differ for legacy/partial states.

Overview
Prevents Rewards tab crashes caused by older/partial persisted Redux/controller state by defaulting missing fields to safe empty values.

Selectors and rehydrate logic now coalesce undefined arrays/objects (e.g., campaigns, season arrays, benefits, dismissed-toasts map, controller accounts/subscriptions) to empty defaults, and RewardsController default state was extracted into defaultState.ts and reused. Test coverage was expanded to lock in these upgrade/undefined-state behaviors.

Reviewed by Cursor Bugbot for commit d7b351d. Bugbot is set up for automated code reviews on this repo. Configure here.

@sophieqgu sophieqgu requested a review from a team as a code owner May 6, 2026 20:14
@github-actions

github-actions Bot commented May 6, 2026

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.

@metamaskbotv2 metamaskbotv2 Bot added the team-rewards Rewards team label May 6, 2026
@github-actions github-actions Bot added the size-M label May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
This PR makes purely defensive coding improvements to the Rewards system:

  1. Refactoring only: getRewardsControllerDefaultState and defaultRewardsControllerState are moved from RewardsController.ts to a new defaultState.ts file. The exported API is unchanged (re-exported from the original location), so no consumers are broken.

  2. Null-coalescing guards: Added ?? [] and ?? {} fallbacks in reducers and selectors to handle missing persisted state fields during app upgrades. This is purely defensive - when state is properly initialized (as it always is in E2E tests), behavior is identical.

  3. No UI changes: No components, screens, navigation, or user-facing flows are modified.

  4. No shared infrastructure changes: TabBar, Browser, Confirmations, Modals, and other shared components are untouched.

  5. Test files only add unit tests: The test file changes add unit tests for the new null-safety behaviors - no E2E test infrastructure is modified.

The changes are scoped entirely to the Rewards controller state management layer with defensive null-coalescing. E2E tests for Perps (SmokePerps), Predictions (SmokePredictions), or WalletPlatform (SmokeWalletPlatform) would not be meaningfully validated by these changes since the null-safety guards only activate when state fields are absent (which doesn't happen in normal E2E test flows). Running no E2E tags is appropriate here as the risk is low and the changes are purely internal defensive improvements covered by unit tests.

Performance Test Selection:
The changes are purely defensive null-coalescing improvements to state selectors and reducers. No UI rendering, list components, data loading patterns, or critical user flows are modified. No performance impact is expected.

View GitHub Actions results

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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.

Reviewed by Cursor Bugbot for commit d7b351d. Configure here.

Comment thread app/reducers/rewards/index.test.ts
@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown

@sophieqgu sophieqgu changed the title fix(Rewards): error when visiting rewards tab cp-7.76.0 fix(Rewards): error when visiting rewards tab May 6, 2026

@Montoya Montoya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Tested and confirmed no issues.

@Montoya Montoya added this pull request to the merge queue May 7, 2026
@Montoya Montoya changed the title fix(Rewards): error when visiting rewards tab fix(Rewards): error when visiting rewards tab cp-7.76.0 May 7, 2026
Merged via the queue into main with commit 8208502 May 7, 2026
86 checks passed
@Montoya Montoya deleted the RWDS-1267-error-when-visiting-rewards-tab branch May 7, 2026 01:43
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-M team-rewards Rewards team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants