Skip to content

fix(ui): read SwapKit's error codes on the DEX amount screens - #1087

Merged
romchornyi merged 6 commits into
developfrom
fix/swapkit-error-mapping
Sep 29, 2026
Merged

romchornyi merged 6 commits into
developfrom
fix/swapkit-error-mapping

Conversation

@romchornyi

@romchornyi romchornyi commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Reported from the Dash DEX Enter amount screens: the errors SwapKit returns had changed, and the screen answered almost everything with the same dead end — "Something went wrong setting up your swap" — even when the API had said exactly what was wrong.

Verified by hand against api.swapkit.dev on 2026-08-28. An amount below a route's floor comes back three different ways depending on how far below it is:

Request (NEAR, DASH → BTC) Response
0.05 DASH 200 + providerErrors[0].errorCode = sellAssetAmountTooSmall
≤ 0.01 DASH 404 + error = noRoutesFound
≥ 1000 DASH 200 + providerErrors[0].errorCode = apiRequestFailed

Two reasons none of it reached the user:

  1. 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 — so even the one error that screen tried to handle fell through to the generic copy.
  2. A failure a provider reports — an HTTP 200 with no routes and a providerErrors[] entry — was passed on as its prose alone, dropping errorCode, the only stable identifier in the response.

What was done?

Mirrors Android's SwapKitErrors (dashpay/dash-wallet#1526) and the enter-amount copy from dashpay/dash-wallet#1539.

  • providerErrorMessage(_:) renders a provider failure as "<code>: <detail>", so provider-level and top-level failures reach the mapper through one path.
  • Below-minimum codes are family-matched on an AmountTooSmall / AmountTooLow suffix rather than enumerated — SwapKit doesn't document the per-provider vocabulary, and the prefix names whichever side was too small. Both forms carry "Amount", so an unrelated below-threshold code (a too-low fee) stays out.
  • Four live codes mapped that previously fell through: apiRequestFailed, invalidRoute, invalidAsset, memoTooLongForSourceChain. The last one shares the copy the wallet already shows when it catches an over-length memo locally before broadcasting.
  • Routability probing classifies on codes too. A below-minimum reply says the probe amount was too small, not that the asset can't be routed — the coin picker no longer marks an asset unroutable on that evidence. A provider naming its own noRoutesFound still counts as conclusive.
  • decodeQuoteError is code-first, matching what the swap-side decoder already did.
  • Over-balance copy follows the redesign: "The maximum transaction amount is $205.32" → "Max $205.32" (Figma 24034:44864, Android maya_max_amount_error).

One string is removed: the buy screen's hand-rolled dex_enter_amount_invalid fallback is orphaned now that both amount screens share the mapper.

Not in this PR

How Has This Been Tested?

  • Clean dashpay build, ARCHS=arm64, iOS Simulator SDK — BUILD SUCCEEDED.
  • Every error shape above was reproduced against live api.swapkit.dev with the app's own API key and request bodies (quote and swap, both directions, amount sweeps per asset), and the mapping checked against those recorded responses.
  • Not exercised on device end-to-end: with Maya down, a Maya-routed sell can't be run right now, and the NEAR sell path is separately blocked upstream (/v3/swap answers invalidRoute for DASH → BTC even with SwapKit's own nextActions payload).

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages in swap buy and convert flows, including clearer guidance for amounts below provider minimums and when no route is available.
    • Shows provider and API error details when quotes or routes fail.
    • Clarified maximum-amount messaging.
  • Localization

    • Added specific messages for below-minimum swap amounts and labels for maximum amounts across supported languages.

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.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b10963e7-7170-4e0d-a524-d0ae9fe502dd

📥 Commits

Reviewing files that changed from the base of the PR and between c5eea1e and 82b91ca.

