Repository navigation
fix: drop setup sheets queued before app lock - #1433
Conversation
A scan whose route opens a setup or approval sheet (BTCPay setup, LNURL login, Pubky login) replaces the open scanner or Send sheet after the replacement delay. If the app locked in that delay, the sheet opened after unlock. These routes now pass the app lock check to the sheet, which opens only if the app has not locked since the route asked for it. Fixes #1425 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A deep link's LNURL lookup ran without a lock check, so a lock during the lookup let its sheet open after the unlock (the sheet's own check is taken when the route runs, after the lock). The lock check is now taken before the lookup and passed through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The changes affect lock-aware scan sheets and deep-link routing in Bitkit. The PR appears safe to merge, with non-blocking fixes for stale error toasts and test isolation. FindingsSummaryThis PR drops setup and sign-in sheets queued before a PIN lock.
Two non-blocking improvements remain: suppress failed lookups after a lock, and isolate the setup test's saved identity. Acknowledged scope: Reviews (1) · Last reviewed commit: "fix: drop a deep link lookup that outlas..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Drops the BTCPay setup, LNURL login and Pubky approval sheets that a scan queued just before a PIN lock, by checking lockCheck() when the 0.7 s sheet replacement comes due, and drops a deep link whose LNURL lookup outlasts a lock. Reviewed f5bcf5b87, full tier, static: iOS does not build on this reviewer's Linux host, so nothing was built or run here.
What I checked, and 6 candidates I ruled out
Read in full: SheetViewModel.showSheet / hideSheetBeforePerforming / beginReplacement, AppViewModel lockCheck, noteAppLocked, handleScannedData, ensureScannedDataHandlingOwnership, the BTCPay, LNURL auth and Pubky approval handlers, retainDeepLink / routePendingDeepLinkIfReady, MainNavView.handleDeepLink, the lock site in AppScene (scene to background with PIN on).
Call sites traced: every handleScannedData caller (MainNavView clipboard and deep link, AppScene incoming request, Send sheet, manual entry, contacts, subscriptions, shop, PaymentNavigationHelper); every showSheet for .btcpayConnection, .lnurlAuth, .pubkyAuthApproval now goes through showScannedRouteSheet.
CI: lint is red, but the job is a SwiftFormat segfault (exit 139, no lint output), and the same head passed lint in run 45645420352. Run Tests was still pending at review time.
Ruled out
- Lock during the decode reaching the new check: LNURL auth decodes, then
ensureScannedDataHandlingOwnershiprunsisCurrentScanbefore the handler, and the BTCPay and Pubky handlers have no await beforeshowScannedRouteSheet, so the check is taken with no lock window before it. - A dropped Pubky approval stranding a deep link held behind it:
replacingSheetIDis cleared before the newisCurrentguard, soisPubkyAuthApprovalShownOrPendingflips false and MainNavView'sonChangepromotesdeepLinkAfterPubkyAuth; the new SheetViewModel test asserts the cleared state on both branches. - A deep link retained while locked being dropped after unlock:
handleDeepLinkDatatakes the check when the route runs, which is after the unlock that released it, so only a later lock drops it. - Silent drop of a deep link on lock:
CancellationErrorreturns without a toast inhandleDeepLink; the body states that as the intended behaviour. - Immediate path skipping the check: with no sheet open the sheet is shown synchronously, so there is no window for a lock.
- Other
showSheetcallers: theisCurrentdefault is{ true }, so received-tx and the rest behave as before.
Not covered by a test, as the PR notes: the MainNavView switch to handleDeepLinkData.
Merge confidence: 4/5, lint is red on a tool crash rather than the change and Run Tests had not finished; the MainNavView wiring has no test.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (this reviewer's run metadata does not expose a reasoning setting)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at f5bcf5b8.
No new actionable code findings.
No actionable code findings introduced by this PR. Source analysis only: nothing was built or run in this review because iOS does not build on this Linux host.
- Deferred sheet gate:
SheetViewModel.showSheetchecksisCurrent()only after it clearsisReplacingSheetandreplacingSheetID. A dropped Pubky approval therefore still releasesisPubkyAuthApprovalShownOrPending, and a deep link held behind it is promoted onceMainNavViewremounts after unlock. Other callers keep the{ true }default. - Scanned routes: BTCPay setup, LNURL login and both Pubky approval paths now go through
showScannedRouteSheet. That guards everyhandleScannedDatacaller reaching them, not only the main scanner. - Deep links:
handleDeepLinkDatacaptures the lock generation before the lookup.MainNavViewis unmounted behind the PIN screen andnoteAppLockedruns only on backgrounding, so links retained while locked route after unlock with a current check and are not dropped. Cancellation is caught silently inhandleDeepLink.
Existing concerns (not counted as PR defects)
- Greptile: discarded links still show errors (open, no reply). Verified at this head: if the deep-link lookup throws a non-cancellation error after a lock,
MainNavView.handleDeepLink's generic catch still shows the decoding-error toast, because the lock check lives insidehandleDeepLinkData. The scanner path suppresses this withguard isCurrent()atScannerManager.swift:172. The base toasted in the same case, so this is pre-existing rather than introduced. It is narrower than the PR description's "dropped deep link is gone with no toast". - Greptile: saved identity breaks the test (open). The new test asserts no stored Pubky identity as a precondition, the same pattern as
ShopPaymentRequestTestsandPubkyProfileManagerTests. A leftover key fails it loudly rather than letting it pass falsely. Not promoted. - The clipboard lookup and the deep-link payment-sheet replacement are still unguarded. The author tracks this in #1434.
Android comparison
Source only, scoped to this flow, at bitkit-android 2d3b1a45 (default-branch HEAD at review time). showSheet re-checks canPresent after its transition delay, and scans record lockGeneration at start (scanCrossedLock), so the intent is comparable. Visual and runtime equivalence was not established.
Validation
- I inspected the new unit tests (SheetViewModel gate; BTCPay and Pubky scans with and without a lock; deep-link lookup resumed after a lock) but did not run them. The author reports 4411 unit tests passing at f5bcf5b.
- The
MainNavViewwiring and LNURL login have no failing-if-reverted test, as the author acknowledges. - SwiftFormat at this head: one run passed; a later run crashed with a segfault (exit 139) before producing lint output.
Recommended before device testing: wait for Run Tests, Run Integration Tests and build-local at f5bcf5b, which were still in progress at review time, and re-run SwiftFormat to clear the crashed job.
Device testing: not performed in this review.
Suggested additional test cases
- iOS, PIN enabled, Paykit UI enabled, no Pubky identity. With the scanner open, open a Pubky sign-up deep link and then a second payment deep link, and lock inside the 0.7 s replacement window. Expected after unlock: no approval sheet, and the held second link routes normally rather than staying stuck.
- iOS, PIN enabled, local LNURL server set to fail (e.g. HTTP 500) after about 10 s. Open an LNURL-withdraw deep link, lock during the lookup, then unlock. Observe whether a decoding-error toast appears, and confirm with the author whether that matches the intended "no toast" behaviour for dropped deep links.
Reviewer model: claude-opus-5-5
Reasoning effort: high
A deep link lookup that failed after the app locked still surfaced its error, so a stale toast showed after the unlock. The wrapper now turns any error after a lock into a cancellation. The setup-sheet test also clears and restores the Pubky session and secret key, which count as a stored identity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Verdict:
The PR moved to 9927815 after this run; these results are for f5bcf5b.
Findings: No new findings. The failed-lookup error path at Bitkit/ViewModels/AppViewModel.swift:1312 is already covered by Greptile's finding; code inspection confirms it at f5bcf5b, with no additional device evidence.
QA for f5bcf5b:
Unit suite including scanner and sheet lock checks ⏭️ Incomplete: two scanner checks passed, but the suite did not finish.
The app and test targets built. XCTest passed testDeepLinkLookupFromBeforeALockIsDropped and testSetupSheetQueuedBeforeALockDoesNotOpenAfterIt. The run then stalled in the existing SendSheetLifecycleTests.testScannerReplacementPreservesLnurlConfirmation; testReplacementSheetOpensOnlyWhileItsRouteIsCurrent was not reached. The iOS 26.5 retry did not launch the test host. Simulator recovery was still incomplete when the head moved.
A failed lookup after lock ends silently ⏭️ Not driven: simulator recovery was incomplete when the head moved.
Additional failure-response variant of manual case 6, requested in the QA review. The controlled endpoint was prepared, but no runtime result is claimed.
A held payment link resumes after a dropped Pubky approval ⏭️ Not driven: simulator recovery was incomplete when the head moved.
The QA review requested this additional case; it remains unverified.
Not re-driven: manual cases 1–6, relying on the author's same-head evidence using pasted QR codes. No physical-camera coverage was added.
Changed Swift files pass SwiftFormat 0.64.6 on macOS. The Linux CI formatter run crashed with a segmentation fault before reporting a violation.
Full six-file diff reviewed. Own runtime coverage is limited to the partial unit run; setup-sheet and successful lookup device behavior relies on the author's report. No Android twin is linked.
Reviewed by gpt-6.1-sol-high
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since f5bcf5b8, including affected code paths and prior findings, at 99278154. Baseline: previous QA review. The deferred sheet gate in SheetViewModel, the showScannedRouteSheet routing for BTCPay setup, LNURL login and Pubky approval, the MainNavView deep-link wiring and the changelog fragment are unchanged since the baseline, so their coverage is inherited.
No new actionable code findings.
No new actionable code findings in the follow-up. Source analysis only: nothing was built or run in this review.
- Deep-link lookup error after a lock:
handleDeepLinkDatanow catches errors fromhandleScannedData. When the lock check captured before the lookup no longer holds, it throwsCancellationErrorinstead.MainNavView.handleDeepLinkalready returns silently onCancellationError, so a lookup that fails after the app locked no longer shows the decoding-error toast after unlock. Errors from lookups that did not cross a lock are still rethrown to the existing toast path.handleDeepLinkDatais only called fromMainNavView.handleDeepLink. The two new tests cover both branches: a lookup resumed with an error afternoteAppLocked()ends inCancellationErrorwith no sheet open, and a failing lookup without a lock keeps its original error. - Setup-sheet test isolation: the test now saves, clears and restores
.paykitSessionand.pubkySecretKeybefore it asserts that no Pubky identity is stored. That clears the identity precondition the sign-up route depends on.
Prior concerns reconciled
- Greptile: discarded links still show errors: the thread is marked resolved, and the fix is confirmed in source at this head as described above. The baseline listed this as an existing concern; it no longer applies.
- Greptile: saved identity breaks the test: the thread is marked resolved, and the fix is confirmed in source at this head.
- The clipboard lookup and the deep-link payment-sheet replacement are still unguarded. The author tracks this separately in #1434, and this delta does not touch it.
Validation and limitations
- I read the new and changed unit tests but did not run them. At review time,
Run Tests,Run Integration Testsande2e-tests-localwere pending for this head and SwiftFormat passed. - I did not re-compare Android for this delta. The baseline's source comparison covered the lock-gating intent for this flow.
Recommended before device testing: wait for Run Tests and Run Integration Tests to finish at 9927815.
Device testing: not performed in this review.
Suggested additional test cases
- iOS, PIN enabled, a local LNURL server set to fail (for example HTTP 500) after about 10 s. Open an LNURL-withdraw deep link, lock the app during the lookup, then unlock. Expected: no decoding-error toast and no sheet. Repeat without locking: the decoding-error toast appears.
Reviewer model: claude-opus-5-5
Reasoning effort: high
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: No new findings. Verified the fixes for the stale lookup error and setup-test identity state.
QA for 9927815:
iPhone 17 Pro simulator, iOS 27.0, Debug regtest. The error-response cases use the unmodified head; the held-link case uses the timing hook below.
A failed lookup without locking shows its error ✅ The failed LNURL lookup showed “Decoding Error.”
The controlled endpoint confirmed receipt and release of the failing response. No payment sheet opened.
failed-unlocked.2x.mp4
A failed lookup after locking ends silently ✅ Releasing the failure after PIN unlock left Home open without an error or sheet.
The lookup began before backgrounding. Response timing was checked in the endpoint log.
failed-locked.2x.mp4
A held payment link resumes after a dropped Pubky approval ✅ After unlocking, the held Bitcoin request produced its normal “Insufficient Savings” response.
On 9927815 plus the timing hook, a pasted Pubky sign-up queued its approval and a Bitcoin deep link arrived while it was pending. The app log confirmed the approval was dropped after the PIN lock; after unlock, the held request showed “Insufficient Savings” on the empty wallet.
held-payment.2x.mp4
Temporary timing hook
Not pushed: holds only the deferred Pubky callback until an explicit file release after the app reports background, preserving the existing cleanup and lock check. Queue release was verified with controlled timing; the original 0.7-second window relies on the author's earlier device evidence.
diff --git a/Bitkit/ViewModels/SheetViewModel.swift b/Bitkit/ViewModels/SheetViewModel.swift
index 183de5042..7cf816363 100644
--- a/Bitkit/ViewModels/SheetViewModel.swift
+++ b/Bitkit/ViewModels/SheetViewModel.swift
@@ -97,23 +97,25 @@ class SheetViewModel: ObservableObject {
DispatchQueue.main.asyncAfter(deadline: .now() + Self.replacementDelaySeconds) { [weak self] in
guard let self else { return }
- isReplacingSheet = false
- if replacingSheetID == id {
- replacingSheetID = nil
+ qaHoldPubkyReplacement(id) { // test hook
+ self.isReplacingSheet = false
+ if self.replacingSheetID == id {
+ self.replacingSheetID = nil
}
- guard pendingReplacements.remove(replacement) != nil else { return }
+ guard self.pendingReplacements.remove(replacement) != nil else { return }
guard isCurrent() else {
Logger.debug("Dropped sheet \(id.rawValue): its route is no longer current", context: "SheetViewModel")
return
}
Logger.debug("Showing sheet \(id.rawValue) after delay", context: "SheetViewModel")
- activeSheetConfiguration = SheetConfiguration(id: id, data: data)
- playHaptics(for: id)
+ self.activeSheetConfiguration = SheetConfiguration(id: id, data: data)
+ self.playHaptics(for: id)
// Notify timed sheet manager
Task { @MainActor in
TimedSheetManager.shared.onSheetShown()
}
+ } // test hook
}
} else {
isReplacingSheet = false
@@ -129,6 +131,19 @@ class SheetViewModel: ObservableObject {
}
}
+ private func qaHoldPubkyReplacement(_ id: SheetID, perform: @escaping () -> Void) { // test hook
+ #if DEBUG // test hook
+ if id == .pubkyAuthApproval, ProcessInfo.processInfo.environment["QA_HOLD_PUBKY"] == "1", // test hook
+ !FileManager.default.fileExists(atPath: Env.appStorageUrl.appendingPathComponent("qa-release-approval").path) { // test hook
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in // test hook
+ self?.qaHoldPubkyReplacement(id, perform: perform) // test hook
+ } // test hook
+ return // test hook
+ } // test hook
+ #endif // test hook
+ perform() // test hook
+ } // test hook
+
func hideSheet(reason: String? = nil, file: String = #file, function: String = #function, line: Int = #line) {
if let config = activeSheetConfiguration {
if !isReplacingSheet {Not re-driven:
- Manual cases 1–5 and the successful-response variant of case 6: the author's passing device report at f5bcf5b covers those unchanged paths.
- Focused checks at 9927815: the author's report covers the added error branches and setup-test isolation.
- Physical-camera coverage: the device reports use pasted QR contents on a simulator.
Reviewed the two-file delta f5bcf5b..9927815 plus prior findings. Device checks cover the remaining cases requested in the QA review; the test-key restoration was checked in source and relies on the author's focused test report.
Android twin: none linked; cross-platform behavior was not re-tested.
Reviewed by gpt-6.1-sol-high
|
@jvsena42 Merged, as it was approved and green. |
Fixes #1425
This PR drops a setup or approval sheet that a scan queued just before the app locked, so it no longer opens after unlock.
Description
AppViewModel.lockCheck()to the sheet at the point it asks for it, and the sheet opens only if the app has not locked since.isCurrentcheck toSheetViewModel.showSheet, read when a deferred replacement is due; other callers keep the default and behave as before.Out of Scope
MainNavView: the clipboard prompt's lookup, and a deep link's payment sheet going through the 0.7 s replacement delay, still have no lock check. Tracked in Clipboard prompt and deep link payment sheet open after an app lock #1434.Design
N/A — no UI changes.
Preview
LNURL login scanned, app locked inside the 0.7 s sheet delay, unlocked: no login sheet (
Dropped sheet lnurlAuth).1433-login-lock.mp4
BTCPay setup, same steps: no BTCPay sheet.
1433-btcpay-lock.mp4
Deep link to a slow LNURL-withdraw, locked during the lookup: nothing opens after unlock.
1433-deeplink-lock.mp4
Regression: LNURL login without a lock opens its sheet.
1433-login-no-lock.mp4
QA Notes
Setup
E2E_BUILDand thebitkit-dockerlnurl-server(LNURL row of the Capabilities table injourneys/README.md), and a Spending balance so LNURL withdraw and login are allowed (Lightning running).Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
regression:Main scanner → scan each QR from 1–4 without locking → its sheet opens as before — camera QR scanning not in Capabilitiesxcrun simctl openurlor a tapped link) → lock during the lookup → unlock → nothing opens and no toast shows — delayed LNURL response and locking during the lookup not in CapabilitiesAutomated Checks
ScannerManagerTests.swift— BTCPay setup and Pubky sign-up scans from the main scanner open their sheet without a lock, and not when the app locks before the replacement delay ends; the test clears and restores the stored Pubky session and secret keyScannerManagerTests.swift— a deep link lookup interrupted by a lock is dropped: no send state and no sheetScannerManagerTests.swift— a deep link lookup that fails after a lock is dropped without its errorScannerManagerTests.swift— a deep link lookup that fails without a lock still reports its errorSheetViewModelTests.swift— a deferred sheet replacement opens only if itsisCurrentcheck still holds when due, and clears the replacing state either wayEvidence
ScannerManagerTests,SheetViewModelTests,ShopPaymentRequestTests,PubkyAuthURLSchemeTests). The new lock-failure test fails against the previousAppViewModel.swift. SwiftFormat lint clean. Full suite not rerun this round. The device run below is from f5bcf5b; the change since only affects a deep link lookup that fails after a lock.handleScan. All six manual cases passed:Showing sheet lnurlWithdraw, no sheet after unlock. Withdraw goes through the payment-sheet path from feat: nfc and bluetooth nearby payments #1302, as listed in Out of Scope.Dropped sheet lnurlAuthat unlock, no sheet.Dropped sheet btcpayConnection, no sheet.Dropped sheet pubkyAuthApproval, no sheet.Droppedlines.BitkitTestsunit suite with the CI skips ran 4411 tests, 0 failures. With the lock check not passed into the deep link lookup, the new deep link test fails.ScannerManagerTestsandSheetViewModelTests58/58 passed; theBitkitTestsunit suite with the CI skips ran 4410 tests, 0 failures. SwiftFormat lint clean on changed files.AppViewModel.swiftreverted to master, the new scanner test fails for both routes (the sheet opens after the lock).Gaps
BitkitUITestswere not run on this branch. On master (7fdf32e), on the same simulator,HomeHeaderUITests.testHeaderRowTapsOpenHeaderButtonsAndBalanceStillToggles,UsdtWalletUITests.testReceiveAndInvalidPaymentStaySeparateFromBitcoin,UsdtWalletUITests.testUnknownBalanceAndManualEntryUseConsistentAmountsInCommaRegionfail waiting for the wallet home after onboarding; they fail the same way on fix: tie the scan lock to the scanner visit #1432's branch.MainNavViewcall tohandleDeepLinkDatahas no test that fails if it is reverted (same view-wiring gap as fix: tie the scan lock to the scanner visit #1432'sSendOptionsView); manual case 6 covers it.Models used
claude-opus-5-5(reasoning:Not exposed)Metadata note: the task brief came from a parent session whose model was not recorded here; this session's reasoning setting is not exposed in its run metadata.
🤖 Generated with Claude Code