Skip to content

fix(swap): stop reporting unsettled conversions as successful - #699

Merged
islandbitcoin merged 6 commits into
mainfrom
fix/swap-pending-and-probe-errors
Aug 16, 2026
Merged

islandbitcoin merged 6 commits into
mainfrom
fix/swap-pending-and-probe-errors

Conversation

@islandbitcoin

@islandbitcoin islandbitcoin commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Symptom (reported from TEST, applies to prod)

A Cash→BTC conversion showed "Conversion successful" while no funds moved; the retry showed only "An unexpected error occurred. Please try again later." IBEX recorded no send for either attempt.

⚠️ Release ordering — do not ship this client build before lnflash/flash#483 is on prod

Against the current production backend (pre-flash#483, which reads only transaction.payment.payment.status.id and defaults everything else to Pending), conversions that IBEX actually settled but reported through statusId or the top-level status field come back as PENDING. This client renders PENDING as "not confirmed yet" instead of "Conversion successful" — correct, but a visible support-load change on the happy path.

Gate: flash#483 deployed to prod before this lands in a shipped build. If they cannot ship together, measure the share of IBEX responses that populate only statusId/top-level status first, so the team knows what fraction of conversions will start showing the pending screen.

Defects fixed

  1. PENDING rendered as success. swap() returned true for PENDING, and the confirmation screen navigated straight to the success screen. A payment that is merely in flight — or one the server could not confirm at all — looked settled. swap() now returns {status: "success" | "pending"}, and the success screen renders a real in-progress state for pending (the existing payment-pending icon, the already-translated SendBitcoinScreen.notConfirmed copy the send flow uses for the same state, a longer dwell before auto-dismiss).

  2. Status was read before errors. Errors are now checked first. To be precise about what the server actually does: lnInvoicePaymentSend returns {status: FAILURE, errors: [...]} on every error path and {status, errors: []} otherwise — errors and a non-failed status are mutually exclusive today, and flash#483 deliberately returns Pending with no error for the unconfirmed case. So this ordering is defensive, not a workaround for an observed response: it keeps a future PENDING-carrying-an-error response from rendering as an ordinary in-flight conversion.

  3. Fee-probe errors were swallowed. prepareUsdToBtc used amount || 0, so a failed probe became a fee of 0 and the user continued to confirmation on a fee we never obtained — the real reason was discarded and resurfaced later as a vaguer send failure. Probe errors (and a missing amount) now surface on the details screen, in a state kept separate from the amount-validation error so they cannot permanently disable the Next button. moveToNextScreen is wrapped in try/catch/finally, so a probe rejection (the most common probe failure) clears the spinner instead of hanging it.

  4. Silent dead tap. The Breez branch of swap() fell off the end returning undefined on failure; the confirmation screen read that as "nothing happened" — no success, no error. It now throws, and distinguishes Breez Completed from Pending. The confirmation screen's if (lnInvoice) wrapper is also gone, so an empty prepared invoice (prepareBtcToUsd can produce lnInvoice: "") reaches the hook's guard and surfaces an error instead of doing nothing.

Other cleanups from review

  • swap() switches on the generated PaymentSendResult const rather than raw string literals, with an explicit FAILURE case so default: means only "unrecognised". The useSwap test's wholesale mock of @app/graphql/generated now takes the enum from jest.requireActual, so a codegen rename fails the test instead of passing against stale literals.
  • throw new Error("Invoice is already paid") was hardcoded English toasted straight to the user; it now uses the translated ReceiveScreen.invoicePaid.
  • The three remaining console.log(">>>>>>>>") debug lines are deleted — one dumped the full Breez receivePayment response (payment request included) into the retained log-buffer on every USD→BTC conversion.
  • No new i18n keys. The earlier revision added three English strings that duplicated already-translated ones and shipped as English into all 23 locales. common.somethingWentWrong is replaced by the existing errors.generic, and the pending copy by the existing SendBitcoinScreen.notConfirmed. app/i18n/ is now byte-identical to main.

Test-infrastructure fix

__mocks__/@breeztech/breez-sdk-spark-react-native.js exported PaymentStatus as strings keyed Complete, while the real SDK (and app code such as app/types/transactions.ts:108) uses numeric Completed. Any test exercising that comparison silently compared against undefined and took the wrong branch — it did exactly that to these tests before I caught it. The mock now mirrors the real enum.

Tests

app/hooks/__tests__/useSwap.test.tsx plus three new screen suites — conversion-success-screen, conversion-confirmation-screen, conversion-details-screen — covering the wiring that turns {status: "pending"} into a pending screen, which previously had no coverage at all. Each screen suite was verified by mutation: hardcoding pending, restoring the if (lnInvoice) guard, moving the submit error back into errorMsg, or removing the try/catch each turns them red.

Full suite 70 suites / 488 tests green, yarn check-code clean (tsc, translations, codegen, graphql-inspector). Pre-existing @ts-ignore/no-else-return lint in untouched parts of useSwap.ts deliberately left alone to keep the diff reviewable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV

A Cash->BTC conversion showed the success screen while no funds moved,
and the retry died on a generic error. Three defects in the swap flow,
all of which also affect production:

- swap() returned `true` for PENDING, so the confirmation screen
  navigated to "Conversion successful". A payment that is merely in
  flight — or one the API could not confirm at all — rendered as
  settled. It now returns a discriminated {status: "success"|"pending"},
  and the success screen shows an "in progress" state (payment-pending
  icon, its own copy, longer dwell) for the pending case.
- swap() read `status` before `errors`. The API reports a payment it
  could not confirm as PENDING *carrying* an error (see flash#483), so
  errors must win; they now throw.
- prepareUsdToBtc swallowed lnUsdInvoiceFeeProbe payload errors via
  `amount || 0`, sending the user to confirmation on a fee we never
  obtained — the real reason ("An error occurred. Contact support…")
  was discarded and resurfaced later as a vaguer send failure. Probe
  errors and a missing amount are now surfaced at the details screen.
- The Breez branch of swap() fell off the end returning undefined when
  the send failed, which the confirmation screen read as "nothing
  happened": no success, no error, no spinner reset. It now throws on
  failure and distinguishes Completed from Pending.

Also fixes the shared Breez SDK test mock, which exported PaymentStatus
as strings keyed "Complete" while the real SDK (and app code such as
app/types/transactions.ts) uses numeric `Completed` — any test touching
that comparison silently took the wrong branch.

Tests: 10 new covering each behaviour above. Full suite 67/471 green,
tsc clean, no ESLint errors on changed lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV
Dread and others added 5 commits August 15, 2026 21:24
check:translation-drift requires each locale to contain every key in
en.json. Added with the English text as the placeholder, matching how
previous key-adding PRs (#689, #691, #693) seeded new keys before
translation.
- conversion-details-screen: submit-time errors go to a separate
  `submitErrorMsg` state instead of `errorMsg`. `ConversionAmountError`
  only clears `errorMsg` from an effect keyed on the amount, so a probe
  error parked there left Next permanently greyed out with no hint that
  nudging the amount was the only escape.
- conversion-details-screen: wrap `moveToNextScreen` in try/catch/finally.
  `receivePaymentBreez` has no try/catch and the Apollo fee probe rejects
  on network error, so a probe timeout left the spinner up forever plus an
  unhandled rejection.
- conversion-confirmation-screen: drop the `if (lnInvoice)` wrapper so the
  `!lnInvoice` guard added in useSwap is reachable. `prepareBtcToUsd` can
  produce `lnInvoice: ""`, and Convert was a silent dead tap for it.
- useSwap: switch on the generated `PaymentSendResult` const instead of raw
  string literals, with an explicit `FAILURE` case so `default:` means only
  "unrecognised". A codegen rename would otherwise break the app at runtime
  with every test green.
- useSwap: correct the errors-outrank-status comment — the server does not
  pair an error with a non-failed status today; the ordering is defensive.
- useSwap: `throw new Error("Invoice is already paid")` was hardcoded
  English toasted straight to the user; use the translated
  `ReceiveScreen.invoicePaid`.
- useSwap: delete the three remaining `console.log(">>>>>>>>")` lines; one
  dumped the full Breez receivePayment response into the retained log
  buffer on every USD->BTC conversion.
- i18n: drop all three new English keys. `common.somethingWentWrong` was
  byte-identical to the already-translated `errors.generic`, and the
  pending copy duplicates the fully-translated
  `SendBitcoinScreen.notConfirmed` the send flow already renders for an
  unconfirmed payment. They had shipped as English into all 23 locales;
  app/i18n/ is now byte-identical to main.
- tests: new conversion-success-screen, conversion-confirmation-screen and
  conversion-details-screen suites — the wiring that turns
  `{status: "pending"}` into a pending screen had no coverage at all.
  Verified by mutation: hardcoding `pending`, restoring the `if (lnInvoice)`
  guard, moving the submit error back into `errorMsg`, or removing the
  try/catch each turns them red.
- tests: useSwap's wholesale mock of @app/graphql/generated now takes
  `PaymentSendResult` from `jest.requireActual`, so a codegen change fails
  the test instead of passing against stale literals.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV
…entType mock

Follow-up review fixes on the pending/probe-error PR.

- __mocks__ PaymentType was still string-valued while the real SDK enum is
  numeric (Send = 0, Receive = 1) — the same trap that had already been fixed
  for PaymentStatus three lines below, left armed in the same object literal.
  Any test using a realistic Breez fixture (paymentType: 1) would have compared
  1 === "Receive", taken the send branch, and passed green while asserting the
  opposite of production behaviour. Both enums now carry the generated numbering
  and one comment covering the whole block.
- conversion-details-screen: the new catch swallowed the rejection into on-screen
  text and reported it nowhere, unlike its sibling in conversion-confirmation-screen.
  It now records the error to Crashlytics before setting the message, so the
  fee-probe failure rate is visible in the field.
- conversion-details-screen: submitErrorMsg was cleared only on submit, so a stale
  "An error occurred" stayed pinned under the inputs after a direction flip or an
  amount edit — describing a request that no longer matched the screen. It now
  clears on the same keys ConversionAmountError re-validates on.

Tests:
- app/types/__tests__/transactions.test.ts (new): isReceiveTransaction and
  getTransactionStatus against raw numeric SDK values; red with the string mock.
- conversion-details-screen tests: the amount-validation gate test now actually
  produces an error (was passing purely on "no amount entered", so deleting
  `|| Boolean(errorMsg)` left the suite green); a new test drives the USD→BTC
  direction and asserts prepareUsdToBtc is the one called; two new tests cover
  stale submit-error clearing; the reject tests now assert the Crashlytics report.

All five fixes verified by mutation: reverting each one turns its test red.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV
The catch branch added for non-Error rejections showed the generic copy
and recorded nothing, so the least diagnosable failure — an Apollo link
or Breez binding throwing a string — was also the only invisible one.
Wrap instead of branching: the report now carries the raw thrown value,
while the user still sees the generic message.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV
@islandbitcoin
islandbitcoin merged commit 441191a into main Aug 16, 2026
9 checks passed
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.

1 participant