Skip to content

fix(predict): prevent duplicate Predict claim requests during pending state#27133

Merged
matallui merged 12 commits into
mainfrom
predict/fix-multiple-claim
Mar 9, 2026
Merged

fix(predict): prevent duplicate Predict claim requests during pending state#27133
matallui merged 12 commits into
mainfrom
predict/fix-multiple-claim

Conversation

@caieu
Copy link
Copy Markdown
Contributor

@caieu caieu commented Mar 6, 2026

Description

Summary

  • Add isClaimPending state to usePredictClaim to prevent concurrent claim executions from repeated taps.
  • Early-return from claim() when a claim is already in flight, and always reset pending state in a finally block.
  • Keep retry behavior intact while making retry invocation explicit with void claim().

Tests

  • Extend usePredictClaim tests to validate pending-state behavior:
    • initializes with isClaimPending = false
    • sets pending while claim starts
    • ignores a second claim() call while pending
    • resets pending after success
    • resets pending after failure
  • Wrap async claim actions with act(...) to ensure stable React state assertions in hook tests.

Why

Repeated taps on Predict claim could trigger multiple confirmation flows. This change enforces a single in-flight claim request and avoids duplicate claim confirmations.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/PRED-739

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

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
Touches claim/transaction flow by adding per-account pending-claim tracking in PredictController and wiring it through UI/hook logic; bugs here could block or duplicate user claim attempts despite added tests.

Overview
Prevents duplicate claim submissions by adding non-persisted pendingClaims state to PredictController, short-circuiting claimWithConfirmation when a claim is already in flight, and clearing pending state on errors and on terminal transaction status updates.

Propagates claim-pending state to the UI via a new selectPredictPendingClaimByAddress selector and usePredictClaim.isClaimPending, showing an “in progress” toast on repeat taps and rendering claim buttons in a disabled loading state (spinner + new predict.claiming_text), including privacy-mode hiding of amounts.

Refactors market/positions claim CTAs to reuse PredictClaimButton and threads isClaimPending through PredictActionButtons, game details, sport card footer, and market details actions, with updated/added tests covering the new behavior and edge cases.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

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-predict Predict team label Mar 6, 2026
@github-actions github-actions Bot added the size-M label Mar 6, 2026
@caieu caieu marked this pull request as ready for review March 6, 2026 15:49
@caieu caieu requested a review from a team as a code owner March 6, 2026 15:49
Comment thread app/components/UI/Predict/hooks/usePredictClaim.ts
Comment thread app/components/UI/Predict/hooks/usePredictClaim.test.ts
@github-actions github-actions Bot added size-L and removed size-M labels Mar 9, 2026
Copy link
Copy Markdown
Contributor

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

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/components/UI/Predict/controllers/PredictController.ts Outdated
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.40741% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.23%. Comparing base (43e62f8) to head (b125661).
⚠️ Report is 84 commits behind head on main.

Files with missing lines Patch % Lines
...onents/UI/Predict/controllers/PredictController.ts 0.00% 22 Missing ⚠️
...ents/PredictActionButtons/PredictActionButtons.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #27133       +/-   ##
===========================================
- Coverage   81.52%   71.23%   -10.30%     
===========================================
  Files        4626     4658       +32     
  Lines      121238   121982      +744     
  Branches    26642    26819      +177     
===========================================
- Hits        98845    86892    -11953     
- Misses      15446    28544    +13098     
+ Partials     6947     6546      -401     

☔ 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 size-XL and removed size-L labels Mar 9, 2026
Comment thread app/components/UI/Predict/hooks/usePredictClaim.ts
Comment thread app/components/UI/Predict/controllers/PredictController.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeTrade, SmokeWalletPlatform, SmokeCard, SmokePerps, SmokeRamps, SmokeMultiChainAPI, SmokePredictions, FlaskBuildTests
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: %
click to see 🤖 AI reasoning details

E2E Test Selection:
Fallback: AI analysis did not complete successfully. Running all tests.

Performance Test Selection:
Fallback: AI analysis did not complete successfully. Running all performance tests.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 9, 2026

@matallui matallui enabled auto-merge March 9, 2026 22:07
@matallui matallui added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit b063652 Mar 9, 2026
195 of 198 checks passed
@matallui matallui deleted the predict/fix-multiple-claim branch March 9, 2026 22:46
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 9, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 size-XL team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants