Repository navigation
chore(runway): cherry-pick feat(predict): cp-7.60.2 add auto-refresh polling when country is missing - #23518
Conversation
…polling when country is missing (#23513) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Add automatic polling mechanism to usePredictEligibility hook that refreshes eligibility when no country is returned in the response. Changes: - Add sequential polling pattern (wait for response → wait interval → poll again) - Poll every 2 seconds until country is returned or component unmounts - Continue polling even if individual requests fail - Stop polling automatically when country becomes available - Add comprehensive tests for the new polling behavior This ensures users get their country data even if the initial eligibility check doesn't return it, improving the reliability of the Predict feature's geo-restriction handling. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin 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** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds sequential auto-refresh polling to `usePredictEligibility` when `country` is missing, reduces debounce to 100ms, and updates tests accordingly. > > - **Predict Eligibility Hook (`usePredictEligibility`)**: > - Adds sequential auto-refresh polling when `eligibility[providerId].country` is missing. > - Polls every `2000ms` up to `3` retries; stops on country availability or unmount; logs failures and retry limits. > - Introduces `useRef` to stabilize `refreshEligibility` in effects. > - Reduces debounce interval to `100ms` for automatic refreshes. > - **Tests (`usePredictEligibility.test.ts`)**: > - Update debounce expectations to `100ms` and related timings. > - Add comprehensive tests for missing-country polling: start/interval, max retries, error handling, cleanup on unmount, and sequential polling behavior. > - Ensure scenarios for app state transitions, race prevention, manual refresh, and error logging reflect new timings and polling logic. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9ad7a9c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
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. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsFallback: AI analysis did not complete successfully. Running all tests. |
|
|
||
| // Minimum time between automatic eligibility refreshes (1 minute) | ||
| const DEBOUNCE_INTERVAL_MS = 60000; | ||
| const DEBOUNCE_INTERVAL_MS = 100; |
There was a problem hiding this comment.
Bug: Debounce interval reduced from 1 minute to 100ms
The DEBOUNCE_INTERVAL_MS constant was changed from 60000 (1 minute) to 100 (100 milliseconds), while the comment on line 18 still says "Minimum time between automatic eligibility refreshes (1 minute)". This mismatch indicates the production value was accidentally reduced to accommodate test timing. With a 100ms debounce instead of 60 seconds, eligibility API calls could occur 600x more frequently than intended when the app transitions between foreground states, potentially causing unnecessary API load, rate limiting issues, and degraded mobile performance.
|
|
No release label on PR. Adding release label release-7.60.2 on PR, as PR was cherry-picked in branch 7.60.2. |



Description
Add automatic polling mechanism to usePredictEligibility hook that
refreshes eligibility when no country is returned in the response.
Changes:
poll again)
This ensures users get their country data even if the initial
eligibility check doesn't return it, improving the reliability
of the Predict feature's geo-restriction handling.
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Adds sequential auto-refresh polling to
usePredictEligibilitywhencountryis missing (2s interval, 3 retries) and reduces auto-refresh debounce to 100ms, with comprehensive tests.usePredictEligibility):countryis missing: wait for response → wait2000ms→ retry, up to3retries.refreshEligibilityin auseRefto avoid effect restarts.countryvia memoized selector and uses it to control polling.60000msto100ms.usePredictEligibility.test.ts):100ms.Written by Cursor Bugbot for commit 831dd0e. This will update automatically on new commits. Configure here.
a9cb801