feat(ramps-controller): public getSmartSelectedQuote + validateBuyAmount; scope-gate widening#9414
Draft
saustrie-consensys wants to merge 3 commits into
Conversation
…unt; scope-gate widening Promote the private in-app pick to a public pure getSmartSelectedQuote in a new quoteSelection module, ranking preferredProviderIds -> reliability -> price -> first and reusing the shared isInAppOnlyQuote filter. Extract the limit-fit check as public validateBuyAmount/fitsProviderLimits. Make #pickInAppQuote a thin wrapper that feeds the controller-owned order-history preference into the shared pick. Groundwork for retiring the native-only scaffolding: derive getQuotes' widening from provider-class scope and mark restrictToKnownOrNativeProviders @deprecated while still honoring it (OR-ed in) so existing callers are unaffected. scope: 'off' stays native-only.
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. |
…tion to the param A block-level @deprecated tag in the getQuotes JSDoc marked the whole method deprecated (TSDoc has no per-param deprecation), flagging every getQuotes caller. Move the deprecation note into the param description prose instead.
Contributor
Author
|
@metamaskbot publish-preview |
10 tasks
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Contributor
Author
|
@metamaskbot publish-preview |
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
Headless Buy "All Providers Support" Phase 2 core follow-on, stacked on #9409 (base branch
saustrie/ramps-controller-ui-logic, notmain).Today the widened in-app quote pick lives in the private
RampsController#pickInAppQuote, reachable only through theautoSelectProvider/restrictToKnownOrNativeProviderspath that MM Pay'sgetRampsQuoteuses. The mobile headlessgetQuotesfacade does not trigger it, so selection is forked and the headless UI re-derives ordering. This PR promotes that logic to a public, pure, provider-agnostic module so both callers pick identically, and lays the non-breaking groundwork for retiring the Money V0 native-only scaffolding (P2.M6 + the non-breaking part of P2.M8).What changed:
quoteSelection.tsmodule exporting:getSmartSelectedQuote(response, { scope, amount, fiat, providers, preferredProviderIds? })- the promoted body of#pickInAppQuote, rankingpreferredProviderIds -> reliability -> price -> first. It reuses the feat(ramps-controller): share provider/quote/error helpers with consumers #9409isInAppOnlyQuoteclassification for the in-app filter (drops external-browser and custom-action quotes underin-app/off, keeps them underall) and enforces per-provider fiat limits up front.validateBuyAmount({ amount, limit })andfitsProviderLimits(quote, { amount, fiat, providers })- the limit-fit check extracted from the inlined#pickInAppQuotelogic, plus aBuyAmountValidationresult type.#pickInAppQuoteis now a thin wrapper overgetSmartSelectedQuote, feeding it the controller-owned order-history preference (#getPreferredProviderIdsFromOrders) as the top ranking rung. A returning user's previously-used provider now wins over the reliability/price winner on the widened pick.getQuotesnow derives provider-widening from thegetProviderScopescope (off= native-only kill switch;in-app/all= widen, then rank), re-keying the widening gate and the empty-response guard off scope.restrictToKnownOrNativeProvidersis marked@deprecatedin JSDoc but is still honored (OR-ed into the auto-select path) so existing callers (TPCgetRampsQuote) are unaffected.scope: 'off'stays native-only. The option is not removed (that is a later breaking change).All new logic is pure and provider-agnostic; deeplink schemes, redirect/callback URLs, navigation, and error taxonomy stay in the mobile consumer.
Tests: new
quoteSelection.test.ts(ranking with/withoutpreferredProviderIds, in-app filter under each scope,allscope, limit bounds,validateBuyAmount/fitsProviderLimits) plus newRampsController.test.tscases (order-history preference on the widened pick,scope: 'off'still native-only with the deprecated flag, deprecated flag alone still honored). Full package suite green (612 tests), typecheck and lint clean.References
providerAvailability/quoteClassification/errorNormalizationhelpers this builds on).getSmartSelectedQuote+validateBuyAmount) and the non-breaking part of P2.M8 (scope-gated widening; deprecaterestrictToKnownOrNativeProviders).Checklist
Made with Cursor