📒 Files selected for processing (46)
  • DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift
  • DashWallet/Sources/Models/SwapKit/SwapKitSwapProvider.swift
  • DashWallet/ar.lproj/Localizable.strings
  • DashWallet/bg.lproj/Localizable.strings
  • DashWallet/ca.lproj/Localizable.strings
  • DashWallet/cs.lproj/Localizable.strings
  • DashWallet/da.lproj/Localizable.strings
  • DashWallet/de.lproj/Localizable.strings
  • DashWallet/el.lproj/Localizable.strings
  • DashWallet/en.lproj/Localizable.strings
  • DashWallet/eo.lproj/Localizable.strings
  • DashWallet/es.lproj/Localizable.strings
  • DashWallet/et.lproj/Localizable.strings
  • DashWallet/fa.lproj/Localizable.strings
  • DashWallet/fi.lproj/Localizable.strings
  • DashWallet/fil.lproj/Localizable.strings
  • DashWallet/fr.lproj/Localizable.strings
  • DashWallet/hr.lproj/Localizable.strings
  • DashWallet/hu.lproj/Localizable.strings
  • DashWallet/id.lproj/Localizable.strings
  • DashWallet/it.lproj/Localizable.strings
  • DashWallet/ja.lproj/Localizable.strings
  • DashWallet/ko.lproj/Localizable.strings
  • DashWallet/mk.lproj/Localizable.strings
  • DashWallet/ms.lproj/Localizable.strings
  • DashWallet/nb.lproj/Localizable.strings
  • DashWallet/nl.lproj/Localizable.strings
  • DashWallet/pl.lproj/Localizable.strings
  • DashWallet/pt.lproj/Localizable.strings
  • DashWallet/ro.lproj/Localizable.strings
  • DashWallet/ru.lproj/Localizable.strings
  • DashWallet/sk.lproj/Localizable.strings
  • DashWallet/sl.lproj/Localizable.strings
  • DashWallet/sl_SI.lproj/Localizable.strings
  • DashWallet/sq.lproj/Localizable.strings
  • DashWallet/sr.lproj/Localizable.strings
  • DashWallet/sv.lproj/Localizable.strings
  • DashWallet/th.lproj/Localizable.strings
  • DashWallet/tr.lproj/Localizable.strings
  • DashWallet/uk.lproj/Localizable.strings
  • DashWallet/vi.lproj/Localizable.strings
  • DashWallet/zh-Hans.lproj/Localizable.strings
  • DashWallet/zh-Hant-TW.lproj/Localizable.strings
  • DashWallet/zh.lproj/Localizable.strings
  • DashWallet/zh_TW.lproj/Localizable.strings
  • DashWalletTests/SwapKitQuoteDecodingTests.swift
 ______________________________________________________________________________________________________________________________________________________________________
< Refactor early, refactor often. Just as you might weed and rearrange a garden, rewrite, rework, and re-architect code when it needs it. Fix the root of the problem. >
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

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: 4c68dc50-705e-4fc2-8fd7-bbd1c3868a08

📥 Commits

Reviewing files that changed from the base of the PR and between ed88d63 and c5eea1e.

📒 Files selected for processing (5)
  • DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift
  • DashWallet/Sources/Models/SwapKit/SwapKitSwapProvider.swift
  • DashWallet/Sources/UI/Swap/Buy/EnterAmount/BuyEnterAmountViewModel.swift
  • DashWallet/Sources/UI/Swap/Convert/SwapConvertViewModel.swift
  • DashWallet/en.lproj/Localizable.strings

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

SwapKit errors now use normalized, case-insensitive codes for provider formatting, route classification, and amount validation. Buy and convert flows use shared error mapping. Localization adds below-minimum and shortened maximum-amount messages.

Changes

SwapKit error flow

Layer / File(s) Summary
Normalize and map SwapKit errors
DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift
SwapKitErrorCopy now extracts normalized error codes, formats provider errors, detects no-route and below-minimum failures, and maps apiRequestFailed and invalidRoute.
Apply normalized errors to provider flows
DashWallet/Sources/Models/SwapKit/SwapKitSwapProvider.swift
Quote and buy-route flows use shared provider formatting. Routability now uses provider error codes instead of prose matching. Quote decoding prefers top-level error codes.
Use mapped messages in swap UI
DashWallet/Sources/UI/Swap/Buy/EnterAmount/BuyEnterAmountViewModel.swift, DashWallet/Sources/UI/Swap/Convert/SwapConvertViewModel.swift, DashWallet/en.lproj/Localizable.strings
Buy and convert error paths use SwapKitErrorCopy.message(for:coin:). Localization adds below-minimum copy and changes the maximum-amount format to Max %@.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SwapKitSwapProvider
  participant SwapKitErrorCopy
  participant BuyEnterAmountViewModel
  participant SwapConvertViewModel
  SwapKitSwapProvider->>SwapKitErrorCopy: Normalize provider error
  SwapKitErrorCopy-->>SwapKitSwapProvider: Return error code and routability
  SwapKitSwapProvider->>BuyEnterAmountViewModel: Return quote error
  BuyEnterAmountViewModel->>SwapKitErrorCopy: Map validation message
  SwapKitSwapProvider->>SwapConvertViewModel: Return API error
  SwapConvertViewModel->>SwapKitErrorCopy: Map conversion message
