Skip to content

fix(rewards): remove client cache for Ondo portfolio positions#29868

Merged
sophieqgu merged 1 commit into
mainfrom
rwds-ondo-perps-positions-cache-timeout
May 7, 2026
Merged

fix(rewards): remove client cache for Ondo portfolio positions#29868
sophieqgu merged 1 commit into
mainfrom
rwds-ondo-perps-positions-cache-timeout

Conversation

@VGR-GIT

@VGR-GIT VGR-GIT commented May 7, 2026

Copy link
Copy Markdown
Contributor

Description

After a rebalance, the Ondo positions list could remain stale for up to 60 seconds while the activity list (which is not cached on the client) showed the up-to-date trade. Both views read the same upstream data, so the divergence was purely a client-side cache artifact in RewardsController.getOndoCampaignPortfolioPosition.

This PR sets ONDO_CAMPAIGN_PORTFOLIO_POSITION_CACHE_THRESHOLD_MS to 0, which makes wrapWithCache always treat the entry as stale and fetch fresh from the API. The mirrored Redux state (state.ondoCampaignPortfolio[…]) is still written on each fetch, so selectors continue to render the latest snapshot — only the staleness window is removed.

Agreed on the approach with @jonathan.deyoung and @christian.montoya in this Slack thread; flagged as a quick win for today's RC. Jonathan's call: low-risk because traffic to this endpoint is low and hits read-only servers, and the longer-term fix (timestamp-aligning positions and activity, à la S1) is parked as Perps follow-up work.

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A — driven by Slack thread linked above.

Manual testing steps

Feature: Ondo positions stay in sync with activity after a rebalance

  Scenario: user rebalances and immediately reopens the campaign details
    Given the user has an active Ondo GM portfolio with at least one position
    When the user performs a rebalance (e.g. swap GE for MSFT)
    And the user navigates back into the Ondo campaign details screen within 60s
    Then the positions list reflects the post-rebalance holdings (MSFT present, GE absent)
    And the positions list matches the activity list

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

Note

Medium Risk
Disables several short-lived client caches, increasing request frequency for authenticated rewards endpoints; main risk is performance/network impact and potential rate-limiting, not data integrity.

Overview
Removes the client-side TTL for several rewards “live snapshot” reads by setting their cache thresholds to 0, forcing fresh API fetches while still mirroring responses into controller state for selectors.

This applies to Ondo leaderboard position, Ondo portfolio position, Ondo first-page activity, and Perps trading leaderboard position, and updates unit tests and generated action-type docs to reflect the new always-fresh behavior (including re-fetching even when a recent not-found sentinel exists).

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

@metamaskbotv2 metamaskbotv2 Bot added the team-rewards Rewards team label May 7, 2026
@github-actions

github-actions Bot commented May 7, 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.

@github-actions github-actions Bot added the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label May 7, 2026
@metamaskbotv2 metamaskbotv2 Bot added the INVALID-PR-TEMPLATE PR's body doesn't match template label May 7, 2026
@github-actions github-actions Bot added the size-S label May 7, 2026
Disables the client-side cache (sets TTL to 0 in wrapWithCache) for
the user-facing campaign endpoints whose freshness was visibly lagging
behind activity:

- ONDO_CAMPAIGN_PORTFOLIO_POSITION_CACHE_THRESHOLD_MS
- ONDO_CAMPAIGN_LEADERBOARD_POSITION_CACHE_THRESHOLD_MS
- ONDO_CAMPAIGN_ACTIVITY_CACHE_THRESHOLD_MS
- PERPS_TRADING_CAMPAIGN_LEADERBOARD_POSITION_CACHE_THRESHOLD_MS

Selectors continue to read from the mirrored Redux state, which is
still written on every fetch. Per agreement on Slack for today's RC.

Co-authored-by: VGR-GIT <vangulckrik@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@VGR-GIT VGR-GIT force-pushed the rwds-ondo-perps-positions-cache-timeout branch from c9444c4 to e77be61 Compare May 7, 2026 16:27
@VGR-GIT VGR-GIT marked this pull request as ready for review May 7, 2026 16:28
@VGR-GIT VGR-GIT requested a review from a team as a code owner May 7, 2026 16:28
@github-actions github-actions Bot added size-M and removed size-S labels May 7, 2026
@sophieqgu sophieqgu removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label May 7, 2026
@sophieqgu sophieqgu enabled auto-merge May 7, 2026 17:13
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 82%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes disable caching (set TTL to 0) for four specific RewardsController data endpoints: Ondo campaign leaderboard positions, Ondo campaign portfolio positions, Ondo campaign activity, and Perps trading campaign leaderboard positions. These were previously cached for 1-5 minutes and now always fetch fresh from the API.

Impact analysis:

  1. The RewardsController is primarily consumed by Perps UI components (usePerpsCloseAllCalculations, usePerpsOrderFees, usePerpsRewardAccountOptedIn, mobileInfrastructure adapter) and Rewards hooks (useGetOndoLeaderboardPosition, useGetOndoCampaignActivity, useGetPerpsTradingCampaignLeaderboardPosition).
  2. The changes affect data freshness for Perps trading features - leaderboard positions and portfolio data will now always be fetched fresh, keeping user ranks in sync with latest trades.
  3. No structural API changes - only caching behavior changed, so no breaking changes to consumers.
  4. The test file updates confirm the behavioral change: tests that previously expected cached results now expect fresh API calls.

Tag selection rationale:

  • SmokePerps: Directly affected - Perps trading campaign leaderboard position caching is disabled, impacting Perps trading features
  • SmokeWalletPlatform: Required per SmokePerps tag description (Perps is a section inside Trending tab)
  • SmokeConfirmations: Required per SmokePerps tag description (Add Funds deposits are on-chain transactions)

The changes are scoped to cache TTL constants and don't affect Engine initialization, other controllers, or navigation infrastructure, so broader test coverage is not warranted.

Performance Test Selection:
Disabling cache TTLs for Perps trading campaign leaderboard positions means every data fetch will now hit the API instead of returning cached results. This could impact the performance of Perps market loading and position management flows, as more network requests will be made. The @PerformancePreps tag covers perps market loading, position management, add funds flow, and order execution - all of which could be affected by increased API call frequency due to disabled caching.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

@sophieqgu sophieqgu added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit f2d69c4 May 7, 2026
223 of 226 checks passed
@sophieqgu sophieqgu deleted the rwds-ondo-perps-positions-cache-timeout branch May 7, 2026 18:42
@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

INVALID-PR-TEMPLATE PR's body doesn't match template 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