Skip to content

fix: drop late send scans on enter manually - #2035

Merged
ovitrif merged 3 commits into
masterfrom
fix/send-scan-visit-camera-paste
Nov 25, 2026
Merged

ovitrif merged 3 commits into
masterfrom
fix/send-scan-visit-camera-paste

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #2029

This PR drops a camera, gallery or paste scan that is still decoding when the payer leaves the Send recipient screen.

Description

  • Fixes a late scan result replacing the screen the payer moved to, for example the LNURL amount screen opening over Enter Manually.

Cause: the recipient screen keeps the decode job of a request so that Enter Manually, Contacts and closing Send can cancel it, but only for nearby reads (NFC and Bluetooth). Camera, gallery and paste scans were not kept, so their result still routed. A camera frame decoded after the tap, while the recipient screen was still leaving, also started a new scan.

Changes:

  • Every request continued from the recipient or address screen and every paste is kept as the visit's scan, the same handle nearby reads and Send's own scanner already use.
  • From Enter Manually, Contacts or Send closing until the recipient screen is shown again, reads the recipient screen delivers on its own (camera, gallery, nearby) are dropped. An address the payer continues on the address screen and a paste are not affected.
  • A scan that closes Send itself (a pasted contact key, a login request, a withdraw) releases the handle without being cancelled, so a later Send visit cannot cancel work it still does, such as refreshing the contact's payment methods.

Checked:

  • A new scan on the same visit still works: the same code scanned again once the recipient screen is back routes, and a paste that replaces a scan still decoding routes while the replaced scan does not.
  • A repeated read of the code being decoded starts no new job and keeps the handle of the running one, so it stays cancellable.
  • Cancelling the visit's scan never stops a payment: the job sends none. After it routes to the confirmation it only estimates fees, which stop with it for a request the payer left.

Out of Scope

  • A scan deferred while the wallet is locked or behind a scan that must complete is queued without a job and is not cancelled by Enter Manually, as for nearby reads today.
  • Fee estimates after routing still run in the scan's job. Moving them to their own job is left out.
  • A predictive-back swipe back to the recipient screen that lasts longer than the screen transition can drop one camera frame, and the analyzer's 2 s cooldown then delays the same QR code.
  • On Android 9 and older in split screen, an unfocused, paused Bitkit drops camera reads on the recipient screen until it is tapped.

Design

N/A — no UI changes.

Preview

Camera on a slow LNURL-pay QR, Enter Manually before it answers: the address screen stays after the lookup returns.

2035-camera-enter-manually.mp4

Back to the recipient screen, the same QR routes again.

2035-rescan-after-back.mp4

Camera on a QR, Contacts: nothing routes over the list; back on the recipient screen the QR routes.

2035-camera-contacts.mp4

Send closed with the camera on a QR, then reopened: Send does not reopen by itself and the camera reads on the new visit.

2035-close-reopen.mp4

QA Notes

Setup

