Repository navigation
fix(swap): stop reporting unsettled conversions as successful - #699
Merged
Merged
Conversation
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
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Against the current production backend (pre-flash#483, which reads only
transaction.payment.payment.status.idand defaults everything else toPending), conversions that IBEX actually settled but reported throughstatusIdor the top-levelstatusfield come back asPENDING. This client rendersPENDINGas "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-levelstatusfirst, so the team knows what fraction of conversions will start showing the pending screen.Defects fixed
PENDING rendered as success.
swap()returnedtrueforPENDING, 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 existingpayment-pendingicon, the already-translatedSendBitcoinScreen.notConfirmedcopy the send flow uses for the same state, a longer dwell before auto-dismiss).Status was read before errors. Errors are now checked first. To be precise about what the server actually does:
lnInvoicePaymentSendreturns{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 returnsPendingwith 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.Fee-probe errors were swallowed.
prepareUsdToBtcusedamount || 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.moveToNextScreenis wrapped in try/catch/finally, so a probe rejection (the most common probe failure) clears the spinner instead of hanging it.Silent dead tap. The Breez branch of
swap()fell off the end returningundefinedon failure; the confirmation screen read that as "nothing happened" — no success, no error. It now throws, and distinguishes BreezCompletedfromPending. The confirmation screen'sif (lnInvoice)wrapper is also gone, so an empty prepared invoice (prepareBtcToUsdcan producelnInvoice: "") reaches the hook's guard and surfaces an error instead of doing nothing.Other cleanups from review
swap()switches on the generatedPaymentSendResultconst rather than raw string literals, with an explicitFAILUREcase sodefault:means only "unrecognised". The useSwap test's wholesale mock of@app/graphql/generatednow takes the enum fromjest.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 translatedReceiveScreen.invoicePaid.console.log(">>>>>>>>")debug lines are deleted — one dumped the full BreezreceivePaymentresponse (payment request included) into the retainedlog-bufferon every USD→BTC conversion.common.somethingWentWrongis replaced by the existingerrors.generic, and the pending copy by the existingSendBitcoinScreen.notConfirmed.app/i18n/is now byte-identical tomain.Test-infrastructure fix
__mocks__/@breeztech/breez-sdk-spark-react-native.jsexportedPaymentStatusas strings keyedComplete, while the real SDK (and app code such asapp/types/transactions.ts:108) uses numericCompleted. Any test exercising that comparison silently compared againstundefinedand 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.tsxplus 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: hardcodingpending, restoring theif (lnInvoice)guard, moving the submit error back intoerrorMsg, or removing the try/catch each turns them red.Full suite 70 suites / 488 tests green,
yarn check-codeclean (tsc, translations, codegen, graphql-inspector). Pre-existing@ts-ignore/no-else-returnlint in untouched parts ofuseSwap.tsdeliberately left alone to keep the diff reviewable.🤖 Generated with Claude Code
https://claude.ai/code/session_01NEoz7nBtdtsHyuYG5wNPQV