Skip to content

[READY] Improve Error Messages#1171

Open
Sharqiewicz wants to merge 1 commit into
stagingfrom
1069-improve-error-messages-for-order-limits
Open

[READY] Improve Error Messages#1171
Sharqiewicz wants to merge 1 commit into
stagingfrom
1069-improve-error-messages-for-order-limits

Conversation

@Sharqiewicz
Copy link
Copy Markdown
Member

@Sharqiewicz Sharqiewicz commented May 28, 2026

Closes: #1069

Improves the wording, locale-awareness, and coverage of order-limit error messages, and
adds backend support for above-maximum (upper-bound) limit errors from Alfredpay.

  • Frontend now renders friendlier Minimum/Maximum {buy|sell} amount is X SYM. strings instead of the
    older {SYM} orders must be more/less than ... wording, with locale-aware number formatting
    (Intl.NumberFormat).
  • Backend detects Alfredpay's above-max errors (HTTP 409 errorCode 111426 with maxQuantity in
    errorMetadata) and surfaces them as user-facing limit errors. Previously only below-min errors were
    handled.
  • AlfredpayTradeLimitError is now a discriminated union (kind: "above" | "below"); consumed via
    static factories AlfredpayTradeLimitError.above() / .below().

Changes

Backend

  • apps/api/src/api/services/quote/index.ts
    • Catches both above-max and below-min AlfredpayTradeLimitError and maps them to APIError via a
      new mapAlfredpayLimitErrorToApiError helper.
  • packages/shared/src/services/alfredpay/alfredpayApiService.ts
    • Extracts maxQuantity alongside minQuantity from errorMetadata and picks the appropriate
      factory.
    • Adds a diagnostic logger.warn when a trade-limit error is thrown.
  • packages/shared/src/services/alfredpay/types.ts
    • AlfredpayTradeLimitError refactored to discriminated union: kind, quantity, fromCurrency;
      private constructor + static below() / static above() factories.
  • packages/shared/src/endpoints/quote.endpoints.ts
    • Adds QuoteError.AboveUpperLimitSell and QuoteError.AboveUpperLimitBuy.

Frontend

  • apps/frontend/src/hooks/ramp/useRampValidation.ts
    • Locale-aware formatting via Intl.toLocaleString using i18n.language.
    • 4-branch limit ladder collapsed into a buildLimitMessage helper.
    • Parses backend-supplied limit values from the error message via a strict regex
      (/of\s+(\d+(?:\.\d+)?)\s+([A-Z]{3})/) and falls back to static config if not present.
    • Switched translation keys from pages.swap.error.amountOutOfRange.* to the friendlier
      pages.swap.error.{lessThanMinimumWithdrawal,moreThanMaximumWithdrawal}.{buy,sell} (keys already
      existed in en.json/pt.json).
  • apps/frontend/src/stores/quote/useQuoteStore.ts
    • Adds pass-through entries for the new AboveUpper* QuoteError variants.

User-facing (frontend translations)

Direction Limit Before After
Buy min {SYM} orders must be more than {min} {SYM} Minimum buy amount is {min} {SYM}.
Buy max {SYM} orders must be less than {max} {SYM} Maximum buy amount is {max} {SYM}.
Sell min {SYM} orders must be more than {min} {SYM} Minimum sell amount is {min} {SYM}.
Sell max {SYM} orders must be less than {max} {SYM} Maximum sell amount is {max} {SYM}.

Amounts are now locale-formatted (e.g. 10,000.50 vs 10.000,50) instead of raw Big.toString().

Backend QuoteError constants

Constant Value Status
BelowLowerLimitSell Output amount below minimum SELL limit of pre-existing
BelowLowerLimitBuy Input amount below minimum BUY limit of pre-existing
AboveUpperLimitSell Output amount exceeds maximum SELL limit of new
AboveUpperLimitBuy Input amount exceeds maximum BUY limit of new

Internal (not user-facing)

Class Format
AlfredpayTradeLimitError Trade below minimum: {qty} {ccy} / Trade above maximum: {qty} {ccy}

@Sharqiewicz Sharqiewicz linked an issue May 28, 2026 that may be closed by this pull request
@netlify
Copy link
Copy Markdown

netlify Bot commented May 28, 2026

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit 41db8d6
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6a1873dc8be95500089cf31b
😎 Deploy Preview https://deploy-preview-1171--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 28, 2026

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit 41db8d6
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6a1873dc8be95500089cf317
😎 Deploy Preview https://deploy-preview-1171--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Sharqiewicz Sharqiewicz requested a review from ebma May 28, 2026 16:57
@Sharqiewicz Sharqiewicz changed the title Improve Error Messages [READY] Improve Error Messages May 28, 2026
@ebma ebma requested a review from Copilot May 28, 2026 17:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves order-limit error UX by switching to friendlier, locale-aware "Minimum/Maximum {buy|sell} amount is X SYM." messages on the frontend, and adds backend support for Alfredpay above-maximum (upper-bound) limit errors that previously went unhandled.

Changes:

  • Refactors AlfredpayTradeLimitError into a discriminated union (kind: "above" | "below") with static below()/above() factories, and detects maxQuantity in Alfredpay 409/errorCode 111426 responses.
  • Adds new QuoteError.AboveUpperLimit{Sell,Buy} constants and a backend mapper from AlfredpayTradeLimitErrorAPIError covering both above/below × buy/sell.
  • Rewrites the frontend limit-message rendering in useRampValidation with a buildLimitMessage helper, Intl-based locale-aware formatting (i18n.language), a regex-based parser of backend-supplied amount/symbol, and switches translation keys to the friendlier lessThanMinimumWithdrawal/moreThanMaximumWithdrawal.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/shared/src/services/alfredpay/types.ts Refactor AlfredpayTradeLimitError to discriminated union with static factories.
packages/shared/src/services/alfredpay/alfredpayApiService.ts Extract maxQuantity, log diagnostic, dispatch to above()/below() factory.
packages/shared/src/endpoints/quote.endpoints.ts Add AboveUpperLimitSell/AboveUpperLimitBuy quote-error constants.
apps/api/src/api/services/quote/index.ts Extract mapAlfredpayLimitErrorToApiError covering both kinds × directions.
apps/frontend/src/stores/quote/useQuoteStore.ts Pass-through entries for the new upper-limit QuoteError variants.
apps/frontend/src/hooks/ramp/useRampValidation.ts Locale-aware formatting, regex parser for backend limits, buildLimitMessage helper, switch to friendlier translation keys, handle above-max cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Error Messages for Order Limits

2 participants