Regtest devDebug build of this branch. An LNURL-pay QR code whose server answers slowly (throttle the phone's connection or use a slow endpoint) so the decode takes a few seconds.

Journeys

N/A — not drivable; see Manual Tests.

Manual Tests

  • 1. Open Send, scan the slow LNURL-pay QR with the camera and tap Enter Manually before the decode returns, keeping the camera on the QR → the address screen stays; the LNURL amount screen does not open — camera QR scan and connection throttling not in Capabilities
  • 2. Copy the slow LNURL-pay link, open Send, tap Paste and tap Enter Manually before the decode returns → the address screen stays — connection throttling not in Capabilities
  • 3. Open Send and scan a QR code without leaving the screen (a bolt11 invoice, then a slow LNURL-pay left to finish) → each routes to its amount or confirm screen as before — camera QR scan not in Capabilities
  • 4. After case 1, go back to the recipient screen and scan the same QR again → it routes — camera QR scan not in Capabilities
  • 5. On the address screen, paste an invoice and tap Continue → it routes as before
  • 6. With the camera on a QR code, tap Contacts, then go back to the recipient screen → nothing routes over Contacts; back on the recipient screen the QR routes — camera QR scan not in Capabilities
  • 7. Close Send with the camera on a QR code, then open Send again → Send does not reopen by itself; the camera, an NFC tap and the gallery read again on the new visit — camera QR scan and NFC tap not in Capabilities
  • 8. Send Bitkit to the background and back on the recipient screen, then scan a QR code → it routes — camera QR scan not in Capabilities
  • 9. With Paykit on, paste a saved contact's key in Send → the contact opens; open Send again and tap Enter Manually → the contact's payment methods still load

Automated Checks

  • added AppViewModelSendFlowTest.kt — a camera scan and a paste still decoding do not route after Enter Manually, and a camera scan does not route after Contacts
  • added AppViewModelSendFlowTest.kt — a repeated camera read keeps the decoding scan cancellable
  • added AppViewModelSendFlowTest.kt — a paste still preparing does not reopen Send after the sheet closes
  • added AppViewModelSendFlowTest.kt — a camera frame delivered after Enter Manually, Contacts or Send closing starts no scan, and the recipient screen reads again once it is shown
  • added AppViewModelSendFlowTest.kt — an address continued after Enter Manually routes, and a paste replacing a scan still decoding routes
  • added AppViewModelSendFlowTest.kt — a pasted contact's refresh is not cancelled by a later Send visit
  • added AppViewModelSendFlowTest.kt — a login request from the recipient camera or a paste still opens its sheet

Evidence

Device run on 2c9c6ad1d, API 35 emulator, regtest devDebug, no Spending balance (a routed LNURL shows "Unable To Pay (LNURL)" and closes Send; a routed invoice shows "Insufficient Spending Balance"), a local LNURL-pay server answering after 10 s, the camera fed from a QR image:

  • 1: the address screen stayed 60 s after the lookup returned; no Handling decoded or LNURL: line.
  • 2: paste → Enter Manually; the address screen stayed.
  • 3: a bolt11 and a slow LNURL-pay each routed without leaving the screen.
  • 4: back on the recipient screen the first scan started 1.5 s later and routed 10.4 s after the request (the server delay).
  • 5b (LNURL on the address screen) routed after Continue. 5 (invoice) is blocked without a Spending balance: the address validator shows "Insufficient Spending Balance" and keeps Continue disabled.
  • 6: the contact list stayed open 40 s with no toast; back on the recipient screen the QR routed.
  • 7: closing Send with the camera on a QR (and with a paste still decoding) left it closed for 43 s or more; on reopen the camera (1.1 s to scan) and the gallery (1.4 s to route) read again.
  • 8 and 8b: back from the background, scan in about 1 s and route in 2–3 s. The first of three attempts of case 8 showed a white camera preview for 45 s with no frames and no scan while the emulator was overloaded; the next two attempts passed with the same steps. With no frames there was nothing for the recipient-left check to drop, so this looks like the emulator camera, not this change.
  • 9: pasting a contact's key opened the contact in 3.4 s. Whether its payment methods still load could not be shown: the test contact has no Paykit endpoints and the refresh ended with a transport error.
  • Regression: the home scanner and a lightning: deep link each routed once.
  • No crashes, ANRs, stuck spinners or Send reopening in any case.

Run locally on 2c9c6ad1d, no device:

  • ./gradlew testDevDebugUnitTest --tests "to.bitkit.viewmodels.AppViewModelSendFlowTest" — 808 tests, 0 failures
  • The same run with the recipient-left check and the handle release switched off: the four tests for them fail (a frame after Enter Manually, after Contacts, after Send closes, and the pasted contact's refresh). An independent review found 6 of the earlier tests fail without the first commit's change.
  • ./gradlew compileDevDebugKotlin, ./gradlew detekt --rerun-tasks, ./gradlew lintDevDebug — passed

Gaps

  • Run on an emulator, not a phone. The NFC part of case 7 was not run (no NFC on the emulator).
  • Case 5 (invoice on the address screen) needs a Spending balance and was not run.
  • Case 9's payment-methods check was inconclusive (the test contact publishes no Paykit endpoints).
  • The recipient screen tells the view model it is shown from its lifecycle (on resume). That wiring has no unit test; device cases 4, 6, 7 and 8 passed on it.
  • The full unit test suite was not run locally, only AppViewModelSendFlowTest.kt; CI runs the rest.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium)
  • Implementation: claude-fable-5-2 (reasoning: medium)
  • Review: claude-opus-5-5 (reasoning: Unknown)
  • Review rounds: 1

Metadata note: the reviewer model was reported by the coordinating session; its reasoning effort was not passed on.

🤖 Generated with Claude Code

Camera, gallery and paste scans on the recipient screen are kept as the visit's scan, like nearby reads, so Enter Manually, Contacts and closing Send cancel one still decoding.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42 jvsena42 self-assigned this Nov 25, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 2c9c6ad (run).

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

A camera, gallery or nearby read delivered after Enter Manually, Contacts or Send closing starts no scan until the recipient screen shows again. A scan that closes Send itself releases the visit's handle, so a later visit cannot cancel it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 25, 2026 16:46
@jvsena42
jvsena42 requested review from a team, ovitrif and piotr-iohk and removed request for a team November 25, 2026 16:46
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

This PR keeps camera, gallery, paste, and continued-address scans tied to the current Send visit.

  • Send drops recipient-screen reads after the payer leaves.

No actionable issues were found.

Acknowledged scope from jvsena42: queued scans without a job remain outside cancellation; fee estimates remain in the scan job; a long predictive-back gesture can delay a repeated camera read; paused split-screen use on Android 9 and older can drop camera reads.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Recipient screen resumes] --> B[Allow recipient reads]
    B --> C[Start scan and keep its job]
    C --> D{What happens next?}
    D -->|Enter Manually, Contacts, or close Send| E[Cancel scan and block late reads]
    E --> A
    D -->|Scan closes Send itself| F[Release handle and let work finish]
    D -->|Request is ready| G[Open amount or review screen]
