feat: add status tracking to RampsController ResourceState#8116
Open
feat: add status tracking to RampsController ResourceState#8116
Conversation
Add explicit status field to ResourceState to distinguish between uninitialized and empty-fetched states. The default idle/loading/success/error statuses are now tracked per resource and set explicitly via #setResourceStatus during fetch cycles in executeRequest. This eliminates ambiguity when determining if a resource has been fetched vs is still in its initial state, fixing false positive "token unavailable" errors in mobile when payment methods are actually still loading.
7 tasks
AxelGes
added a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Mar 4, 2026
…ble errors Replace local ref-based loading tracking with paymentMethodsStatus from RampsController. The controller now exposes explicit 'idle'/'loading'/'success'/'error' status per resource, eliminating the need for component-level workarounds. Changes: - Expose status from useRampsPaymentMethods and thread through useRampsController - Replace hasSeenLoadingRef/prevProviderIdRef/prevSettledAssetIdRef with direct paymentMethodsStatus === RequestStatus.SUCCESS check - Add migration 124 to backfill status: 'idle' on persisted RampsController state - Make selectors tolerant of missing status field for backward compatibility - Update all tests to mock paymentMethodsStatus Depends on: MetaMask/core#8116
- Add missing status field reset in resetResource function to fix bugbot issue - Update test helpers (createResourceState, createDefaultResourceState) to include status field - Add createMockProvider helper to generate complete Provider objects with all required fields - Fix test mocks to use proper Provider type instead of partial objects - Update changelog with new status field feature
- Extend #updateResourceField to accept 'status' field, removing the duplicate update logic in #setResourceStatus - Move SUCCESS/ERROR status transitions to the finally block behind the same ref-count guard (next === 0) used by isLoading, so status and isLoading never disagree during concurrent requests
… branch coverage BuyWidget.url is typed as string (non-optional), so the ?? null was dead code that prevented 100% branch coverage.
…idle inconsistency When isResultCurrent() returns false, terminalStatus was never assigned, leaving status stuck at 'loading' while isLoading was set back to false. Fall back to RequestStatus.IDLE so the two fields always stay in sync.
There was a problem hiding this comment.
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.
…nsistent states Replace separate #setResourceLoading and #setResourceStatus calls with a single #setResourceLoadingAndStatus that writes both fields inside one this.update() call, so subscribers never observe a snapshot where isLoading and status disagree.
Contributor
Author
|
@metamaskbot release-preview |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
This PR adds explicit status tracking to the
ResourceStatetype in@metamask/ramps-controller. Previously, the controller used onlyisLoadinganderrorfields, making it impossible to distinguish between:This ambiguity caused false positive "token unavailable" errors in MetaMask Mobile when payment methods were still loading.
Changes
RampsController.ts
status: \${RequestStatus}`field toResourceState` typecreateDefaultResourceStateto initialize withstatus: RequestStatus.IDLE#setResourceStatusmethod to update resource statusexecuteRequest:loadingwhen fetch startssuccesswhen fetch completes successfullyerrorwhen fetch failsThe status field uses the existing
RequestStatusenum fromRequestCache.ts('idle' | 'loading' | 'success' | 'error'), already exported in the package's public API.References
Checklist
Note
Medium Risk
Adds a new
statusfield to the controller’s persisted/observableResourceStateshape and wires it intoexecuteRequest, which can affect any consumers that assume onlyisLoading/errorsemantics. Also changesgetWidgetUrl()to return the service URL verbatim (including empty string) rather than coercing falsy values tonull.Overview
Adds explicit fetch status to
ResourceState. All resource slices now includestatus(idle/loading/success/error) to distinguish never fetched from fetched empty, and defaults/reset logic is updated accordingly.Wires status transitions into request execution.
executeRequestnow updates resourceisLoadingandstatusatomically (with ref-counted pending requests) and sets terminal status on success/error.Behavior tweak:
getWidgetUrl()now returnsbuyWidget.urlas-is (e.g., empty string), and tests/snapshots are updated to reflect the new state shape and mock provider construction.Written by Cursor Bugbot for commit 9351996. This will update automatically on new commits. Configure here.