Skip to content

fix: keep receive amount across refresh - #2034

Open
jvsena42 wants to merge 7 commits into
masterfrom
fix/receive-amount-survives-refresh
Open

jvsena42 wants to merge 7 commits into
masterfrom
fix/receive-amount-survives-refresh

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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.start calls WalletRepo.refreshBip21, which called clearBip21State before creating the new invoice. That set bip21AmountSats to null and the note to "", so the new BIP21 and the new Lightning invoice were amountless. iOS refreshBip21 reads invoiceAmountSats and invoiceNote and resets them only when the Receive sheet appears.

Description

  • WalletRepo.refreshBip21 no 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.resetReceiveRequest clears the amount and note. AppViewModel calls 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.
  • The Receive sheet now remembers every invoice (by payment hash) issued during the visit and every address shown in it. The invoice cached from before the visit is left out, read from the wallet state and from the cache store so a cache load that finishes after Receive opened does not add it: opening Receive replaces it before anything is shown, so a late payment of an invoice shared in an earlier visit does not close this one. A Receive sheet that replaces an open one inherits the requests that one showed. A payment of any of them closes the sheet and resets the request. Before, only the latest invoice was matched, so a payment processed after a foreground refresh had replaced the invoice left Receive open on a new unpaid invoice for the same amount. WalletState carries the payment hash of the shown invoice for this; for a cache entry saved without a hash it is parsed from the invoice.
  • The note typed in Edit stays in the edit screen until Continue. Before, every keystroke wrote it to the request, so a refresh while typing would have issued an invoice with a half-typed note. Back from Edit now discards an unconfirmed note. The edit state is saved across an activity recreation.
  • The open-time reset runs once per Receive sheet (WalletViewModel.openReceive, keyed by the sheet's presentationId). 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.
  • Opening the Receive sheet resets the request as before (AppViewModel.showSheet clears the amount, refreshReceiveState clears amount and note).

Callers of the refresh and of the clear, and what each does after this change:

Trigger Path Amount and note Invoice
App returns to foreground, Receive open ContentView ON_START → WalletViewModel.start → refreshBip21 kept (was: cleared) new invoice for the kept amount
App returns to foreground, Receive closed same already null / "" since the sheet closed new amountless invoice, as before
Node start from the foreground service LightningNodeService.setupService → refreshBip21 kept if Receive is open, else empty new invoice
Node restart, connection change, restore retry WalletViewModel.startNodeOwned → refreshBip21 kept if Receive is open, else empty new invoice
Restore finished WalletRepo init collector → refreshBip21 empty: Receive is not open with a request during a restore new invoice
Spark becomes ready WalletRepo init collector → refreshBip21 kept if Receive is open, else empty new invoice (Spark or LDK is chosen in LightningRepo.createInvoice, unchanged)
Receive sheet opens ReceiveSheet → WalletViewModel.openReceive → refreshReceiveState → clearBip21State, once per sheet cleared, unchanged new amountless invoice
Activity recreated with Receive open (dark mode, font scale, locale) openReceive with the same presentationId does nothing; the ON_START that follows runs WalletViewModel.start → refreshBip21 kept (was: cleared) new invoice for the kept amount
Receive sheet closes (dismiss, replaced by another sheet, payment received), in foreground or background AppViewModel sheet observer → resetReceiveRequest cleared at close (was: left in state until the next refresh or open) cached invoice untouched until the next refresh, as before
Payment received for the shown invoice or address refreshBip21ForEvent invalidates the invoice or rotates the address; AppViewModel.closeSettledReceiveSheet closes the sheet cleared by the close settled invoice dropped, unchanged; the next refresh creates an amountless one
Payment received for an invoice this visit showed earlier (replaced by an edit or a refresh) ReceiveSheetContext.isSettledBy matches the payment hash → closeSettledReceiveSheet cleared by the close (was: sheet stayed open) the unpaid replacement stays cached until the next refresh or open, which replaces it
Channel ready / closed refreshBip21ForEvent kept, unchanged unchanged
Retry after an invoice error retryReceiveInvoice kept, unchanged unchanged
Edit saved updateBip21Invoice set by the user, 0 included unchanged
Address type changed refreshReceiveAddressAfterTypeChange kept, unchanged unchanged
Wallet wipe resetState → WalletState() cleared, unchanged cleared, unchanged

Stale invoices: refreshBip21 has no reuse path. Each call runs createInvoice and replaces bolt11 and bip21 together, so an expired invoice is replaced by the same call. While it runs the Lightning tabs show the loading state. If createInvoice fails, the error flag is set and the Lightning tabs show the retry view instead of a QR, as on master; the previous invoice stays in state behind that view, also as on master. The number of refreshes on foreground is unchanged: this PR adds no trigger.

  • An amount cleared to 0 in Edit now means no amount: WalletRepo.updateBip21Invoice stores null and issues an amountless invoice. Before, it issued an invoice for 0 msat and a BIP21 with amount=0, which the next refresh replaced on master and would have kept here.

Out of Scope

  • WalletRepo.refreshBip21: a foreground start plus a Spark-ready transition can each run a refresh, as on master; they are serialized and the last invoice wins.
  • After a late payment closes Receive, the replacement invoice created by the foreground refresh stays in the cache, unpaid and for the old amount, until the next refresh or the next time Receive opens; Receive never shows it, because opening Receive creates a new invoice.
  • EditInvoiceScreen: the hardware-wallet edit still writes the amount straight to the request on Continue, as on master; its note is now written at the same moment instead of on each keystroke.
  • After returning from the background, Receive shows the previous invoice, which can be expired, for about 8–11 s between the node reaching Running and the refresh. Same on 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.
  • After an activity recreation (night-mode toggle) the open Receive sheet is drawn about 140 px higher until it is closed and reopened. Observed on the device run; likely the same on master, since nothing here touches the sheet layout, but not verified there.
  • CJIT: the Receive sheet has no CJIT invoice path on 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 through showSheet, which cancels the pending Receive. No re-check was added.
  • ReceiveSheet: an activity recreation still re-runs the start-route navigation (LaunchedEffect(startRoute)), as on master; 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

  • J1: new 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 resets

Manual Tests

  • 1. Issue repro: Receive → Edit → 4 000 sats → QR; Home; reopen Bitkit → BIP21 has 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 did
  • 2. Receive → Edit → 4 000 sats; pay the invoice → received sheet shows, Receive closes; open Receive → no amount, amountless invoice, Edit empty — needs a payer
  • 3. Receive → Edit → 4 000 sats; Home; wait past the invoice expiry (or set the device clock forward); reopen Bitkit → a new unexpired 4 000-sat invoice is shown, never the expired one — waiting for expiry is not in Capabilities
  • 4. Receive → Edit → 4 000 sats; close the sheet; Home and back; open Receive → no amount, amountless invoice — covered by J1's last steps
  • 5. Repeat 1 with a PIN and "require on launch" enabled → amount kept after unlocking
  • 6. Repeat 1 on a wallet with no Spark and an amount above inbound capacity → Savings BIP21 keeps the amount, no Lightning invoice, as before backgrounding
  • 7. Receive → Edit → 4 000 sats, copy the invoice; Home; pay the copied invoice while Bitkit is in the background with background payments off, so the payment is processed after reopening; reopen Bitkit → the received sheet shows and Receive is closed, not left open on a new 4 000-sat QR; open Receive → no amount — needs a payer and a payment processed after foreground
  • 9. Receive → Edit → 4 000 sats and a note → QR; toggle dark mode (adb shell cmd uimode night yes, then no) → 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 amount
  • 10. Visit 1: Receive, copy invoice A, close. Visit 2: open Receive, Edit → 4 000 sats, show the QR; pay invoice A → Receive stays open on the 4 000-sat request — needs a payer
  • 8. Receive → Edit → type a note, do not tap Continue; Home and back → the typed note is still in the field and the QR behind it has no note; Back → the note is discarded; Edit again → empty note

Automated Checks

  • added WalletRepoTest.kt — a refresh keeps amount, note and tags and creates a new invoice for that amount
  • added WalletRepoTest.kt — an amount cleared to 0 becomes no amount, with an amountless invoice, and stays so across a refresh
  • added WalletRepoTest.kt — after the request is reset a refresh creates an amountless invoice, also after a payment settled the invoice
  • added WalletRepoTest.kt — a refresh whose invoice fails flags the error and keeps the request
  • added WalletRepoTest.kt — the payment hash of the cached invoice is exposed and cleared when it settles
  • added WalletRepoTest.kt — guard, passes on master too: opening Receive (refreshReceiveState) still resets the request
  • added AppViewModelSendFlowTest.kt — a payment of the first invoice arriving after a refresh replaced it closes Receive and resets the request
  • added AppViewModelSendFlowTest.kt — a payment of any invoice, or to any address, issued during the visit closes Receive; one issued for an earlier visit does not
  • added AppViewModelSendFlowTest.kt — hideSheet and a replacing showSheet reset the request; it is kept while Receive stays open
  • added ReceiveInvoiceEditStateTest.kt — the edit note starts from the request and stays local while typing
  • added WalletViewModelTest.kt — the confirmed note is passed to the repository
  • added AppViewModelSendFlowTest.kt — a payment of the invoice cached before Receive opened does not close the sheet once replaced
  • added AppViewModelSendFlowTest.kt — an on-chain payment found only in the transaction outputs closes Receive after the address rotated
  • updated AppViewModelSendFlowTest.kt — three settled-invoice tests now issue the invoice after Receive opens, as the app does
  • added WalletRepoTest.kt — a cached invoice saved without a payment hash gets it parsed on load
  • added WalletViewModelTest.kt — openReceive resets the request once per sheet presentation and again for a new one
  • added ReceiveInvoiceEditStateTest.kt — the saver restores the edit note, mode and return tab
  • added AppViewModelSendFlowTest.kt — an invoice the cache load publishes after Receive opened does not close the sheet when paid
  • added AppViewModelSendFlowTest.kt — a payment of an invoice shown by a replaced Receive sheet closes the sheet replacing it
  • updated WalletViewModelTest.kt — openReceive reports whether it opened, which gates clearing the Edit amount
  • added AppViewModelSendFlowTest.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 it

Evidence

Unit checks. At 80fb63d01, with a clean test task (cleanTestDevDebugUnitTest, no cached results): compileDevDebugKotlin passes; testDevDebugUnitTest passes for WalletRepoTest (110), LightningRepoTest (283), WalletViewModelTest (92), AppViewModelSendFlowTest (805) and ReceiveInvoiceEditStateTest (9); detekt --rerun-tasks and lintDevDebug pass. 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 (3 WalletRepoTest tests), the repository reset removed (2), the cached payment hash not exposed (1), the sheet-close reset removed (3 AppViewModelSendFlowTest tests), 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 (at 7f216a7d8): 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 (at 5c705158b): openReceive always reporting an open (1), the cache store not read (1), the replaced sheet's requests not carried over (1). The refreshReceiveState guard and the "preserves / is kept" tests of the first round pass with and without the change by design. Device-run round (at 80fb63d01): zero not normalised (1 WalletRepoTest test).

Device run at bee1837f0 on 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.

Case Result
J1 Steps 1–11, 13, 14 pass. Step 12 failed at bee1837f0: clearing the amount gave amount=0 and a 0-msat invoice, created at "QR Code" before the background. Fixed by the last commit; not re-run on a device.
1 Pass: 4 000 kept, new invoice 24 s after returning, Edit shows 4 000
2 Pass: paid, Receive closed, reopen amountless
3 Pass, with the device clock moved forward 25 h in the background: new unexpired 4 000-sat invoice 35 s after returning. The expired invoice was visible for about 11 s before it (#2045).
4 Pass: closed sheet, amountless after returning
5 Pass: PIN on return, 4 000 kept after unlock
6 Pass on a testnet build with no channel: Savings BIP21 keeps the amount, no invoice
7 Pass: invoice paid after the refresh replaced it, Receive closed, reopen amountless
8 Pass: typed note kept in the field, not in the request; Back discards it
9 Pass: amount, note, typed Edit amount and note kept across night-mode toggles; a new invoice 5–8 s after each toggle
10 Pass: paying the earlier visit's invoice shows the received sheet over Receive; the 4 000 request stays open behind it

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

  • J1 step 12 and the zero-amount fix are not re-run on a device after the last commit; the unit test covers them.
  • Case 1 on a mainnet build and the optional case 7b were not run.
  • Case 6 ran on testnet without a channel, not with an amount above a non-zero inbound capacity.
  • No instrumented test covers the once-per-sheet open, or the Edit amount it keeps, through an actual activity recreation; the guard is unit-tested in WalletViewModelTest.kt and case 9 covered it on the device.
  • The full unit suite was not run locally.

Models used

  • Planning/scoping: claude-fable-5-2 (reasoning: Not exposed)
  • Implementation: claude-fable-5-2 (reasoning: Not exposed)
  • Review: claude-fable-5-2 (reasoning: Unknown)
  • Review rounds: 4

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

@jvsena42 jvsena42 self-assigned this Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from d97deff (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@jvsena42
jvsena42 marked this pull request as ready for review November 25, 2026 19:41
@jvsena42
jvsena42 requested review from a team, ovitrif and piotr-iohk and removed request for a team November 25, 2026 19:41
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Keeps the Receive amount and note when the app refreshes an open request.

  • Receive refreshes keep the edited amount and note.
  • Closing Receive clears the request for the next visit.
  • Payments still close Receive after its request has been replaced.
  • Typed Receive notes stay in Edit until Continue.

Scope acknowledgments from jvsena42: the expired-invoice display gap, unpaid replacement remaining cached after a late payment, duplicate refresh triggers, direct hardware amount writes, and repeated deep-link navigation on recreation are known or deferred.

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]
Loading

Reviews (1) · Last reviewed commit: "fix: treat a zero receive amount as no a..." · Reviewed by Greptile

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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: observeReceiveSheetClosed compares presentationId, and every Sheet.Receive gets a fresh UUID, so dismiss, replace and payment-close all reach resetReceiveRequest before the next refreshBip21.
  • Recreation re-running the open reset: openReceive is keyed on presentationId and WalletViewModel is activity-scoped, so a recreation is a no-op; key(presentationId) around ReceiveSheet scopes the rememberSaveable edit state to one presentation.
  • Pre-visit invoice closing the new sheet: cachedBolt11s reads both walletState and the cache store, and withRequest drops a bolt11 in that set together with its payment hash.
  • Half-typed note reaching an invoice: the note lives in ReceiveInvoiceEditState until Continue; updateInvoice and updateOnchainInvoice both pass it explicitly.
  • Zero amount: updateBip21Invoice and setBip21AmountSats both normalise 0 to null, so no 0 msat invoice and no amount=0 BIP21.
  • Payment hash missing for an old cache entry: the cache load falls back to QuickPayInvoiceParser, the same Bolt11Invoice.fromStr(...).paymentHash() used in setBolt11Locked.

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)

ovitrif
ovitrif previously approved these changes Nov 25, 2026

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

utAck

@piotr-iohk

Copy link
Copy Markdown
Collaborator

@jvsena42 please resolve conflicts.

@jvsena42

Copy link
Copy Markdown
Member Author

Conflicts with master are resolved in merge commit d97deff.

@jvsena42
jvsena42 requested a review from ovitrif November 26, 2026 10:57

@piotr-iohk piotr-iohk 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.

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 blanking bip21 in beforeLock) and add a unit regression assertion in WalletRepoTest.kt verifying bip21 retains amount and message when refreshBip21 fails after an address-check failure.
  • Wait for the in-progress lint, compose-ui / ui-tests, and e2e-tests-local checks 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 sats with note coffee, 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 encode bitcoin:<address>?amount=0.00004&message=coffee rather 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 sats and note coffee, tap QR Code, background Bitkit and return; then reopen Edit, clear amount to 0 and note to empty, tap QR Code, and verify the Hardware QR/Copy keeps amount=0.00004&message=coffee across 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) } },

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.

[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).

This branch has not been deployed

No deployments
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.

[Bug]: Receive amount resets after backgrounding and reopening the app

4 participants