Loading

Reviews (1) · Last reviewed commit: "fix: drop reads from a recipient screen ..." · Reviewed by Greptile

@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. Drops a camera, gallery or paste scan that is still decoding when the payer taps Enter Manually, opens Contacts or closes Send: every recipient-screen request and paste is now kept as the visit's scan job, and reads the recipient screen delivers on its own are ignored from leaving it until its ON_RESUME. Reviewed 2c9c6ad1d, full tier on the view model and screen changes.

What I checked, and 5 candidates I ruled out

Read in full: the diff to SendRecipientScreen.kt and AppViewModel.kt, plus launchScan, onAddressContinue, onPasteClick, hideSheet, showSheet, handleQuickPayIfApplicable and QrCodeAnalyzer at the head. The new cases in AppViewModelSendFlowTest.kt were read against the paths they claim to cover.
Call sites traced: SendEvent.AddressContinue is built in three places: the address screen's Continue (isRecipientRead stays false, so it is never dropped), the nearby source (isNearbyRead = true, so isRecipientRead defaults to true), and the camera and gallery handlers (explicit isRecipientRead = true). hasLeftSendRecipient is set by Enter Manually, Contacts (both branches, Paykit on or off) and hideSheet while Send is shown, and cleared only by onSendRecipientShown.
Not built here: on this track an auto review does not run the branch's Gradle build, so this is reasoned from the code and from CI.
CI: on this head, build-and-test (unit tests), lint, detekt and build-local passed. The build gate is red from the first run: compose-ui / ui-tests aborted at 128 of 258 tests with INSTRUMENTATION_ABORTED: System has crashed, with one failure in SendConfirmScreenTest.preparingUsdtRequestUsesUsdtAccentAndCannotPay. That file is not in this PR. A second CI run on the same head has its ui-tests and local e2e shards still pending.

Ruled out

  • Cancelling the visit job stops a payment: handleQuickPayIfApplicable only sets _quickPayData and navigates. Nothing in the scan job sends, so cancelling it after routing stops only the fee estimate for a request the payer left.
  • A scan that closes Send cancels itself: hideSheet checks isRunningScan (a thread-local set by the scan's own coroutine context) and then only drops the handle. The pasted-contact test pins down that a later visit cannot cancel that job.
  • A duplicate camera frame loses the handle: launchScan returns null for the same active scan, and job?.let keeps the running job's handle. This is covered by the duplicate-read test.
  • The flag never clears on a back navigation: the observer is registered on the recipient entry's LocalLifecycleOwner, and that entry reaches ON_RESUME again on return from Address, Contacts or Coming Soon. While the recipient entry sits under Address in the back stack, a background and foreground cycle resumes only the Address entry, so the flag stays set as it should.
  • A recipient read on a new visit before ON_RESUME: hideSheet leaves the flag true, so a read that lands between the recipient screen's composition and its first ON_RESUME on a later visit is dropped. The camera analyzer is attached only after TRANSITION_SCREEN_MS, so this window can only catch an NFC or Bluetooth read during the opening transition, and a second tap goes through. I ruled this out narrowly, since that wiring has no unit test (the PR's Gaps list says so too).

Merge confidence: 4/5. No findings, but the ON_RESUME reset has no test, and the first CI run's ui-tests crashed in a file this PR does not touch, with the rerun still pending.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the review runner does not report it)

