Skip to content

chore: don't fire social leaderboard queries while wallet is locked#29567

Merged
zone-live merged 3 commits into
mainfrom
TSA-top-trader-check-if-wallet-is-unlocked
May 4, 2026
Merged

chore: don't fire social leaderboard queries while wallet is locked#29567
zone-live merged 3 commits into
mainfrom
TSA-top-trader-check-if-wallet-is-unlocked

Conversation

@zone-live

@zone-live zone-live commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Description

We had a Sentry error (getBearerToken - unable to proceed, wallet is locked) caused by TanStack Query refetching social leaderboard and trader profile/positions queries while the wallet is locked.

The root cause is that ReactQueryService wires AppState to TanStack's focusManager, so every app foreground triggers a refetch of all stale queries. Since staleTime: 0 is hardcoded in @metamask/react-data-query, all queries are always stale. If the wallet auto-locked while the app was backgrounded, the refetch on foreground hits getBearerToken → #assertIsUnlocked → throws.

To address this we can gate the enabled prop on selectIsUnlocked in the three affected hooks. TanStack fully pauses a query (no refetch interval, no focus refetch, no reconnect refetch) when enabled: false. On wallet unlock, the Redux selector triggers a re-render and the query immediately resumes.

The updated hooks are:

  1. useTopTraders
  2. useTraderProfile
  3. useTraderPositions
    Cached data continues to be shown while locked, so there is no visual regression.

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

Low Risk
Small, localized change to query enabled conditions; main risk is unintentionally suppressing expected refetches when lock state is misreported.

Overview
Prevents social leaderboard-related TanStack queries from firing while the wallet is locked by gating each hook’s useQuery enabled flag on selectIsUnlocked.

This updates useTopTraders, useTraderProfile, useTraderPositions, and useTraderPosition to stop focus/interval refetches during lock, and adjusts unit tests to mock selectIsUnlocked and assert queries are disabled when locked.

Reviewed by Cursor Bugbot for commit 72fcf20. Bugbot is set up for automated code reviews on this repo. 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.

@metamaskbotv2 metamaskbotv2 Bot added the team-social-ai Social & AI team label Apr 30, 2026

@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 3a5f459. Configure here.

Comment thread app/components/Views/Homepage/Sections/TopTraders/hooks/useTopTraders.ts Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.89%. Comparing base (51b6bbd) to head (7dda418).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29567      +/-   ##
==========================================
- Coverage   82.15%   81.89%   -0.26%     
==========================================
  Files        5178     5178              
  Lines      137450   137489      +39     
  Branches    31079    31090      +11     
==========================================
- Hits       112924   112600     -324     
- Misses      16875    17237     +362     
- Partials     7651     7652       +1     

☔ 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.

@zone-live zone-live added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Apr 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are confined to 4 data-fetching hooks in the Social Leaderboard / Top Traders feature area. Each hook received the same minimal fix: adding && isUnlocked to the enabled condition of useQuery calls, preventing API calls when the wallet is locked. This is a correctness/security improvement with no structural changes.

The SocialLeaderboard and TopTraders components are part of the Trending/discovery section of the wallet homepage, which falls under SmokeWalletPlatform (Trending discovery tab, browsing content feeds including Tokens, Perps, Sites sections). No E2E tests exist specifically for the Social Leaderboard feature, so SmokeWalletPlatform is the closest applicable tag to validate the surrounding feature area.

No other tags are warranted: no confirmations, no account management, no network changes, no browser/snap/swap/stake flows are touched. The changes are isolated to hook-level query guards.

Performance Test Selection:
The changes only add a wallet-lock guard to prevent API calls when the wallet is locked. This reduces unnecessary network calls (a minor positive), but does not affect rendering performance, list rendering, animations, or any critical user flow performance metrics. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@zone-live zone-live added this pull request to the merge queue May 4, 2026
Merged via the queue into main with commit 2d09677 May 4, 2026
115 checks passed
@zone-live zone-live deleted the TSA-top-trader-check-if-wallet-is-unlocked branch May 4, 2026 09:21
@github-actions github-actions Bot locked and limited conversation to collaborators May 4, 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 4, 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 skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-social-ai Social & AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants