Skip to content

Conversation

@caieu
Copy link
Contributor

@caieu caieu commented Nov 11, 2025

Description

Changes the auto-refresh behavior in usePredictOrderPreview from interval-based
to sequential pattern. The timer now waits for the preview response before
starting the timeout countdown, preventing overlapping requests.

Key changes:

  • Replace setInterval with recursive setTimeout pattern
  • Add scheduleNextRefresh function to trigger after response
  • Schedule next refresh after both successful and error responses
  • Clear pending timers on unmount and parameter changes
  • Update tests to verify sequential refresh behavior

This ensures the autoRefreshTimeout is a delay AFTER each response
completes, rather than a fixed interval that could cause overlapping
requests when API response times exceed the timeout value.

Changelog

CHANGELOG entry: null

Related issues

Fixes: PRED-299

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

Replaces interval-based auto-refresh with response-triggered sequential timeouts in usePredictOrderPreview, adds cleanup on param changes/unmount, and updates tests accordingly.

  • Hook usePredictOrderPreview:
    • Replace setInterval auto-refresh with sequential setTimeout scheduled via scheduleNextRefresh after each response (success or error).
    • Introduce refs for timer and callbacks: refreshTimerRef, calculatePreviewRef, scheduleNextRefreshRef.
    • Clear pending refresh timers on unmount and when parameters change; debounce initial calculation.
    • Minor safety: optional chaining on calculatePreviewRef.current?.().
  • Tests usePredictOrderPreview.test.ts:
    • Rename and add cases to verify response-triggered scheduling, waiting before countdown, scheduling after errors, and clearing timers on parameter changes and unmount.

Written by Cursor Bugbot for commit 2c9fb28. 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 11, 2025
@caieu caieu marked this pull request as ready for review November 11, 2025 19:47
@sonarqubecloud
Copy link

@caieu caieu enabled auto-merge November 11, 2025 22:57
@caieu caieu added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit d4803d4 Nov 11, 2025
138 of 141 checks passed
@caieu caieu deleted the chore/predict-fix-buy-refetch branch November 11, 2025 23:42
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2025
@metamaskbot metamaskbot added the release-7.60.0 Issue or pull request that will be included in release 7.60.0 label Nov 11, 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 team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants