-
-
Notifications
You must be signed in to change notification settings - Fork 283
feat(transaction-pay-controller): surface fiat ramps quote error as fiatPayment.quoteError #9030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ogp/fiat-money-account-deposit-fix
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import { projectLogger } from '../../logger'; | |
| import type { | ||
| PayStrategyGetQuotesRequest, | ||
| QuoteRequest, | ||
| TransactionFiatPayment, | ||
| TransactionFiatQuoteError, | ||
| TransactionPayRequiredToken, | ||
| TransactionPayQuote, | ||
| } from '../../types'; | ||
|
|
@@ -127,8 +129,9 @@ export async function getFiatQuotes( | |
| }); | ||
|
|
||
| messenger.call('TransactionPayController:updateFiatPayment', { | ||
| callback: (fiatPayment) => { | ||
| callback: (fiatPayment: TransactionFiatPayment) => { | ||
| fiatPayment.rampsQuote = fiatQuote; | ||
| fiatPayment.quoteError = undefined; | ||
| }, | ||
| transactionId, | ||
| }); | ||
|
|
@@ -143,6 +146,17 @@ export async function getFiatQuotes( | |
| ]; | ||
| } catch (error) { | ||
| log('Failed to fetch fiat quotes', { error, transactionId }); | ||
|
|
||
| const quoteError = isRampsQuoteError(error) | ||
| ? error.quoteError | ||
| : { code: 'QUOTE_FAILED' as const }; | ||
|
|
||
| messenger.call('TransactionPayController:updateFiatPayment', { | ||
| callback: (fiatPayment: TransactionFiatPayment) => { | ||
| fiatPayment.quoteError = quoteError; | ||
| }, | ||
| transactionId, | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quoteError set for non-ramps failuresMedium Severity The shared Reviewed by Cursor Bugbot for commit 86a299a. Configure here. |
||
| } | ||
|
|
||
| return []; | ||
|
|
@@ -173,7 +187,12 @@ async function getRampsQuote({ | |
| autoSelectProvider: true, | ||
| fiat: DEFAULT_FIAT_CURRENCY, | ||
| paymentMethods: [fiatPaymentMethod], | ||
| restrictToKnownOrNativeProviders: true, | ||
| // Do not restrict to native-only providers — the fiat strategy is used for | ||
| // moneyAccountDeposit which may be served by aggregator providers (e.g. | ||
| // onramp.money in regions where Transak is unavailable). The gate | ||
| // (RampsController:getBestProviderForAsset) already verified that a | ||
| // supporting provider exists for the asset in the user's region. | ||
| restrictToKnownOrNativeProviders: false, | ||
| walletAddress, | ||
| }); | ||
|
|
||
|
|
@@ -184,12 +203,59 @@ async function getRampsQuote({ | |
| const quote = quotes.success?.[0]; | ||
|
|
||
| if (!quote) { | ||
| throw new Error('No matching ramps quote found for selected provider'); | ||
| const errorEntry = quotes.error?.[0]; | ||
| const message = errorEntry?.error; | ||
| const code = classifyRampsError(message); | ||
|
|
||
| const err = new Error('No matching ramps quote found for selected provider') as Error & { | ||
| quoteError: TransactionFiatQuoteError; | ||
| }; | ||
| err.quoteError = { code, message }; | ||
| throw err; | ||
| } | ||
|
|
||
| return quote; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the thrown value is an Error with an attached `quoteError` | ||
| * property produced by {@link getRampsQuote}. | ||
| * | ||
| * @param error - The caught value to inspect. | ||
| * @returns Whether the error carries structured ramps quote error metadata. | ||
| */ | ||
| function isRampsQuoteError( | ||
| error: unknown, | ||
| ): error is Error & { quoteError: TransactionFiatQuoteError } { | ||
| return ( | ||
| error instanceof Error && | ||
| 'quoteError' in error && | ||
| error.quoteError !== null && | ||
| typeof error.quoteError === 'object' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Classifies a provider error message into a structured error code. | ||
| * Messages that mention purchase/transaction limits are classified as | ||
| * `LIMIT_EXCEEDED`; all other failures fall back to `QUOTE_FAILED`. | ||
| * | ||
| * @param message - The raw error string from the provider, if any. | ||
| * @returns The error code to surface in `TransactionFiatPayment.quoteError`. | ||
| */ | ||
| function classifyRampsError( | ||
| message: string | undefined, | ||
| ): TransactionFiatQuoteError['code'] { | ||
| if ( | ||
| message && | ||
| /\b(minimum|maximum|limit)\b/iu.test(message) && | ||
| !/\b(rate|request)\b/iu.test(message) | ||
| ) { | ||
| return 'LIMIT_EXCEEDED'; | ||
| } | ||
| return 'QUOTE_FAILED'; | ||
| } | ||
|
|
||
| function buildRelayRequestFromAmountFiat({ | ||
| amountFiat, | ||
| fiatAsset, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superseded fetch persists quoteError
High Severity
The
getFiatQuotescatch handler always callsupdateFiatPaymentto setquoteErrorbut never checksrequest.signal. A superseded in-flight attempt can still write a stale provider error intofiatPaymentafter a newer refresh already succeeded, so the limit UI can show a rejection while current quotes are valid. The handler also does not clearrampsQuote, so error and quote fields can disagree.Reviewed by Cursor Bugbot for commit a3d867d. Configure here.