Loading

Suggested reviewers: jeanpierreroma, llbartekll

Merge Risk: ⚪ Minimal · up to c5eea

The PR improves how existing SwapKit errors are classified and shown on swap amount screens without changing transaction authority, stored state, or external interfaces; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: updating DEX amount screens to read and use SwapKit error codes.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@thepastaclaw

thepastaclaw commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

🕓 Queued for automated review — 10th in line, estimated start in ~1.8 h (commit 82b91ca)
Estimated review time once started: ~1.2 h (two-phase automated review; median of recent runs).

  • Request priority review — click to move this review to the front of the queue.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Final validation — GLM Flash + Sol

The code-first normalization correctly preserves stable SwapKit codes and improves the amount-screen copy. Two in-scope suggestions remain: top-level noRoutesFound is still treated as conclusive despite the PR's measured amount ambiguity, and the new normalization and classification behavior lacks regression coverage; two minor documentation and cleanup issues are also noted.

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-5.6-sol (agent: phase2-reviewer, role: general); final verifier: gpt-5.6-sol (agent: sol-verifier, role: final-verifier)

Review provenance

  • Phase 1 reviewers (GLM Flash): glm-5.3-flash — general (completed); agent phase1-reviewer
  • Fresh verifier (Sol): gpt-5.6-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers (Sol): gpt-5.6-sol — general (completed); agent phase2-reviewer

