Skip to content

fix(dash-dex): show the amount-too-low hint when a provider reports sellAssetAmountTooSmall - #1526

Merged
bfoss765 merged 1 commit into
masterfrom
fix/swapkit-amount-too-low
Aug 7, 2026
Merged

bfoss765 merged 1 commit into
masterfrom
fix/swapkit-amount-too-low

Conversation

@HashEngineering

@HashEngineering HashEngineering commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

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[], where errorCode is the stable identifier and message is human prose. SwapKitApiAggregator passed the prose into MayaException:

MayaException(quote.providerErrors?.firstOrNull()?.message ?: "no swapkit route")

Both SwapKitErrors.messageResFor and isAmountTooLowError key off the code (via substringBefore(':')), so "Sell asset amount too small for provider MAYACHAIN." matched nothing — it fell through to dex_error_generic, and the too-low check returned false, forcing the modal path. sellAssetAmountTooSmall was 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-level error field already uses — so the code leads and the existing mapping matches. Both routeless-quote sites (sell and buy) use it.
  • sellAssetAmountTooSmall maps to a new dex_error_amount_too_small string and joins noRoutesFound as an amount-too-low code, so it surfaces as the inline red error rather than a modal.
  • The code vocabulary now lives in 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

    • Improved swap error handling with clearer provider error messages.
    • Correctly identifies insufficient swap amounts across supported error formats.
    • Displays a dedicated message when the entered amount is below the minimum required.
    • Preserves appropriate fallback messaging for unknown or incomplete errors.
  • Tests

    • Added coverage for error mapping, amount validation, provider responses, and fallback behavior.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12f33015-e798-491e-bab5-3a0bc4fb7b8e

📥 Commits

Reviewing files that changed from the base of the PR and between d4c0495 and 2a5e7e4.

📒 Files selected for processing (4)
  • integrations/maya/src/main/java/org/dash/wallet/integrations/maya/swapkit/SwapKitApiAggregator.kt
  • integrations/maya/src/main/java/org/dash/wallet/integrations/maya/swapkit/SwapKitErrors.kt
  • integrations/maya/src/main/res/values/strings-maya.xml
  • integrations/maya/src/test/java/org/dash/wallet/integrations/maya/swapkit/SwapKitErrorsTest.kt

📝 Walkthrough

Walkthrough

SwapKit 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.

Changes

SwapKit error handling

Layer / File(s) Summary
Centralized error vocabulary and mappings
integrations/maya/src/main/java/org/dash/wallet/integrations/maya/swapkit/SwapKitErrors.kt, integrations/maya/src/main/res/values/strings-maya.xml, integrations/maya/src/test/java/org/dash/wallet/integrations/maya/swapkit/SwapKitErrorsTest.kt
Error codes are normalized through a shared extractor, sellAssetAmountTooSmall receives a dedicated resource mapping, amount-too-low codes are classified centrally, provider errors are formatted consistently, and the behavior is tested.
Route failure integration
integrations/maya/src/main/java/org/dash/wallet/integrations/maya/swapkit/SwapKitApiAggregator.kt
General and NEAR-pinned route failures use centralized provider-error formatting, and amount-too-low detection delegates to SwapKitErrors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: abaranouski

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: handling sellAssetAmountTooSmall as an amount-too-low hint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/swapkit-amount-too-low

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@HashEngineering HashEngineering self-assigned this Jul 30, 2026
@bfoss765
bfoss765 merged commit 0dfafb6 into master Aug 7, 2026
2 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2026
3 tasks
romchornyi added a commit to dashpay/dashwallet-ios that referenced this pull request Sep 29, 2026
* 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]>
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.

2 participants