feat(ramps): adds an agnostic selector for ramps request metadata #7554
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 a new
createRequestSelectorutility function to the@metamask/ramps-controllerpackage. This utility enables consumers to create memoized selectors for tracking request states (loading, error, data) from RampsController methods.Current state: Consumers who want to track request states from RampsController methods (like
updateGeolocation,getCryptoCurrencies, etc.) need to manually create selectors that extract and transform the request cache state. This can lead to:Solution: The
createRequestSelectorfunction provides a standardized, optimized way to create selectors for request states. It:shallowEqualis needed with React Redux'suseSelectorImplementation details: The selector memoizes by comparing the request object reference. When the controller updates state, if it preserves the request object reference (typical in immutable state management), the selector returns the cached result. This avoids expensive deep equality checks while maintaining correctness.
References
example usage: This selector is being used in this metamask mobile pull request
Checklist
Note
Introduces a memoized selector utility for RampsController request states.
selectors.tswithcreateRequestSelectorandRequestSelectorResultfor efficientdata/isFetching/errorselection using cache keyscreateRequestSelectorandRequestSelectorResultviasrc/index.tsselectors.test.tscovering loading/success/error states, memoization stability, state transitions, and cache key isolationCHANGELOG.mdunder Unreleased to document the new utilityWritten by Cursor Bugbot for commit 93f3172. This will update automatically on new commits. Configure here.