Skip to content

fix(rewards): patch invalidateSubscriptionCache#30279

Open
sophieqgu wants to merge 1 commit into
mainfrom
Invalidate-cache-patch
Open

fix(rewards): patch invalidateSubscriptionCache#30279
sophieqgu wants to merge 1 commit into
mainfrom
Invalidate-cache-patch

Conversation

@sophieqgu
Copy link
Copy Markdown
Contributor

@sophieqgu sophieqgu commented May 15, 2026

Description

  • Refactors invalidateSubscriptionCache to take an options object: { subscriptionId, seasonId?, campaignId? }.
  • Adds centralized cache-key helpers for season/subscription and subscription/campaign composite keys, replacing hardcoded ${subscriptionId}:${campaignId} usage.
  • Makes cache invalidation more scoped:
    -- subscriptionId + seasonId: season-scoped caches only.
    -- subscriptionId + campaignId: campaign-scoped caches only.
    -- subscriptionId only: all subscription-related rewards API caches.
  • Keeps invalidateSubscriptionAndAccounts focused on subscription/account auth state: removes subscription metadata, resets linked account state and active account, removes token, but does not clear vipDashboard.
  • Narrows claim reward and bonus code handling to invalidate points-events cache only, instead of clearing broad subscription caches.
  • Updates logout, auth retry, account linking, opt-out, balance update, and campaign opt-in call sites to use the new invalidation API.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

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

Medium Risk
Changes cache invalidation semantics in RewardsController, including new season/campaign scoping and narrower invalidations after reward claims/bonus codes, which could leave stale UI data or trigger extra refetches if callers rely on prior broad clears.

Overview
Refactors RewardsController.invalidateSubscriptionCache to accept an options object ({ subscriptionId, seasonId?, campaignId? }) and centralizes composite-key generation/matching so invalidation can be targeted to season-scoped vs campaign-scoped caches, plus subscription-keyed caches (e.g. benefits/VIP/off-device accounts) only when doing a full subscription clear.

Separates responsibilities between auth/account reset and cache clearing: invalidateSubscriptionAndAccounts now removes subscription metadata, resets linked account state, and removes the session token without clearing rewards API caches like vipDashboard, while logout, optOut, account linking flows, auth-retry, and balance update paths are updated to use the new invalidation API.

Narrows post-mutation invalidation: claimReward and applyBonusCode now invalidate only pointsEvents for the subscription (with updated logging), and the test suite is updated/expanded to reflect the new scoping rules and typed cache-key deletion behavior.

Reviewed by Cursor Bugbot for commit 79d25a2. 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 15, 2026 20:28
@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.

@metamaskbotv2 metamaskbotv2 Bot added the team-rewards Rewards team label May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations, SmokePredictions, SmokeSwap
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 78%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR refactors the RewardsController's invalidateSubscriptionCache method from positional arguments to an options object pattern, and significantly changes the cache invalidation behavior:

  1. Signature change: invalidateSubscriptionCache(subscriptionId, seasonId?)invalidateSubscriptionCache({ subscriptionId, seasonId?, campaignId? }) - all internal call sites updated
  2. Behavioral change: invalidateSubscriptionAndAccounts no longer clears vipDashboard (that responsibility moved to invalidateSubscriptionCache)
  3. New surgical invalidation: #invalidatePointsEventsCache for claim/bonus code flows that only clears points events, not all caches
  4. New campaignId scoping: Cache invalidation can now be scoped to specific campaigns

The RewardsController manages state for:

  • Perps trading (campaign leaderboards, portfolio, participant status) → SmokePerps
  • Predictions/Ondo campaigns (leaderboard positions, portfolio, activity) → SmokePredictions
  • Swap rewards (points events, season statuses) → SmokeSwap
  • VIP dashboard (subscription benefits, fees) → SmokeWalletPlatform (Trending section)
  • Confirmations are part of Perps, Predictions, and Swap flows → SmokeConfirmations

The cache invalidation changes could affect data freshness after user actions (claiming rewards, applying bonus codes, opting into campaigns, logging out). If cache is not properly invalidated, stale data could be shown in the UI. E2E tests for these flows should verify the behavior is correct end-to-end.

Per tag descriptions: SmokePerps requires SmokeWalletPlatform and SmokeConfirmations; SmokePredictions requires SmokeWalletPlatform and SmokeConfirmations; SmokeSwap requires SmokeConfirmations.

Performance Test Selection:
The changes are internal cache invalidation logic refactoring within the RewardsController. While cache management can affect data loading performance, these changes are about correctness of cache invalidation (what gets cleared and when), not rendering performance, list rendering, or app startup. No UI components, list rendering, or critical performance paths are modified. Performance tests are not warranted for this type of internal controller refactoring.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant