Skip to content

Conversation

@matallui
Copy link
Contributor

@matallui matallui commented Nov 10, 2025

Description

This PR improves error handling in the Predict feature's placeOrder method by refactoring the control flow to fail fast and ensuring analytics tracking is consistent across both success and error paths.

Reason for change: The previous implementation had nested success/failure logic that made the code harder to follow and potentially allowed analytics events to be tracked incorrectly in edge cases.

Improvement:

  • Refactored to throw immediately on failure, simplifying the control flow
  • Moved analytics failure tracking to the catch block where it belongs
  • Added support for detecting "unable to access this provider" error messages as eligibility errors in the Polymarket provider

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Predict order placement error handling

  Scenario: user places an order that fails
    Given user is on the Predict screen with a valid market

    When user attempts to place an order that fails (e.g., region restriction)
    Then the appropriate error message is displayed
    And analytics failure event is tracked correctly

  Scenario: user places a successful order
    Given user is on the Predict screen with a valid market

    When user places a valid order
    Then the order completes successfully
    And analytics completion event is tracked with correct amounts
    And user balance is optimistically updated

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

Refactors placeOrder to fail fast with unified success/failed analytics and optimistic balance updates; adds detection of "unable to access this provider" as an eligibility error in Polymarket.

  • PredictController (PredictController.ts):
    • placeOrder: Fail-fast on unsuccessful provider response; centralizes COMPLETED tracking after result parsing and moves FAILED tracking to catch block; keeps optimistic balance updates and real share price/amount derivation.
  • PolymarketProvider (PolymarketProvider.ts):
    • placeOrder: Treats errors containing "unable to access this provider" (in addition to region block) as NOT_ELIGIBLE.

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

@github-actions
Copy link
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.

@metamaskbot metamaskbot added the team-predict Predict team label Nov 10, 2025
@matallui matallui requested review from caieu and kevinbluer November 10, 2025 18:42
@matallui matallui marked this pull request as ready for review November 10, 2025 18:42
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@matallui matallui added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Nov 10, 2025
Copy link
Contributor

@caieu caieu left a comment

Choose a reason for hiding this comment

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

LGTM

@matallui matallui added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 5138211 Nov 10, 2025
166 of 171 checks passed
@matallui matallui deleted the predict/order-error-handling branch November 10, 2025 20:38
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2025
@metamaskbot metamaskbot added the release-7.60.0 Issue or pull request that will be included in release 7.60.0 label Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.60.0 Issue or pull request that will be included in release 7.60.0 size-M skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants