Repository navigation
Conversation
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryKeeps the Receive amount and note when the app refreshes an open request.
Scope acknowledgments from Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Open Receive] --> B[Reset once per presentationId]
B --> C[Create invoice]
C --> D[Edit and confirm request]
D --> E[Refresh while Receive stays open]
E --> F[Create new invoice with kept amount and note]
F --> G[Remember requests from this visit]
G --> H[Payment matches a remembered request]
H --> I[Close Receive]
I --> J[Clear amount and note]
Reviews (1) · Last reviewed commit: "fix: treat a zero receive amount as no a..." · Reviewed by Greptile |
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: None.
QA for 80fb63d:
Tested on a Pixel 10 Pro emulator, Android 16 (API 36), dev/regtest build.
Receive amount and note survive backgrounding ✅ J1 passes, including clearing the amount.
A 4,000-sat request with coffee keeps its amount and note after Home/return and gets a new, unexpired 4,000-sat invoice. An unconfirmed tea note survives the round trip; Back discards it. Clearing the amount produces an amountless invoice immediately and after refresh. Closing and reopening clears both amount and note. QR payloads were read from UI semantics and the BOLT11 amount and expiry decoded.
J1-2x.2x.mp4
Check: receive regression tests ✅ Repository, sheet, viewmodel, and edit-state checks pass.
WalletRepoTest, LightningRepoTest, WalletViewModelTest, AppViewModelSendFlowTest, and ReceiveInvoiceEditStateTest pass at 80fb63d. The dev APK was built from that head with assembleDevDebug.
The remaining manual cases were not re-driven: the author's device report covers cases 2–10 at bee1837, and their positive-amount, payment, PIN, and recreation paths are unchanged by the final zero-amount normalization. Case 6 used a testnet wallet without a channel; the variant above nonzero inbound capacity remains undriven. The mainnet variant was left out because it needs a mainnet wallet. The pre-existing stale-invoice display gap remains tracked in synonymdev/bitkit-android#2045.
Reviewed the full 12-file diff, including callers, cancellation, request history, cache loading, and amount units. Payment matching, PIN, and activity recreation rely on the regression checks and the unchanged author-tested paths above.
Twin: no matching iOS PR; iOS already preserves invoiceAmountSats and invoiceNote during refreshBip21.
Reviewed by gpt-6.1-sol-high
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Keeps the Receive amount and note across a foreground refreshBip21, resets the request when the sheet closes, and closes the sheet on a late payment of any invoice issued during the visit. Reviewed 80fb63d, full tier, statically: on bitkit-android an auto review does not build the branch, so nothing here was compiled or run.
What I checked, and 6 candidates I ruled out
Read in full (diff and surrounding code): WalletRepo.kt (refreshBip21, refreshReceiveState, updateBip21Invoice, setBolt11Locked, cache load, invalidateSettledReceiveInvoice, refreshBip21ForEvent), AppViewModel.kt (ReceiveSheetContext, observeReceiveSheetInvoice, observeReceiveSheetClosed, newReceiveSheetContext, showSheet, hideSheet, handleLdkEvent, closeSettledReceiveSheet), ReceiveSheet.kt, EditInvoiceScreen.kt, WalletViewModel.openReceive, ContentView.kt Receive branch.
Call sites traced: every refreshBip21 caller (WalletViewModel.start, LightningNodeService.setupService, restore and Spark-ready collectors), setBip21AmountSats, updateBip21Description, updateBip21Invoice, every Sheet.Receive(...) construction.
CI: CI and Lint green on bee1837f; no run reported yet for 80fb63d, whose diff from bee1837f is the zero-amount normalisation and its test.
Ruled out
- Amount leaking into a later amountless refresh:
observeReceiveSheetClosedcomparespresentationId, and everySheet.Receivegets a fresh UUID, so dismiss, replace and payment-close all reachresetReceiveRequestbefore the nextrefreshBip21. - Recreation re-running the open reset:
openReceiveis keyed onpresentationIdandWalletViewModelis activity-scoped, so a recreation is a no-op;key(presentationId)aroundReceiveSheetscopes therememberSaveableedit state to one presentation. - Pre-visit invoice closing the new sheet:
cachedBolt11sreads bothwalletStateand the cache store, andwithRequestdrops a bolt11 in that set together with its payment hash. - Half-typed note reaching an invoice: the note lives in
ReceiveInvoiceEditStateuntil Continue;updateInvoiceandupdateOnchainInvoiceboth pass it explicitly. - Zero amount:
updateBip21InvoiceandsetBip21AmountSatsboth normalise0tonull, so no 0 msat invoice and noamount=0BIP21. - Payment hash missing for an old cache entry: the cache load falls back to
QuickPayInvoiceParser, the sameBolt11Invoice.fromStr(...).paymentHash()used insetBolt11Locked.
Merge confidence: 4/5, reviewed from the code only (not built here) and CI has not yet reported on the head commit.
Reviewer model: claude-opus-5-5
Reasoning effort: Unknown (not reported to this review session)
|
@jvsena42 please resolve conflicts. |
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Conflicts with |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at d97deff8.
1 actionable finding — resolve or provide an evidence-backed rebuttal.
The core fix for #1971 — preserving Receive amount, note, and tags across refreshBip21, resetting the request on sheet close, tracking visit-scoped invoices/addresses for settlement dismissal, guarding open-time reset per presentationId, buffering the Edit note locally with a Saver, and normalizing 0 to null — is well structured and covered by unit tests (WalletRepoTest.kt, WalletViewModelTest.kt, AppViewModelSendFlowTest.kt, ReceiveInvoiceEditStateTest.kt). One MEDIUM defect was found in WalletRepo.refreshBip21: blanking bip21 = "" in beforeLock strips the saved amount and note from the Savings tab while the address check runs and leaves Savings stuck on a bare address (disagreeing with Edit) if both address check and invoice creation fail. No prior review findings exist on this PR.
Validation & CI: At d97deff8, build-and-test and detekt passed; lint, compose-ui / ui-tests, and the e2e-tests-local suites were still in progress at review time. No local build or tests were executed in this review.
Cross-platform comparison: Checked synonymdev/bitkit-ios at cc62f525 (Bitkit/ViewModels/WalletViewModel.swift, ReceiveSheet.swift, ReceiveEdit.swift, journeys/receive/). iOS similarly keeps invoiceAmountSats/invoiceNote during refreshBip21, buffers note locally in ReceiveEdit, normalizes 0 to nil, and leaves bip21 intact during refreshBip21 until the new URI commits (avoiding F1). Intentional platform difference: iOS reuses an unexpired matching invoice when forceRefreshBolt11 == false, whereas Android issues a fresh invoice on every refreshBip21. receive-amount-survives-background.xml has no iOS counterpart yet (no twin PR).
Recommended before device testing:
- Resolve F1 in
WalletRepo.refreshBip21(stop blankingbip21inbeforeLock) and add a unit regression assertion inWalletRepoTest.ktverifyingbip21retainsamountandmessagewhenrefreshBip21fails after an address-check failure. - Wait for the in-progress
lint,compose-ui / ui-tests, ande2e-tests-localchecks on d97deff8 to finish.
Device testing: Not performed in this review. Existing device evidence predates the merge commit d97deff8: the author reported cases 1–10 at bee1837f (before the zero-amount fix) and ovi-reviewer[bot] reported J1 passing at 80fb63d0. Coverage gaps from the author checklist remain open: J1 on the current head, Case 6 with a nonzero-inbound channel below the entered amount, and Case 1 on a mainnet build.
Suggested additional test cases:
- Android — Savings tab preserves amount and note across backgrounding and refresh failure: Open Receive, Edit to
4,000 satswith notecoffee, tap QR Code, switch to Savings, background Bitkit for 10s, and return (also test returning while Electrum/invoice refresh fails transiently). Expected: Savings QR, Copy, and Details continue to encodebitcoin:<address>?amount=0.00004&message=coffeerather than falling back to a bare address. - Android — Hardware tab edit survives backgrounding and clears on zero: With a paired hardware wallet on the Hardware tab, tap Edit, enter
4,000 satsand notecoffee, tap QR Code, background Bitkit and return; then reopen Edit, clear amount to0and note to empty, tap QR Code, and verify the Hardware QR/Copy keepsamount=0.00004&message=coffeeacross backgrounding and reverts to a plain address after clearing.
Findings
- [MEDIUM] Keep bip21 intact during refreshBip21 so Savings does not lose amount and note — inline at
app/src/main/java/to/bitkit/repositories/WalletRepo.kt:347.
Reviewer model: gemini-4-neon
Reasoning effort: high
| /** Creates a fresh invoice and BIP21 for the current request, keeping its amount, description and tags. */ | ||
| suspend fun refreshBip21(): Result<Unit> = updateReceiveState( | ||
| beforeLock = { clearBip21State(clearTags = false) }, | ||
| beforeLock = { _walletState.update { it.copy(bip21 = "", hasReceiveInvoiceError = false) } }, |
There was a problem hiding this comment.
[MEDIUM] Keep bip21 intact during refreshBip21 so Savings does not lose amount and note
Trigger: Open Receive, save an amount (e.g. 4,000 sats) and note (e.g. coffee), switch to the Savings tab, and trigger WalletRepo.refreshBip21() (for example by backgrounding and returning to Bitkit). This manifests transiently while checkAddressUsage runs and persistently when both checkAddressUsage and lightningRepo.createInvoice fail (e.g. transient network/Electrum+Spark failure while connectivity still reports CONNECTED).
Mechanism: WalletRepo.refreshBip21() (WalletRepo.kt:346-352) blanks bip21 = "" in beforeLock while keeping bip21AmountSats and bip21Description. Because ReceiveTab.SAVINGS.usesLightningInvoice() is false (ReceiveInvoiceUtils.kt:149), getReceiveInvoiceDisplayMode (ReceiveInvoiceUtils.kt:23-33) keeps Savings in QR/DETAILS mode with no LOADING spinner and no ERROR view. getInvoiceForTab (ReceiveInvoiceUtils.kt:60-64), getSavingsCopyText (ReceiveInvoiceUtils.kt:99-102, called at ReceiveQrScreen.kt:465-468), and ReceiveDetailsView (ReceiveQrScreen.kt:737-740) all pass walletState.bip21 to removeLightningFromBip21, which returns the bare onchainAddress whenever bip21 is blank (ReceiveInvoiceUtils.kt:112). If refreshReusableReceiveAddressOrThrow() throws on checkAddressUsage, updateBip21Url() (WalletRepo.kt:617) is skipped, refreshAddressForInvoice() swallows the failure because onchainAddress is non-empty (WalletRepo.kt:589), and if createInvoice (WalletRepo.kt:1027) then fails, setBolt11Locked is never reached so walletState.bip21 stays "".
Consequence: On the Savings tab, the QR code, Copy button, and Details address drop ?amount=...&message=... and fall back to a bare amountless Bitcoin address during the Electrum check — and persistently with no error or retry UI if checkAddressUsage and createInvoice both fail — while tapping Edit still shows 4,000 sats and coffee. A payer scanning or copying the Savings request would receive an amountless address instead of the requested amount.
Expected behavior: Do not blank bip21 in refreshBip21()'s beforeLock (only clear hasReceiveInvoiceError = false), matching updateBip21Invoice(), retryReceiveInvoice(), and iOS WalletViewModel.refreshBip21. AUTO and SPENDING are already hidden behind LOADING (isReceiveInvoiceUpdating) during refresh and ERROR (hasReceiveInvoiceError) on failure, including nearby NFC/BT offers (nearbyReceiveRequest).
Evidence basis: Source analysis at d97deff8 (not executed on a device).
Fixes #1971
This PR keeps the edited Receive amount, note and tags when the receive request is refreshed while the Receive sheet stays open, for example after Home and back to the app.
Cause: on foreground
WalletViewModel.startcallsWalletRepo.refreshBip21, which calledclearBip21Statebefore creating the new invoice. That setbip21AmountSatstonulland the note to"", so the new BIP21 and the new Lightning invoice were amountless. iOSrefreshBip21readsinvoiceAmountSatsandinvoiceNoteand resets them only when the Receive sheet appears.Description
WalletRepo.refreshBip21no longer clears the amount and note. It still blanks the shown BIP21 before it runs and still creates a new invoice on every call, now for the amount and note of the open request. Tags were already kept and moved to the new invoice.WalletRepo.resetReceiveRequestclears the amount and note.AppViewModelcalls it whenever the current sheet stops being that Receive sheet (dismissed, replaced, closed by a payment), from the sheet state itself and not from composition, so a sheet closed while the app is in the background is reset before the next refresh. Without it, an amount left over from a closed sheet would be used by the next refresh; before, that refresh cleared it.WalletStatecarries the payment hash of the shown invoice for this; for a cache entry saved without a hash it is parsed from the invoice.WalletViewModel.openReceive, keyed by the sheet'spresentationId). Before, an activity recreation (dark mode, font scale, locale) re-ran it and cleared the amount and note of the open request, the same symptom as the issue through another trigger. The Edit amount input is cleared in the same once-per-sheet step, so a recreation on the Edit screen keeps the typed amount.AppViewModel.showSheetclears the amount,refreshReceiveStateclears amount and note).Callers of the refresh and of the clear, and what each does after this change:
ContentViewON_START →WalletViewModel.start→refreshBip21null/""since the sheet closedLightningNodeService.setupService→refreshBip21WalletViewModel.startNodeOwned→refreshBip21WalletRepoinit collector →refreshBip21WalletRepoinit collector →refreshBip21LightningRepo.createInvoice, unchanged)ReceiveSheet→WalletViewModel.openReceive→refreshReceiveState→clearBip21State, once per sheetopenReceivewith the samepresentationIddoes nothing; the ON_START that follows runsWalletViewModel.start→refreshBip21AppViewModelsheet observer →resetReceiveRequestrefreshBip21ForEventinvalidates the invoice or rotates the address;AppViewModel.closeSettledReceiveSheetcloses the sheetReceiveSheetContext.isSettledBymatches the payment hash →closeSettledReceiveSheetrefreshBip21ForEventretryReceiveInvoiceupdateBip21InvoicerefreshReceiveAddressAfterTypeChangeresetState→WalletState()Stale invoices:
refreshBip21has no reuse path. Each call runscreateInvoiceand replacesbolt11andbip21together, so an expired invoice is replaced by the same call. While it runs the Lightning tabs show the loading state. IfcreateInvoicefails, the error flag is set and the Lightning tabs show the retry view instead of a QR, as onmaster; the previous invoice stays in state behind that view, also as onmaster. The number of refreshes on foreground is unchanged: this PR adds no trigger.WalletRepo.updateBip21Invoicestoresnulland issues an amountless invoice. Before, it issued an invoice for 0 msat and a BIP21 withamount=0, which the next refresh replaced onmasterand would have kept here.Out of Scope
WalletRepo.refreshBip21: a foreground start plus a Spark-ready transition can each run a refresh, as onmaster; they are serialized and the last invoice wins.EditInvoiceScreen: the hardware-wallet edit still writes the amount straight to the request on Continue, as onmaster; its note is now written at the same moment instead of on each keystroke.master; tracked in Receive shows the previous, possibly expired invoice for seconds after returning from the background #2045, which also covers an invoice expiring while Receive stays open in the foreground.master, since nothing here touches the sheet layout, but not verified there.master; nothing to change.AppViewModel.showSheet: opening Receive now reads the cache store before it sets the sheet. No sheet can be written directly in that gap: a timed sheet is refused while a sheet transition runs, and a pairing code goes throughshowSheet, which cancels the pending Receive. No re-check was added.ReceiveSheet: an activity recreation still re-runs the start-route navigation (LaunchedEffect(startRoute)), as onmaster; it only matters for a Receive opened by a deep link to Edit or Add Tag.Design
N/A — no UI changes.
Preview
Emulator recordings of the device run at
bee1837f0(see Evidence).Case 1, issue repro: 4 000 sats, Home, back; amount kept, new invoice.
case1.mp4
Case 2: the request is paid, Receive closes, reopening shows no amount.
case2.mp4
Case 9: night-mode toggles keep the request and the typed Edit amount and note.
case9.mp4
Case 10: paying an invoice from an earlier visit leaves the current request open.
case10.mp4
QA Notes
Setup
Dev build (
to.bitkit.dev, regtest) of this branch on a device or emulator, with a wallet that can issue Lightning invoices: Spark connected (default on dev) or a channel to the staging LSP with at least 4 000 sats inbound. A payer for case 2:./lsp POST /regtest/lightning/pay '{"invoice":"<bolt11>"}'or a second wallet. Read requests with Copy on the QR screen and decode the invoice.Journeys
receive-amount-survives-background.xml— amount and note survive Home and back with a new invoice for the same amount; a cleared amount stays cleared; close and reopen resetsManual Tests
amount=0.00004, the invoice is a new 4 000-sat invoice, Edit shows 4 000 — drivable, covered by J1; listed for the mainnet-flavor check the issue didadb shell cmd uimode night yes, thenno) → amount and note unchanged, and a new invoice for the same amount a few seconds after each toggle; in Edit with a typed, unconfirmed amount and note, toggle again → both are still there, and Continue issues the request for the typed amountAutomated Checks
WalletRepoTest.kt— a refresh keeps amount, note and tags and creates a new invoice for that amountWalletRepoTest.kt— an amount cleared to 0 becomes no amount, with an amountless invoice, and stays so across a refreshWalletRepoTest.kt— after the request is reset a refresh creates an amountless invoice, also after a payment settled the invoiceWalletRepoTest.kt— a refresh whose invoice fails flags the error and keeps the requestWalletRepoTest.kt— the payment hash of the cached invoice is exposed and cleared when it settlesWalletRepoTest.kt— guard, passes onmastertoo: opening Receive (refreshReceiveState) still resets the requestAppViewModelSendFlowTest.kt— a payment of the first invoice arriving after a refresh replaced it closes Receive and resets the requestAppViewModelSendFlowTest.kt— a payment of any invoice, or to any address, issued during the visit closes Receive; one issued for an earlier visit does notAppViewModelSendFlowTest.kt—hideSheetand a replacingshowSheetreset the request; it is kept while Receive stays openReceiveInvoiceEditStateTest.kt— the edit note starts from the request and stays local while typingWalletViewModelTest.kt— the confirmed note is passed to the repositoryAppViewModelSendFlowTest.kt— a payment of the invoice cached before Receive opened does not close the sheet once replacedAppViewModelSendFlowTest.kt— an on-chain payment found only in the transaction outputs closes Receive after the address rotatedAppViewModelSendFlowTest.kt— three settled-invoice tests now issue the invoice after Receive opens, as the app doesWalletRepoTest.kt— a cached invoice saved without a payment hash gets it parsed on loadWalletViewModelTest.kt—openReceiveresets the request once per sheet presentation and again for a new oneReceiveInvoiceEditStateTest.kt— the saver restores the edit note, mode and return tabAppViewModelSendFlowTest.kt— an invoice the cache load publishes after Receive opened does not close the sheet when paidAppViewModelSendFlowTest.kt— a payment of an invoice shown by a replaced Receive sheet closes the sheet replacing itWalletViewModelTest.kt—openReceivereports whether it opened, which gates clearing the Edit amountAppViewModelSendFlowTest.kt— guard, passes without any change in this PR: a pairing code requested while Receive is still reading the cache replaces the pending Receive instead of being overwritten by itEvidence
Unit checks. At
80fb63d01, with a clean test task (cleanTestDevDebugUnitTest, no cached results):compileDevDebugKotlinpasses;testDevDebugUnitTestpasses forWalletRepoTest(110),LightningRepoTest(283),WalletViewModelTest(92),AppViewModelSendFlowTest(805) andReceiveInvoiceEditStateTest(9);detekt --rerun-tasksandlintDevDebugpass. The full unit suite was not run locally and is left to CI.Each new test was run against the code with its change reverted and failed. First fix round (at
2bbcf8a1c): the refresh clearing the request again (3WalletRepoTesttests), the repository reset removed (2), the cached payment hash not exposed (1), the sheet-close reset removed (3AppViewModelSendFlowTesttests), payment-hash and address history not matched (3, one shared with the reset), the note not passed on Continue (1), the edit note not seeded (1). Second round (at7f216a7d8): the cached invoice tracked again (1), the outputs match removed (1), the hash parse fallback removed (1), the once-per-sheet guard removed (1), the saver dropping the note (1). Third round (at5c705158b):openReceivealways reporting an open (1), the cache store not read (1), the replaced sheet's requests not carried over (1). TherefreshReceiveStateguard and the "preserves / is kept" tests of the first round pass with and without the change by design. Device-run round (at80fb63d01): zero not normalised (1WalletRepoTesttest).Device run at
bee1837f0on an emulator (API 35, dev build, regtest, payer: a host ldk-node over a 200 000-sat channel). No crash or ANR in any case. One invoice per return or toggle, never a duplicate. No amount or note lost or leaked; no 4 000-sat invoice created after a close.bee1837f0: clearing the amount gaveamount=0and a 0-msat invoice, created at "QR Code" before the background. Fixed by the last commit; not re-run on a device.Also run: an on-chain payment to the shown address closes Receive and rotates the address; an amountless request paid 1 000 sats closes it.
Gaps
WalletViewModelTest.ktand case 9 covered it on the device.Models used
claude-fable-5-2(reasoning: Not exposed)claude-fable-5-2(reasoning: Not exposed)claude-fable-5-2(reasoning:Unknown)Metadata note: the implementation model id comes from the session's environment, which does not expose a reasoning setting to the agent. The review model was reported by the coordinating session; its reasoning effort was not recorded.
🤖 Generated with Claude Code