@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 2c9c6ad1d.

No new actionable code findings.

All changed surfaces were assessed with no actionable code findings. Camera, gallery, nearby, manual-address, and pasted scans on the Send flow are now tracked in sendVisitScanJob, late recipient-screen reads (isRecipientRead = true) are dropped from Enter Manually, Contacts, or Send closing until SendRecipientScreen receives ON_RESUME, and scans that close Send themselves (isRunningScan == true) release the handle without cancelling their ongoing work.

Validation and limitations: Local Gradle execution could not run in this review environment (Android SDK unavailable). On 2c9c6ad1d, CI passed build-and-test, compose-ui / ui-tests, build, detekt, and lint; e2e-tests-local - send was still in progress at review time. The 15 new unit tests in AppViewModelSendFlowTest.kt cover the AppViewModel cancellation, recipient-left drop, resume reset, and handle-release paths; SendRecipientScreen's ON_RESUME lifecycle hook and gallery callback wiring remain unexercised by UI tests.

iOS parity: Compared against SendOptionsView.swift in synonymdev/bitkit-ios at master (7fdf32e1e) and draft twin synonymdev/bitkit-ios#1432 (f1ee713a5). Both platforms drop late camera, gallery/photo, NFC, Bluetooth, and paste reads after leaving the Send recipient screen. Minor non-defect platform differences: iOS also invalidates the scanner visit when the offline overlay covers Send (pre-existing on Android), while Android's sendVisitScanJob also cancels an in-flight manual-entry lookup if Send is closed.

Recommended before device testing: Wait for e2e-tests-local - send to finish on 2c9c6ad1d. During device testing, cover the gaps the author reported from their API 35 emulator run at 2c9c6ad1d: manual case 5 with a Spending balance, the NFC portion of case 7 on a physical device, and Paykit payment-methods loading in case 9 with a contact that publishes Paykit endpoints.

Device testing: Not performed in this review.

Suggested additional test cases:

  • Android (gallery scan → Enter Manually): With a slow LNURL-pay QR image saved in the device gallery, open Send, tap Gallery, select that QR image, and tap Enter Manually before the LNURL lookup finishes → the address screen stays open after the lookup would return, no LNURL amount screen or error replaces it, and going Back to the recipient screen allows scanning or picking from Gallery again.

Reviewer model: gemini-4-neon
Reasoning effort: high

@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 2c9c6ad: Android 16 emulator, regtest devDebug built from this head.

Gallery lookup cannot replace manual entry ✅ Enter Manually stayed open after the delayed lookup returned; selecting the same image after Back started a fresh lookup, confirmed in app and endpoint logs.

Extends manual cases 1 and 4 with the gallery case requested in QA review. The LNURL endpoint delayed each response by 10 seconds.

gallery-manual-2x.2x.mp4

Manual invoice entry still routes ✅ Pasting an amountless regtest invoice on the address screen and tapping Continue opened Bitcoin Amount.

Manual case 5, using an amountless invoice so no Spending balance was required.

manual-invoice-2x.2x.mp4

Scan cancellation and contact refresh regressions ✅ The focused AppViewModelSendFlowTest suite passed, including a contact refresh surviving a later Send visit and Enter Manually.

Automated coverage for manual case 9's cancellation boundary, late camera and paste results, duplicate reads, returning to the recipient screen, and manual Continue.

Not driven: NFC in manual case 7 requires physical NFC hardware. Manual case 5 used an amountless invoice; a funded fixed-amount invoice and case 9 with live contact payment endpoints were not driven on the emulator.

Relied on the author's same-head device evidence for the unchanged camera, paste, Contacts, close/reopen and background cases, alongside the code review and QA review.

Full review: 747926f…2c9c6ad, four changed files. Device coverage added gallery and manual-entry checks; the test additions ran in the focused suite and the changelog was read.

Twin: synonymdev/bitkit-ios#1432 matches the intended late-result behavior after leaving Send.


Reviewed by gpt-6.1-sol-high

@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

@ovitrif

ovitrif commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Merged, as it was approved and green.

@ovitrif
ovitrif merged commit 667e7d5 into master Nov 25, 2026
38 of 40 checks passed
@ovitrif
ovitrif deleted the fix/send-scan-visit-camera-paste branch November 25, 2026 19:02
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.

Send scanner: a late camera or paste scan routes after Enter Manually

4 participants