Repository navigation
fix(dash-dex): show the amount-too-low hint when a provider reports sellAssetAmountTooSmall - #1526
Conversation
…ellAssetAmountTooSmall
A quote that comes back with no routes carries the reason in providerErrors[],
where the stable identifier is `errorCode` and `message` is prose. The aggregator
passed the prose into MayaException, so SwapKitErrors.messageResFor — which keys off
the code — always fell through to dex_error_generic, and isAmountTooLowError never
matched.
The user-visible effect: selling an amount under MAYACHAIN's minimum popped
"Something went wrong setting up your swap. Please try again." as a modal instead of
the inline "enter a larger amount" hint, giving no clue that the amount was the
problem. Reproduced on testnet with 0.0033 DASH -> BTC.BTC, where SwapKit returned
routes: [] plus providerErrors: [{errorCode: sellAssetAmountTooSmall}].
- providerErrorMessage() renders provider errors as "<code>: <detail>", the same
shape the top-level `error` field uses, so the code leads and the mapping matches
- map sellAssetAmountTooSmall to a new dex_error_amount_too_small string and treat it
as amount-too-low, so it surfaces inline like noRoutesFound already did
- centralize the code vocabulary in SwapKitErrors (codeOf/isAmountTooLow) instead of
re-parsing the prefix in the aggregator
- cover the mapping with SwapKitErrorsTest, including that prose alone must not match
Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughSwapKit error handling now centralizes error-code extraction, amount-too-low classification, provider-error formatting, and user-facing message mapping. Maya route failures use the centralized formatting, with coverage added for mappings, fallbacks, provider errors, and amount thresholds. ChangesSwapKit error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
* fix(ui): read SwapKit's error codes on the DEX amount screens
Every amount-related failure on Enter amount rendered as a dead end
("Something went wrong setting up your swap") even when SwapKit had said
exactly what was wrong. Two causes, both about where the code was read
from.
`decodeQuoteError` returned `body.message` before `body.error`, so the
prose reached the mapper and the code never did: "No routes found for
DASH.DASH -> BTC.BTC" does not match `noRoutesFound`, and the buy
screen's own `contains("noRoutesFound")` check missed it for the same
reason. And a failure a provider reports — an HTTP 200 with no routes
and `providerErrors[]` — was passed on as its prose alone, dropping
`errorCode`, the only stable identifier in the response.
Measured against api.swapkit.dev on 2026-08-28: at 0.05 DASH a
DASH -> BTC quote answers 200 with `sellAssetAmountTooSmall`; below
about 0.01 DASH it answers 404 `noRoutesFound`; above the pool's depth
it answers 200 with `apiRequestFailed`. All three read as "something
went wrong".
- `providerErrorMessage` puts the code back in front of the prose, so
provider-level and top-level failures reach the mapper the same way.
- Below-minimum codes are family-matched on an `AmountTooSmall` /
`AmountTooLow` suffix rather than enumerated, since SwapKit does not
document the per-provider vocabulary.
- `apiRequestFailed`, `invalidRoute`, `invalidAsset` and
`memoTooLongForSourceChain` are mapped; the last shares the copy the
wallet already uses when it catches an over-length memo locally.
- Routability probing classifies on codes too: a below-minimum reply
says the probe amount was too small, not that the asset is unroutable,
so the coin picker no longer hides an asset on that evidence.
- The convert screen's over-balance line follows the redesign to
"Max $205.32" (Figma 24034:44864).
Mirrors Android's `SwapKitErrors` (dashpay/dash-wallet#1526) and the
enter-amount copy from dashpay/dash-wallet#1539.
* fix(ui): stop pruning the Buy picker on an ambiguous no-route
Review follow-up.
A top-level `noRoutesFound` was cached as a conclusive negative for ten
minutes, but SwapKit answers with it for an amount far below a route's
floor as well as for a pair it cannot carry — measured 2026-08-28,
DASH -> BTC returned it at 0.01 DASH and quoted a route at 0.3. The
probe is a $50 estimate that falls back to one whole unit when no USD
price is cached, so a cheap asset could be probed under its own floor
and disappear from the picker for the rest of the window. Only a
provider naming its own no-route in `providerErrors[]` stays conclusive:
it answers for the single provider the probe asked about.
Also from review: drop `isAmountTooLow(_:)`, which had no callers once
the amount screens moved to `message(for:coin:)` and routability took
the two narrower tests; move the ambiguity it documented onto
`isNoRoute(_:)`, which is what acts on it. Point two doc comments at
symbols that exist.
Adds regression coverage for the normalization rules: code-before-prose
composition and its fallbacks, blank and nil handling, the
case-insensitive below-minimum suffix family, the four newly mapped
codes, the shared memo-too-long copy, unknown-code fallback, and the
anchor case — prose without its code must not be mistaken for a mapping.
* test(ui): drive SwapKit quote decoding and routability through the production functions
The helper tests pinned the rules but not the functions that apply them, so
reverting decodeQuoteError to prose-first or restoring top-level noRoutesFound
pruning left every test green. decodeQuoteError(from:) and routability(from:)
become internal statics and SwapKitQuoteBoundaryTests feeds them recorded
SwapKit bodies: code-first decoding and its fallbacks, and each routability
outcome (route, ambiguous top-level no-route, blank provider errors, provider
no-route, below-minimum, upstream failure).
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* chore(ui): keep every locale catalog on the English key set
The two DEX strings this PR adds ("Max %@" and the below-minimum copy)
were only in en.lproj, so the 42 other catalogs fell behind the key set
#1165 had just brought them up to. Add both with the English value, the
way new keys ship until Transifex translates them.
Drop the two keys the PR orphaned from every catalog: the buy screen's
dex_enter_amount_invalid fallback, and "The maximum transaction amount
is %@", replaced by "Max %@" on the convert screen.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Roman <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
The bug
Selling an amount below MAYACHAIN's minimum shows a modal reading "Something went wrong setting up your swap. Please try again." instead of the inline "enter a larger amount" hint. Nothing tells the user the amount is the problem, so the natural response is to retry the same amount.
Found while testing the DEX sell flow on testnet against live SwapKit.
Root cause
When a quote returns no routes, the reason is in
providerErrors[], whereerrorCodeis the stable identifier andmessageis human prose.SwapKitApiAggregatorpassed the prose intoMayaException:Both
SwapKitErrors.messageResForandisAmountTooLowErrorkey off the code (viasubstringBefore(':')), so"Sell asset amount too small for provider MAYACHAIN."matched nothing — it fell through todex_error_generic, and the too-low check returned false, forcing the modal path.sellAssetAmountTooSmallwas also absent from the mapping table entirely.Observed response (testnet, 0.0033 DASH → BTC.BTC):
{"routes":[],"providerErrors":[{"provider":"MAYACHAIN_STREAMING", "errorCode":"sellAssetAmountTooSmall", "message":"Sell asset amount too small for provider MAYACHAIN."}]}The fix
SwapKitErrors.providerErrorMessage()renders a provider error as"<code>: <detail>"— the same shape the top-levelerrorfield already uses — so the code leads and the existing mapping matches. Both routeless-quote sites (sell and buy) use it.sellAssetAmountTooSmallmaps to a newdex_error_amount_too_smallstring and joinsnoRoutesFoundas an amount-too-low code, so it surfaces as the inline red error rather than a modal.SwapKitErrors(codeOf/isAmountTooLow) instead of the aggregator re-parsing the prefix independently.Tests
New
SwapKitErrorsTest(7 cases) covers the mapping, the too-low classification, and the regression directly — including that prose alone must not match a code. All 80 maya unit tests pass and the module compiles.Note the same defect exists on
feat/kotlin-sdk-phase1(it inherited this code via the master merge in #1525); this fix should flow there through the next master merge rather than being duplicated.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests