feat(ramps): refactor RampsControllerState to use nested objects for each resource type#7779
feat(ramps): refactor RampsControllerState to use nested objects for each resource type#7779
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| state.selectedPaymentMethod = null; | ||
| state.providers.selected = null; | ||
| state.paymentMethods.data = []; | ||
| state.paymentMethods.selected = null; |
There was a problem hiding this comment.
Stale error/loading state when provider/token selection changes
Medium Severity
When setSelectedProvider or setSelectedToken is called, paymentMethods.data and paymentMethods.selected are reset but paymentMethods.isLoading and paymentMethods.error are not. This differs from resetDependentResources which properly resets all four fields. When clearing selection (passing null/undefined), stale error or loading states persist indefinitely since no new request is triggered. When setting a new selection, the UI briefly shows both isLoading: true AND the previous error simultaneously until the new request completes.
Additional Locations (2)
amitabh94
left a comment
There was a problem hiding this comment.
Left a comment for more explanation. Approving to unblock.
| * When provided, resource-level error is only set/cleared if this returns true. | ||
| * Used to avoid applying stale errors after e.g. region or selection changes. | ||
| */ | ||
| isResultCurrent?: () => boolean; |
There was a problem hiding this comment.
Cam you explain how this would be used ?
…ethod - Fix #quotePollingOptions being cleared immediately after being set, which prevented polling restart when dependencies changed - Remove unused #setUserRegionRefetchCount variable - Restore breaking change entry in CHANGELOG from #7779 - Add destroy() method for proper cleanup of polling interval
…ethod - Fix #quotePollingOptions being cleared immediately after being set, which prevented polling restart when dependencies changed - Remove unused #setUserRegionRefetchCount variable - Restore breaking change entry in CHANGELOG from #7779 - Add destroy() method for proper cleanup of polling interval
…ethod - Fix #quotePollingOptions being cleared immediately after being set, which prevented polling restart when dependencies changed - Remove unused #setUserRegionRefetchCount variable - Restore breaking change entry in CHANGELOG from #7779 - Add destroy() method for proper cleanup of polling interval
…ethod - Fix #quotePollingOptions being cleared immediately after being set, which prevented polling restart when dependencies changed - Remove unused #setUserRegionRefetchCount variable - Restore breaking change entry in CHANGELOG from #7779 - Add destroy() method for proper cleanup of polling interval
…ethod - Fix #quotePollingOptions being cleared immediately after being set, which prevented polling restart when dependencies changed - Remove unused #setUserRegionRefetchCount variable - Restore breaking change entry in CHANGELOG from #7779 - Add destroy() method for proper cleanup of polling interval


Explanation
RampsControllerStateto use nestedResourceStateobjects for each resource type:userRegion,countries,providers,tokens,paymentMethods, andquotesdata,selected,isLoading, anderrorproperties in a single objectfetchUserRegion) from hooks - the controller now manages fetching internallyselected*properties (e.g.,selectedProvider) - these are now nested within each resourceThis eliminates the need for consumers to reconstruct cache keys to check loading/error states, and provides a consistent, unified structure for accessing resource data and metadata.
Before
After
New State Structure
Breaking Changes
data,selected,isLoading, anderrorselectedProvider,selectedToken,selectedPaymentMethoduserRegionLoading,userRegionError, etc.References
Mobile PR to adopt breaking change: MetaMask/metamask-mobile#25414
Checklist
Note
Medium Risk
Medium risk due to a breaking state-shape change and updated async fetching/loading/error semantics that can affect consumers and race-condition behavior.
Overview
Breaking: Refactors
RampsControllerStateso each resource (countries,providers,tokens,paymentMethods,quotes) is a nestedResourceStatewithdata,selected,isLoading, anderror, removing the flatselected*fields.Updates request execution to track per-resource loading/error (with in-flight ref-counting and staleness guards via
isResultCurrent) and replaces the oldtrigger*fire-and-forget APIs with internal#fireAndForgetusage. ExportsResourceType/ResourceStateand addsRAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONSplus tests to ensure messenger delegation and new concurrency/error behaviors.Written by Cursor Bugbot for commit 2aeb120. This will update automatically on new commits. Configure here.