🟡 2 suggestion(s) | 💬 2 nitpick(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWallet/Sources/Models/SwapKit/SwapKitSwapProvider.swift`:
- [SUGGESTION] DashWallet/Sources/Models/SwapKit/SwapKitSwapProvider.swift:749-751: Do not classify top-level `noRoutesFound` as conclusively unroutable
  The PR's recorded API behavior shows that SwapKit returns top-level `noRoutesFound` when an amount is far below a route's minimum. This branch nevertheless caches `.notRoutable` for ten minutes, so an asset can disappear from the optimistic Buy picker when its approximately $50 probe—or the one-unit fallback—falls below that asset's route floor. Remove this branch and let the response fall through to `nil`; explicit provider below-minimum errors can remain positive routability evidence, while actual routes remain conclusive positive proof.

In `DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift`:
- [SUGGESTION] DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift:40-79: Add regression tests for the new SwapKit error normalization
  This bug fix introduces several interacting parsing and classification rules without executable coverage. Extend the existing SwapKit tests with compile-ready cases for provider code/detail composition, code-only and detail-only responses, whitespace and nil handling, code-first top-level decoding, case-insensitive `AmountTooSmall` and `AmountTooLow` suffixes, the four newly mapped codes, unknown-code fallback, and routability outcomes for explicit below-minimum versus ambiguous `noRoutesFound` responses. These tests are needed to prevent a decoder or mapper refactor from dropping the stable code behind provider prose again.
- [NITPICK] DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift:38: Correct the nonexistent mapper reference in the doc comment
  The comment references `message(for:coin:minimum:)`, but this module only defines `message(for:coin:)`. Point the documentation at the actual mapper so readers are not directed to a nonexistent overload.
- [NITPICK] DashWallet/Sources/Models/Swap/SwapKitErrorCopy.swift:55-65: Remove the unused `isAmountTooLow(_:)` helper
  Repository-wide usage shows no caller for this newly added helper. The amount screens call `message(for:coin:)`, while routability intentionally uses the narrower `isNoRoute(_:)` and `isBelowMinimum(_:)` methods. Delete the unused API and move any useful ambiguity explanation to the classifier that implements the behavior.

Comment on lines 749 to 751
if SwapKitErrorCopy.isNoRoute(response.error) {
return .notRoutable
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: Do not classify top-level noRoutesFound as conclusively unroutable

The PR's recorded API behavior shows that SwapKit returns top-level noRoutesFound when an amount is far below a route's minimum. This branch nevertheless caches .notRoutable for ten minutes, so an asset can disappear from the optimistic Buy picker when its approximately $50 probe—or the one-unit fallback—falls below that asset's route floor. Remove this branch and let the response fall through to nil; explicit provider below-minimum errors can remain positive routability evidence, while actual routes remain conclusive positive proof.

source: ['codex']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 46ebf78 — the top-level branch is gone and that response now falls through to nil.

Agreed on the reasoning, and the recorded data is worse than the comment suggests: DASH → BTC returns top-level noRoutesFound at 0.01 DASH and a route at 0.3, so the ambiguous band is wide. The probe’s one-unit fallback (no cached USD price) lands inside it for any cheap asset.

Provider-level evidence still decides: a below-minimum code is positive, a provider naming its own noRoutesFound in providerErrors[] is the one conclusive negative — it answers for the single provider the probe asked about — and anything else (apiRequestFailed) leaves the question open. The optimistic-filter comment above candidates.filter was promising pruning the top-level code no longer performs, so it was corrected too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 056ba663): Your classifier now returns nil for top-level noRoutesFound without provider evidence, so that response cannot populate the negative routability cache. Provider-level no-route and below-minimum classifications remain intact, and the new boundary tests explicitly protect these distinctions.

Comment on lines +40 to +79
static func providerErrorMessage(_ error: SwapKitProviderError?) -> String? {
let code = error?.errorCode?.trimmingCharacters(in: .whitespacesAndNewlines)
let detail = error?.message?.trimmingCharacters(in: .whitespacesAndNewlines)
switch (code?.isEmpty == false ? code : nil, detail?.isEmpty == false ? detail : nil) {
case let (code?, detail?):
return "\(code): \(detail)"
case let (code?, nil):
return code
case let (nil, detail?):
return detail
case (nil, nil):
return nil
}
}

/// True when the failure means "the sell amount is under what this route can fill" — the case
/// the amount screens surface inline (raise the amount and retry) instead of as a dead end.
/// `noRoutesFound` is included because SwapKit answers with it for amounts far below the
/// minimum and only switches to an explicit below-minimum code close to the floor: measured
/// 2026-08-28, DASH → BTC returned `noRoutesFound` at 0.01 DASH and `sellAssetAmountTooSmall`
/// (min 0.175) at 0.05. It is genuinely ambiguous — a route can also be briefly unavailable —
/// so its copy stays neutral.
static func isAmountTooLow(_ rawError: String?) -> Bool {
let code = code(of: rawError)
return code == noRoutesFoundCode || isBelowMinimumCode(code)
}

static func message(for rawError: String?, coin: SwapCryptoCurrency) -> String {
let code = rawError?
.components(separatedBy: ":")
.first?
.trimmingCharacters(in: .whitespacesAndNewlines)
.lowercased()
?? ""
let code = code(of: rawError)

// Per-provider below-minimum codes are family-matched rather than enumerated: SwapKit does
// not document the per-provider vocabulary, and the prefix names whichever side was too
// small (`sellAssetAmountTooSmall` today). Both forms carry "amount", so an unrelated
// below-threshold code — a too-low fee, say — stays out.
if isBelowMinimumCode(code) {
return NSLocalizedString(
"This amount is below the minimum for this swap. Please enter a larger amount.",
comment: "Dash DEX / dex_error_amount_too_small"
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: Add regression tests for the new SwapKit error normalization

This bug fix introduces several interacting parsing and classification rules without executable coverage. Extend the existing SwapKit tests with compile-ready cases for provider code/detail composition, code-only and detail-only responses, whitespace and nil handling, code-first top-level decoding, case-insensitive AmountTooSmall and AmountTooLow suffixes, the four newly mapped codes, unknown-code fallback, and routability outcomes for explicit below-minimum versus ambiguous noRoutesFound responses. These tests are needed to prevent a decoder or mapper refactor from dropping the stable code behind provider prose again.

source: ['claude', 'codex']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 46ebf78 — a SwapKitErrorCopyTests case alongside the existing decoding tests, 12 methods covering: code-before-prose composition and its code-only / detail-only / blank / nil fallbacks; the case-insensitive AmountTooSmall / AmountTooLow suffix family, including the composed "<code>: <detail>" form and a negative for inboundFeeTooLow; isNoRoute on both forms; the four newly mapped codes; memoTooLongForSourceChain sharing the local memo copy; detail-after-code not changing the mapping; unknown and empty falling back to generic.

The anchor case is the regression itself: message(for: "No routes found for DASH.DASH -> BTC.BTC") must still be generic. The fix is that callers stopped sending prose alone, not that the mapper started guessing from text — a test asserting the prose maps would cement exactly the wrong behaviour.

Two limits worth stating plainly:

  • Not executed. The test target cannot be built on this machine: the ../platform checkout it takes SwiftDashSDK from sits on a side branch that predates several symbols develop needs (ManagedPlatformWallet.ParsedIdentityUpdateTransition, PlatformWalletManager.trackedMasternodes, MasternodeKeyRole), and DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift references the first of those directly. That is unrelated to this PR and pre-dates it. To get a real signal I extracted SwapKitErrorCopy verbatim into a standalone target with stubbed SwapKitProviderError / SwapCryptoCurrency / DWLogger and ran the same 28 assertions these tests encode — all pass. Whoever has an up-to-date ../platform should run the XCTest cases before merge.
  • Two call sites stay covered only indirectly. routability(from:) and decodeQuoteError(from:) are private, and reaching them would mean widening the access of a private nested enum and a method purely for tests. Every rule they depend on (providerErrorMessage, isNoRoute, isBelowMinimum, code-prefix extraction) is tested directly, so a refactor that puts prose back in front of the code fails here. Say the word if you would rather have them internal and asserted end-to-end.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 056ba663): Your normalization tests cover provider code/detail composition, missing and blank fields, case-insensitive amount-code families, the four added mappings, and generic fallbacks. The subsequent production-boundary tests also close the two indirect-coverage limitations you identified, while preserving the correct expectation that prose alone remains generic.

static let noRoutesFoundCode = "noroutesfound"

/// A provider-level failure rendered in the same `"<code>: <detail>"` shape the top-level
/// `error` field uses, so both reach `message(for:coin:minimum:)` through one path.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 Nitpick: Correct the nonexistent mapper reference in the doc comment

The comment references message(for:coin:minimum:), but this module only defines message(for:coin:). Point the documentation at the actual mapper so readers are not directed to a nonexistent overload.

Suggested change
/// `error` field uses, so both reach `message(for:coin:minimum:)` through one path.
/// `error` field uses, so both reach `message(for:coin:)` through one path.

source: ['codex']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 46ebf78. The same slip existed a second time — isBelowMinimum(_:) referred to [isAmountTooLow], which your other comment asked me to delete — so both now point at symbols that exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 056ba663): Both documentation references now match existing symbols: the provider-error comment names message(for:coin:), and the below-minimum comment references isNoRoute.

Comment on lines +55 to +65
/// True when the failure means "the sell amount is under what this route can fill" — the case
/// the amount screens surface inline (raise the amount and retry) instead of as a dead end.
/// `noRoutesFound` is included because SwapKit answers with it for amounts far below the
/// minimum and only switches to an explicit below-minimum code close to the floor: measured
/// 2026-08-28, DASH → BTC returned `noRoutesFound` at 0.01 DASH and `sellAssetAmountTooSmall`
/// (min 0.175) at 0.05. It is genuinely ambiguous — a route can also be briefly unavailable —
/// so its copy stays neutral.
static func isAmountTooLow(_ rawError: String?) -> Bool {
let code = code(of: rawError)
return code == noRoutesFoundCode || isBelowMinimumCode(code)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 Nitpick: Remove the unused isAmountTooLow(_:) helper

Repository-wide usage shows no caller for this newly added helper. The amount screens call message(for:coin:), while routability intentionally uses the narrower isNoRoute(_:) and isBelowMinimum(_:) methods. Delete the unused API and move any useful ambiguity explanation to the classifier that implements the behavior.

source: ['codex']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 46ebf78. It was added for parity with Android’s SwapKitErrors.isAmountTooLow, but nothing here calls it: the amount screens go through message(for:coin:) and routability deliberately uses the two narrower tests. The measured ambiguity it documented moved onto isNoRoute(_:), which is the classifier that acts on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 056ba663): Your unused isAmountTooLow(:) helper is removed, and its ambiguity explanation now accompanies isNoRoute(:). The amount screens use message(for:coin:), while routability uses the two narrower classifiers as you described.

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.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

At head 46ebf78, source inspection confirms code-first quote error propagation and conservative handling of ambiguous top-level no-route responses. The two coverage findings reduce to one non-blocking suggestion: the new tests exercise the helpers but not the production functions implementing the fixes. No blocking defect was confirmed; build and runtime results were not independently reproduced during this verification.

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: general); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

Review provenance

  • Triage: critical by gpt-6-astra (effort low) — The change alters SwapKit network-response interpretation and cached asset-routability decisions across cryptocurrency swap flows, so misclassification could disable valid trading paths or mishandle provider failures beyond merely displaying incorrect copy.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort max); agent phase1-reviewer
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer

🟡 1 suggestion(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `DashWalletTests/SwapKitQuoteDecodingTests.swift`:
- [SUGGESTION] DashWalletTests/SwapKitQuoteDecodingTests.swift:148-154: Exercise quote error decoding and routability through the production boundary
  These assertions correctly verify that the mapper distinguishes prose from a leading error code, but they manually supply those strings. None of the tests invokes `decodeQuoteError(from:)` or `routability(from:)`, so reverting the decoder to message-first ordering or restoring top-level `noRoutesFound` pruning would leave the new tests passing. Add fixture-based checks through these production functions using a narrow internal seam or an injected response. Cover a non-2xx response containing both `error` and `message`, and empty-route responses with ambiguous top-level no-route and absent/blank provider errors (`nil`), provider-level no-route (`.notRoutable`), below-minimum provider errors (`.routable`), and upstream failures (`nil`). This protects the actual error-propagation and picker-pruning regressions rather than only their helper functions.

Comment on lines +148 to +154
/// The regression itself: before the fix the prose reached the mapper without its code, and
/// "No routes found for …" matches nothing. Prose alone must still fall through — the fix is
/// that callers no longer send it alone, not that the mapper started guessing from text.
func testProseWithoutItsCodeIsNotMistakenForAMapping() {
XCTAssertEqual(message("No routes found for DASH.DASH -> BTC.BTC"), genericMessage)
XCTAssertNotEqual(message("noRoutesFound: No routes found for DASH.DASH -> BTC.BTC"), genericMessage)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: Exercise quote error decoding and routability through the production boundary

These assertions correctly verify that the mapper distinguishes prose from a leading error code, but they manually supply those strings. None of the tests invokes decodeQuoteError(from:) or routability(from:), so reverting the decoder to message-first ordering or restoring top-level noRoutesFound pruning would leave the new tests passing. Add fixture-based checks through these production functions using a narrow internal seam or an injected response. Cover a non-2xx response containing both error and message, and empty-route responses with ambiguous top-level no-route and absent/blank provider errors (nil), provider-level no-route (.notRoutable), below-minimum provider errors (.routable), and upstream failures (nil). This protects the actual error-propagation and picker-pruning regressions rather than only their helper functions.

source: ['claude', 'codex']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 57cfd40. decodeQuoteError(from:) and routability(from:) are now internal statics (BuyRoutability with them). The bodies are unchanged, and only this type calls them. A new SwapKitQuoteBoundaryTests feeds them recorded SwapKit bodies:

  • decodeQuoteError: the recorded 404 with both error and message (code first), a code-only body, the provider-code fallback, the prose-only fallback, and failures with no SwapKit body (an HTML 502, a transport error) → nil.
  • routability: a route → .routable; top-level noRoutesFound, absent/empty/blank providerErrors → nil; a provider noRoutesFound → .notRoutable; sellAssetAmountTooSmall → .routable; apiRequestFailed → nil.

Reverting the decoder to message-first, or bringing back top-level noRoutesFound pruning, now fails these tests. I ran them against develop merged in, on an iOS 26.5 simulator: 25/25 SwapKit tests pass. The branch also has develop merged in (056ba66).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved (re-reviewed at 056ba663): Your new SwapKitQuoteBoundaryTests call the actual decoder and routability classifier, including the code-before-prose response and every requested picker-classification case. These assertions would catch both regressions identified in the finding; I verified the source and target membership, but could not independently reproduce your simulator run with the installed toolchain.

jeanpierreroma and others added 2 commits September 23, 2026 11:08
…oduction 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]>

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 2 only (queue backlog)

Independently reviewed the complete diff at 056ba66 and relevant callers; no actionable in-scope defects remain, and all five prior findings are fixed. The production decoder preserves error codes, ambiguous top-level no-route responses no longer prune the picker, and regression tests directly exercise both production boundaries. Diff whitespace checks, Swift syntax parsing, and English localization validation passed; independent build, XCTest, and runtime verification remain unavailable because the pinned DashUIKit revision requires Swift tools 6.3 while the installed toolchain provides 6.1.2.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: general); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes error decoding, provider-code classification, routability probing, and shared UI messaging across several production paths with substantial regression tests, but does not itself change funds movement or another critical surface.
  • Phase 1 reviewers: not run (skipped for throughput: 30 PRs queued, above the 10 limit)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — general (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Code-first decoding is right, and so is routing both amount screens through SwapKitErrorCopy. The boundary tests pin the two production functions rather than only the helpers.

I checked that the test initialisers (SwapKitQuoteResponse, SwapKitProviderError, SwapCryptoCurrency, HTTPClientError.statusCode) match the models, and that nothing else used the removed helpers. I did not build this locally.

Three non-blocking notes inline. The first one is the only one I'd look at before a release, since it affects the PR's headline case.

// Step 2: pick RECOMMENDED → CHEAPEST → first (mirrors Android bestRoute()).
guard let best = bestRoute(from: quoteResponse.routes ?? []) else {
let msg = quoteResponse.providerErrors?.first?.message
let providerError = quoteResponse.providerErrors?.first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking, but it touches the headline case. For an asset that NEAR and Maya both list, sellQuoteProviders(for:) asks NEAR, MAYACHAIN and MAYACHAIN_STREAMING together, so a no-route reply can carry up to three providerErrors. Only .first is read.

The description says Maya currently answers noRoutesFound for every pair. So a 0.05 DASH → BTC sell can list both Maya providers as noRoutesFound next to NEAR's sellAssetAmountTooSmall. The user then sees the "try again shortly" copy or the "enter a larger amount" copy depending only on the order SwapKit puts them in. (The recorded measurements were NEAR-only requests, so they don't cover this.) I couldn't confirm the order live: api.swapkit.dev answered my curl with a bot-check page.

Consider picking the most actionable entry instead of the first: below-minimum first, then any other code, then noRoutesFound. Same in fetchIndicativeQuote (L352). Fine as a follow-up.

// and quoted a route at 0.3 — and the probe amount is a $50 estimate that falls back
// to one whole unit when no USD price is cached. Pruning on it would drop a routable
// asset out of the picker for the whole cache window.
return nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree with not pruning on the top-level form. One question about what's left.

Have you seen a NEAR-only probe come back with noRoutesFound inside providerErrors? Your table shows a NEAR-only request that misses answering with the top-level 404. If SwapKit always folds a single-provider miss into that form, .notRoutable never fires and the picker stops pruning altogether.

Also, nil isn't written to buyRoutabilityCache, so these assets are probed again every time the picker opens, where they used to be cached for 10 minutes. The request count is bounded by the batch size, so this doesn't block. It's worth knowing whether the probe still earns its requests.

format: NSLocalizedString(
"The maximum transaction amount is %@",
comment: "Dash DEX"
"Max %@",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: this was the only use of "The maximum transaction amount is %@", so the entry is now orphaned in en.lproj/Localizable.strings (L4526). Worth dropping it the same way dex_enter_amount_invalid was.

jeanpierreroma and others added 2 commits September 29, 2026 14:13
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]>
@romchornyi
romchornyi merged commit 50f04c0 into develop Sep 29, 2026
3 of 4 checks passed
@romchornyi
romchornyi deleted the fix/swapkit-error-mapping branch September 29, 2026 11:21
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.

4 participants