feat(ramps-controller): add getBestProviderForAsset accessor#9029
Open
amitabh94 wants to merge 5 commits into
Open
feat(ramps-controller): add getBestProviderForAsset accessor#9029amitabh94 wants to merge 5 commits into
amitabh94 wants to merge 5 commits into
Conversation
…m quote resolution
…rAsset Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@metamaskbot publish-preview |
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.
Reviewed by Cursor Bugbot for commit d04a0a1. Configure here.
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
…iderForAsset selected-step The selected-provider branch returned state.providers.selected, whose region-specific fields (e.g. limits) may describe a different region than the one resolved here (notably under a region override). Return the matching entry from the region-resolved supporting list instead. Quote path unaffected (uses only .id). Adds a region-override regression test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
…sort Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
amitabh94
added a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Jun 6, 2026
This was referenced Jun 6, 2026
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
Adds a read-only way to resolve the best on-ramp provider for an asset, reusing the provider-selection cascade
RampsControlleralready implements internally. MetaMask Pay's money-account fiat deposit (and later Unified Buy v2) needs a provider's static buy limits (provider.limits) to validate the user-entered amount before spending a network quote — which requires knowing which provider. This accessor returns that provider using the controller's own ordering, so the limit check and the eventual quote agree.Changes
Refactor (no behavior change). The provider-pick cascade (currently-selected → previously-used from order history → native/Transak → first supporting) was extracted from the private quote-resolution method into a shared private helper
#resolveBestSupportingProvider. The existing#resolveProviderIdsForQuotenow delegates to it, preserving its exact list-level behavior (including therestrictToKnownOrNativegating). All pre-existing tests pass unchanged.New public accessor.
RampsController.getBestProviderForAsset({ assetId, region? })(async) + theRampsController:getBestProviderForAssetmessenger action. It resolves the region fromuserRegion(GeolocationController-derived), filters to providers supporting the asset, runs the shared cascade, and returns the bestProvider(ornull). Read-only — it never mutatesproviders.selected/providerAutoSelected/ any state.Deliberately no
getBestQuote— the existinggetQuotesis already provider-scoped (viapreferredProviderIds/restrictToKnownOrNativeProviders). No other controller is touched.References
Consumer (mobile): MetaMask Pay money-account fiat deposit amount-limit validation.
Checklist
🤖 Generated with Claude Code
Note
Medium Risk
Refactors
getQuotesauto-selection internals; behavior is intended to be preserved but touches headless gating and region-scoped provider resolution.Overview
Adds a read-only
getBestProviderForAsset({ assetId, region? })API (plusRampsController:getBestProviderForAsset) so callers can resolve which on-rampProviderwould be used for an asset—e.g. to readprovider.limitsbefore quoting—using the same cascade as quote auto-selection, without changingproviders.selectedor other state.The shared selection logic is extracted into private
#resolveBestSupportingProvider(selected → order-history preferred → native → first supporting).#resolveProviderIdsForQuotenow delegates to that helper while keeping list-level behavior, includingrestrictToKnownOrNativeProvidersgating. When the selected provider wins, the helper returns the region-resolved entry from the supporting list (not the possibly stalestate.providers.selectedobject), including under an explicitregionoverride.Messenger action types, package exports, changelog, and focused tests cover null cases, messenger wiring, no state mutation, and region override behavior.
Reviewed by Cursor Bugbot for commit 3e9ef3c. Bugbot is set up for automated code reviews on this repo. Configure here.