From 51a4b415ae8f8e11d750ed10baa73292b83df439 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 24 Nov 2026 22:31:04 +0100 Subject: [PATCH 1/7] fix: keep confirm open until the swipe finishes A swipe on Confirm, such as one that first updates the spending balance, now holds the screen until it moves on or returns to Confirm: no Back, no swipe back, no sheet drag and no edits. The per-visit guard stays as a safety net. Verified: none (unit suite runs next) --- .../Views/Wallets/Send/LnurlPayConfirm.swift | 10 +++- .../Wallets/Send/SendConfirmationView.swift | 57 ++++++++++++++++++- Bitkit/Views/Wallets/Send/SendSheet.swift | 10 +++- BitkitTests/SendConfirmationSwipeTests.swift | 19 +++++++ .../send/update-spending-balance-payment.xml | 4 +- 5 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift index e9d4b35f55..e81991146f 100644 --- a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift +++ b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift @@ -16,6 +16,8 @@ struct LnurlPayConfirm: View { let requestPinCheck: () async -> Bool let prepareIncomingPaymentRequest: () async throws -> Void let routingCacheResetAttempted: Bool + /// Tells the sheet when a running swipe holds this screen, so its drag waits too. + var onLockChange: (Bool) -> Void = { _ in } @State private var showWarningAlert = false @State private var alertContinuation: CheckedContinuation? @@ -27,6 +29,7 @@ struct LnurlPayConfirm: View { @State private var sparkUpdateQuote: MoveToSparkQuote? @State private var isSparkUpdateQuoting = false @State private var screenVisit = ConfirmScreenVisit() + @State private var swipeLock = ConfirmSwipeLock() /// A first subscription payment that needs the update waits for a swipe on its update fee instead of paying by itself. @State private var needsUpdateConfirmation = false @FocusState private var isCommentFocused: Bool @@ -108,6 +111,7 @@ struct LnurlPayConfirm: View { screenVisit = ConfirmScreenVisit() } } + .confirmSwipeLock($swipeLock, onLockChange: onLockChange) .onDisappear { screenVisit.leave() } @@ -117,7 +121,7 @@ struct LnurlPayConfirm: View { VStack { SheetHeader( title: reviewTitle, - showBackButton: true, + showBackButton: !swipeLock.isLocked, action: AnyView(SendContactHeaderAvatar()) ) @@ -183,6 +187,8 @@ struct LnurlPayConfirm: View { .focused($isCommentFocused) .dismissKeyboardOnReturn(text: $comment, isFocused: $isCommentFocused) .lineLimit(3 ... 3) + // The comment stays as swiped while the swipe runs + .disabled(swipeLock.isLocked) .onChange(of: comment) { _, newValue in let maxLength = Int(commentAllowed) if newValue.count > maxLength { @@ -207,6 +213,8 @@ struct LnurlPayConfirm: View { isLoading: hasStartedAutomaticPayment || isSubmittingPayment, isSubmitted: hasStartedAutomaticPayment ) { + swipeLock.begin() + defer { swipeLock.end() } try await submitPayment(isAutomatic: false) } } diff --git a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift index 53b42dcb85..e5bf4fc929 100644 --- a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift +++ b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift @@ -29,6 +29,8 @@ struct SendConfirmationView: View { var amountIsRoot = false /// True while the send sheet is still loading the fee rate and choosing the funding source. var isSetupPending = false + /// Tells the sheet when a running swipe holds this screen, so its drag waits too. + var onLockChange: (Bool) -> Void = { _ in } @State private var showDetails = false @State private var routedIncomingRequestId: PaykitPaymentRequest.ID? @@ -91,6 +93,7 @@ struct SendConfirmationView: View { @State private var sparkUpdateQuote: MoveToSparkQuote? @State private var sparkUpdateQuoteRuns = SparkUpdateQuoteRuns() @State private var screenVisit = ConfirmScreenVisit() + @State private var swipeLock = ConfirmSwipeLock() private struct WalletSwitchRun { let id: UUID @@ -407,7 +410,7 @@ struct SendConfirmationView: View { VStack(alignment: .leading, spacing: 0) { SheetHeader( title: reviewTitle, - showBackButton: !navigationPath.isEmpty, + showBackButton: !navigationPath.isEmpty && !swipeLock.isLocked, action: AnyView(SendContactHeaderAvatar(publicKey: preparingRequest?.counterparty)) ) @@ -524,9 +527,13 @@ struct SendConfirmationView: View { isSubmitted: hasStartedAutomaticPayment, swipeProgress: $swipeProgress ) { + swipeLock.begin() + defer { swipeLock.end() } try await submitPayment() } } + // The payment's inputs stay as swiped while the swipe runs + .allowsHitTesting(!swipeLock.isLocked) } private var confirmationPresentation: some View { @@ -621,6 +628,7 @@ struct SendConfirmationView: View { screenVisit = ConfirmScreenVisit() } } + .confirmSwipeLock($swipeLock, onLockChange: onLockChange) .onDisappear { screenVisit.leave() startWalletSwitch(context: nil) @@ -3164,6 +3172,53 @@ final class ConfirmScreenVisit { } } +/// Holds a confirm screen while a swipe of it runs, until the swipe moves on to the next screen or returns to Confirm: +/// Back, swipe back, the sheet's drag and the payment's inputs wait meanwhile. +struct ConfirmSwipeLock: Equatable { + private(set) var runs = 0 + var isVisible = false + + var isLocked: Bool { + runs > 0 && isVisible + } + + mutating func begin() { + runs += 1 + } + + mutating func end() { + runs = max(0, runs - 1) + } +} + +extension View { + /// Tracks the screen's stay for `lock`, holds swipe back while it locks, and reports each change to the sheet. + func confirmSwipeLock(_ lock: Binding, onLockChange: @escaping (Bool) -> Void) -> some View { + modifier(ConfirmSwipeLockModifier(lock: lock, onLockChange: onLockChange)) + } +} + +private struct ConfirmSwipeLockModifier: ViewModifier { + @Binding var lock: ConfirmSwipeLock + let onLockChange: (Bool) -> Void + + func body(content: Content) -> some View { + content + .onAppear { lock.isVisible = true } + .onDisappear { + if lock.isLocked { + SwipeBackState.allowSwipeBack = true + onLockChange(false) + } + lock.isVisible = false + } + .onChange(of: lock.isLocked) { _, isLocked in + SwipeBackState.allowSwipeBack = !isLocked + onLockChange(isLocked) + } + } +} + /// Tracks the newest spending balance update quote on Confirm, so an older quote finishing late writes neither its fee nor /// its quote, and only the newest one holds the swipe. struct SparkUpdateQuoteRuns: Equatable { diff --git a/Bitkit/Views/Wallets/Send/SendSheet.swift b/Bitkit/Views/Wallets/Send/SendSheet.swift index 32a1e70843..eeb33d4fc2 100644 --- a/Bitkit/Views/Wallets/Send/SendSheet.swift +++ b/Bitkit/Views/Wallets/Send/SendSheet.swift @@ -96,6 +96,8 @@ final class SendPresentationState { var hasValidatedAfterSync = false var incomingPaymentRequest: PaykitPaymentRequest? var isSubmittingPayment = false + /// True while a running swipe holds Confirm; the sheet's drag waits for it too. + var isConfirmLocked = false var isAmountReviewRequired = false var paymentReview: UUID? var isReviewingUsdtPayment = false @@ -373,7 +375,7 @@ struct SendSheet: View { } } .animation(.easeInOut(duration: 0.3), value: shouldShowSyncOverlay) - .interactiveDismissDisabled(!hwSend.canLeave) + .interactiveDismissDisabled(!hwSend.canLeave || flow.isConfirmLocked) .sheet(isPresented: reconnectPairingBinding) { HardwarePairingSheet(config: HardwarePairingSheetItem()) } @@ -1124,7 +1126,8 @@ struct SendSheet: View { preparingRequest: isPreparingRequest ? config.preparation?.request : nil, isAmountReviewRequired: $flow.isAmountReviewRequired, amountIsRoot: currentRoot == .amount, - isSetupPending: flow.isSetupPending || flow.isFallbackFundingPending + isSetupPending: flow.isSetupPending || flow.isFallbackFundingPending, + onLockChange: { flow.isConfirmLocked = $0 } ) case .hardwareSign: let contactContext = app.contactPaymentContext @@ -1258,7 +1261,8 @@ struct SendSheet: View { isSubmittingPayment: $flow.isSubmittingPayment, requestPinCheck: requestPinCheck, prepareIncomingPaymentRequest: prepareIncomingPaymentRequest, - routingCacheResetAttempted: flow.routingCacheResetAttempted + routingCacheResetAttempted: flow.routingCacheResetAttempted, + onLockChange: { flow.isConfirmLocked = $0 } ) case .lnurlWithdrawAmount: LnurlWithdrawAmount { diff --git a/BitkitTests/SendConfirmationSwipeTests.swift b/BitkitTests/SendConfirmationSwipeTests.swift index 212198911e..25fd209e4c 100644 --- a/BitkitTests/SendConfirmationSwipeTests.swift +++ b/BitkitTests/SendConfirmationSwipeTests.swift @@ -4,6 +4,25 @@ import SwiftUI import XCTest final class SendConfirmationSwipeTests: XCTestCase { + func testARunningSwipeHoldsConfirmUntilItMovesOnOrReturns() { + var lock = ConfirmSwipeLock() + lock.isVisible = true + XCTAssertFalse(lock.isLocked) + + lock.begin() + XCTAssertTrue(lock.isLocked, "A running swipe holds Back, the sheet's drag and the inputs") + lock.isVisible = false + XCTAssertFalse(lock.isLocked, "The screen the swipe moves on to, such as the PIN, is free") + lock.isVisible = true + XCTAssertTrue(lock.isLocked, "Returning to Confirm while the swipe still runs holds it again") + + lock.end() + XCTAssertFalse(lock.isLocked, "A finished swipe frees Confirm") + lock.end() + lock.begin() + XCTAssertTrue(lock.isLocked, "An extra end never frees a later swipe early") + } + @MainActor func testRestoredLoadingSwipeKeepsItsSpinnerInTheKnob() async throws { let confirmation = NavigationStack(path: .constant([true])) { diff --git a/journeys/send/update-spending-balance-payment.xml b/journeys/send/update-spending-balance-payment.xml index f08acb76a2..111381ee0e 100644 --- a/journeys/send/update-spending-balance-payment.xml +++ b/journeys/send/update-spending-balance-payment.xml @@ -5,7 +5,8 @@ and one swipe first moves the channel's balance to Spark, then pays the invoice from Spark. The move shows in Activity as a "Move to Spark" row, and the emptied channel closes in the background. If the payment fails after the move, the funds stay in Spark and the usual payment error shows. QuickPay never sends such a payment; it always - opens the confirm screen. + opens the confirm screen. From the swipe until it moves on or returns to confirm, the confirm screen is locked: no + Back, no sheet dismiss and no edits. Precondition: dev build pointed at a local Spark regtest (spark-sdk regtest/local), QuickPay off, a wallet with an open channel to that stack's SSP Lightning node that can send about 30 000 sats and a Spark balance of about @@ -17,6 +18,7 @@ Verify the Confirm screen (id "SendConfirm") shows 50 000 sats with its details open on their own (Hide Details, id "SendConfirmToggleDetails") Verify the fee row shows the payment's own fee and the "Update fee" row (id "ReviewUpdateFee") shows an amount, without "up to", and that no "Route" row (id "ReviewSwapRoute") shows Swipe to pay (id "GRAB"); the payment is over half of the Spending balance, so verify the "Are You Sure?" dialog warns about sending over 50% of the balance and tap "Yes, Send" (id "DialogConfirm") + While the swipe still shows its loading state, swipe back from the left edge and drag the sheet down; verify the Confirm screen stays open with no Back button Verify the Bitcoin Sent screen (id "SendSuccess") shows 50 000 Go back to Home and verify Activity lists a "Move to Spark" transfer row and the 50 000-sat Lightning payment Open Settings › Advanced › Lightning Connections and verify the channel is closing or closed From a074e2fc8277f029f7262f5319c1a8f716b8b148 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 24 Nov 2026 22:38:51 +0100 Subject: [PATCH 2/7] fix: hold swipe back and embedded sheets for the swipe The confirm's swipe-back hold gets its own flag, so the PIN and Pending screens keep their own setting. A payment still running holds a rebuilt Confirm, and the subscription sheet embedding the send flow keeps its drag off too. Verified: none (unit suite runs next) --- .../UINavigationController+SwipeBack.swift | 4 +- .../Subscriptions/SubscriptionsView.swift | 6 ++- .../Views/Wallets/Send/LnurlPayConfirm.swift | 10 +++-- .../Wallets/Send/SendConfirmationView.swift | 40 +++++++++++++------ Bitkit/Views/Wallets/Send/SendSheet.swift | 6 ++- BitkitTests/SendConfirmationSwipeTests.swift | 17 +++++--- .../send/update-spending-balance-payment.xml | 2 +- 7 files changed, 58 insertions(+), 27 deletions(-) diff --git a/Bitkit/Extensions/UINavigationController+SwipeBack.swift b/Bitkit/Extensions/UINavigationController+SwipeBack.swift index ee62b34c51..4fe4cd6df1 100644 --- a/Bitkit/Extensions/UINavigationController+SwipeBack.swift +++ b/Bitkit/Extensions/UINavigationController+SwipeBack.swift @@ -5,6 +5,8 @@ import UIKit enum SwipeBackState { /// When false, the interactive pop gesture is disabled. Set by views that hide the back button. static var allowSwipeBack: Bool = true + /// True while a running swipe holds a send confirm screen; kept apart so other screens' own setting stays theirs. + static var isHeldByConfirmSwipe = false } /// Re-enables the interactive swipe-back gesture when the navigation bar is hidden @@ -20,6 +22,6 @@ extension UINavigationController: @retroactive UIGestureRecognizerDelegate { public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { // Only allow swipe-back when not at root — avoids iOS 17+ freeze when re-pushing after swiping to root guard viewControllers.count > 1 else { return false } - return SwipeBackState.allowSwipeBack + return SwipeBackState.allowSwipeBack && !SwipeBackState.isHeldByConfirmSwipe } } diff --git a/Bitkit/Views/Subscriptions/SubscriptionsView.swift b/Bitkit/Views/Subscriptions/SubscriptionsView.swift index dd5fd3676c..a9ffc91d1b 100644 --- a/Bitkit/Views/Subscriptions/SubscriptionsView.swift +++ b/Bitkit/Views/Subscriptions/SubscriptionsView.swift @@ -599,6 +599,7 @@ struct SubscriptionSheet: View { @State private var previousRoute: SubscriptionSheetItem.Route? @State private var now = SubscriptionClock.subscriptionNow() @State private var isAccepting = false + @State private var isSendConfirmLocked = false @State private var creationDraft = PaykitSubscriptionDraft.empty @State private var selectedCreationTarget: PaykitPaymentRequestTarget? @@ -649,7 +650,8 @@ struct SubscriptionSheet: View { case let .payment(sendRoute): SendSheet( config: SendSheetItem(presentationID: sheets.activeSheetConfiguration?.presentationID, initialRoute: sendRoute), - isEmbedded: true + isEmbedded: true, + onConfirmLockChange: { isSendConfirmLocked = $0 } ) case .allowanceContact: AllowanceContactView { route = .allowanceSet($0) } @@ -695,7 +697,7 @@ struct SubscriptionSheet: View { } now = SubscriptionClock.subscriptionNow() } - .interactiveDismissDisabled(isAccepting || paymentRequests.isCreatingRequest) + .interactiveDismissDisabled(isAccepting || paymentRequests.isCreatingRequest || isSendConfirmLocked) } private func review(_ subscription: PaykitSubscription) -> some View { diff --git a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift index e81991146f..f9f44dc6e9 100644 --- a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift +++ b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift @@ -111,7 +111,7 @@ struct LnurlPayConfirm: View { screenVisit = ConfirmScreenVisit() } } - .confirmSwipeLock($swipeLock, onLockChange: onLockChange) + .confirmSwipeLock($swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) .onDisappear { screenVisit.leave() } @@ -121,7 +121,7 @@ struct LnurlPayConfirm: View { VStack { SheetHeader( title: reviewTitle, - showBackButton: !swipeLock.isLocked, + showBackButton: !isSwipeLocked, action: AnyView(SendContactHeaderAvatar()) ) @@ -188,7 +188,7 @@ struct LnurlPayConfirm: View { .dismissKeyboardOnReturn(text: $comment, isFocused: $isCommentFocused) .lineLimit(3 ... 3) // The comment stays as swiped while the swipe runs - .disabled(swipeLock.isLocked) + .disabled(isSwipeLocked) .onChange(of: comment) { _, newValue in let maxLength = Int(commentAllowed) if newValue.count > maxLength { @@ -223,6 +223,10 @@ struct LnurlPayConfirm: View { .sheetBackground() } + private var isSwipeLocked: Bool { + swipeLock.isLocked(isSubmittingPayment: isSubmittingPayment) + } + private var reviewTitle: String { paykitPaymentReviewTitle(context: app.contactPaymentContext, fallback: t("wallet__lnurl_p_title")) } diff --git a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift index e5bf4fc929..097f5d0e74 100644 --- a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift +++ b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift @@ -410,7 +410,7 @@ struct SendConfirmationView: View { VStack(alignment: .leading, spacing: 0) { SheetHeader( title: reviewTitle, - showBackButton: !navigationPath.isEmpty && !swipeLock.isLocked, + showBackButton: !navigationPath.isEmpty && !isSwipeLocked, action: AnyView(SendContactHeaderAvatar(publicKey: preparingRequest?.counterparty)) ) @@ -533,7 +533,7 @@ struct SendConfirmationView: View { } } // The payment's inputs stay as swiped while the swipe runs - .allowsHitTesting(!swipeLock.isLocked) + .allowsHitTesting(!isSwipeLocked) } private var confirmationPresentation: some View { @@ -628,7 +628,7 @@ struct SendConfirmationView: View { screenVisit = ConfirmScreenVisit() } } - .confirmSwipeLock($swipeLock, onLockChange: onLockChange) + .confirmSwipeLock($swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) .onDisappear { screenVisit.leave() startWalletSwitch(context: nil) @@ -1111,6 +1111,10 @@ struct SendConfirmationView: View { } } + private var isSwipeLocked: Bool { + swipeLock.isLocked(isSubmittingPayment: isSubmittingPayment) + } + private func submitPayment(isAutomatic: Bool = false) async throws { guard !isSubmittingPayment else { return } guard !requiresAmountReview, preparingRequest == nil, !isRequestSetupPending, walletSwitchContext == nil, @@ -3172,14 +3176,15 @@ final class ConfirmScreenVisit { } } -/// Holds a confirm screen while a swipe of it runs, until the swipe moves on to the next screen or returns to Confirm: -/// Back, swipe back, the sheet's drag and the payment's inputs wait meanwhile. +/// Holds a confirm screen while a swipe of it, or the payment it started, runs, until it moves on to the next screen or +/// returns to Confirm: Back, swipe back, the sheet's drag and the payment's inputs wait meanwhile. struct ConfirmSwipeLock: Equatable { private(set) var runs = 0 var isVisible = false - var isLocked: Bool { - runs > 0 && isVisible + /// The sheet's `isSubmittingPayment` outlives this screen's state, so a payment still holds a rebuilt Confirm. + func isLocked(isSubmittingPayment: Bool) -> Bool { + (runs > 0 || isSubmittingPayment) && isVisible } mutating func begin() { @@ -3193,27 +3198,36 @@ struct ConfirmSwipeLock: Equatable { extension View { /// Tracks the screen's stay for `lock`, holds swipe back while it locks, and reports each change to the sheet. - func confirmSwipeLock(_ lock: Binding, onLockChange: @escaping (Bool) -> Void) -> some View { - modifier(ConfirmSwipeLockModifier(lock: lock, onLockChange: onLockChange)) + func confirmSwipeLock( + _ lock: Binding, + isSubmittingPayment: Bool, + onLockChange: @escaping (Bool) -> Void + ) -> some View { + modifier(ConfirmSwipeLockModifier(lock: lock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange)) } } private struct ConfirmSwipeLockModifier: ViewModifier { @Binding var lock: ConfirmSwipeLock + let isSubmittingPayment: Bool let onLockChange: (Bool) -> Void + private var isLocked: Bool { + lock.isLocked(isSubmittingPayment: isSubmittingPayment) + } + func body(content: Content) -> some View { content .onAppear { lock.isVisible = true } .onDisappear { - if lock.isLocked { - SwipeBackState.allowSwipeBack = true + if isLocked { + SwipeBackState.isHeldByConfirmSwipe = false onLockChange(false) } lock.isVisible = false } - .onChange(of: lock.isLocked) { _, isLocked in - SwipeBackState.allowSwipeBack = !isLocked + .onChange(of: isLocked) { _, isLocked in + SwipeBackState.isHeldByConfirmSwipe = isLocked onLockChange(isLocked) } } diff --git a/Bitkit/Views/Wallets/Send/SendSheet.swift b/Bitkit/Views/Wallets/Send/SendSheet.swift index eeb33d4fc2..ff4ad6c466 100644 --- a/Bitkit/Views/Wallets/Send/SendSheet.swift +++ b/Bitkit/Views/Wallets/Send/SendSheet.swift @@ -216,6 +216,8 @@ struct SendSheet: View { let config: SendSheetItem let isEmbedded: Bool + /// Tells a sheet embedding this flow when Confirm holds the drag, as its own dismiss rule wins. + var onConfirmLockChange: (Bool) -> Void = { _ in } @State private var flow: SendPresentationState @State private var hwSend: HwSendCoordinator @@ -227,9 +229,10 @@ struct SendSheet: View { return sheets.activeSheetConfiguration?.presentationID == presentationID } - init(config: SendSheetItem, isEmbedded: Bool = false) { + init(config: SendSheetItem, isEmbedded: Bool = false, onConfirmLockChange: @escaping (Bool) -> Void = { _ in }) { self.config = config self.isEmbedded = isEmbedded + self.onConfirmLockChange = onConfirmLockChange _flow = State(initialValue: config.state) let hwSend = config.state.hwSend ?? HwSendCoordinator(walletId: config.hardwareWalletId) config.state.hwSend = hwSend @@ -376,6 +379,7 @@ struct SendSheet: View { } .animation(.easeInOut(duration: 0.3), value: shouldShowSyncOverlay) .interactiveDismissDisabled(!hwSend.canLeave || flow.isConfirmLocked) + .onChange(of: flow.isConfirmLocked) { _, isLocked in onConfirmLockChange(isLocked) } .sheet(isPresented: reconnectPairingBinding) { HardwarePairingSheet(config: HardwarePairingSheetItem()) } diff --git a/BitkitTests/SendConfirmationSwipeTests.swift b/BitkitTests/SendConfirmationSwipeTests.swift index 25fd209e4c..f7d14230c1 100644 --- a/BitkitTests/SendConfirmationSwipeTests.swift +++ b/BitkitTests/SendConfirmationSwipeTests.swift @@ -7,20 +7,25 @@ final class SendConfirmationSwipeTests: XCTestCase { func testARunningSwipeHoldsConfirmUntilItMovesOnOrReturns() { var lock = ConfirmSwipeLock() lock.isVisible = true - XCTAssertFalse(lock.isLocked) + XCTAssertFalse(lock.isLocked(isSubmittingPayment: false)) lock.begin() - XCTAssertTrue(lock.isLocked, "A running swipe holds Back, the sheet's drag and the inputs") + XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "A running swipe holds Back, the sheet's drag and the inputs") lock.isVisible = false - XCTAssertFalse(lock.isLocked, "The screen the swipe moves on to, such as the PIN, is free") + XCTAssertFalse(lock.isLocked(isSubmittingPayment: false), "The screen the swipe moves on to, such as the PIN, is free") lock.isVisible = true - XCTAssertTrue(lock.isLocked, "Returning to Confirm while the swipe still runs holds it again") + XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "Returning to Confirm while the swipe still runs holds it again") lock.end() - XCTAssertFalse(lock.isLocked, "A finished swipe frees Confirm") + XCTAssertFalse(lock.isLocked(isSubmittingPayment: false), "A finished swipe frees Confirm") lock.end() lock.begin() - XCTAssertTrue(lock.isLocked, "An extra end never frees a later swipe early") + XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "An extra end never frees a later swipe early") + + lock.end() + XCTAssertTrue(lock.isLocked(isSubmittingPayment: true), "A payment still running holds a Confirm rebuilt without the swipe") + lock.isVisible = false + XCTAssertFalse(lock.isLocked(isSubmittingPayment: true), "The screen the payment moves on to is free") } @MainActor diff --git a/journeys/send/update-spending-balance-payment.xml b/journeys/send/update-spending-balance-payment.xml index 111381ee0e..55378a0bf5 100644 --- a/journeys/send/update-spending-balance-payment.xml +++ b/journeys/send/update-spending-balance-payment.xml @@ -18,7 +18,7 @@ Verify the Confirm screen (id "SendConfirm") shows 50 000 sats with its details open on their own (Hide Details, id "SendConfirmToggleDetails") Verify the fee row shows the payment's own fee and the "Update fee" row (id "ReviewUpdateFee") shows an amount, without "up to", and that no "Route" row (id "ReviewSwapRoute") shows Swipe to pay (id "GRAB"); the payment is over half of the Spending balance, so verify the "Are You Sure?" dialog warns about sending over 50% of the balance and tap "Yes, Send" (id "DialogConfirm") - While the swipe still shows its loading state, swipe back from the left edge and drag the sheet down; verify the Confirm screen stays open with no Back button + While the swipe still shows its loading state, swipe back from the left edge and drag the sheet down; verify the Confirm screen stays open Verify the Bitcoin Sent screen (id "SendSuccess") shows 50 000 Go back to Home and verify Activity lists a "Move to Spark" transfer row and the 50 000-sat Lightning payment Open Settings › Advanced › Lightning Connections and verify the channel is closing or closed From 604e89c1277c8105ad17d5d1b5be8d9a86a79eaf Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 24 Nov 2026 22:48:46 +0100 Subject: [PATCH 3/7] fix: hold confirm again when the swipe returns to it Confirm applies its hold directly on appear and disappear, since a screen covered by the PIN may see no change in between. Verified: none (unit suite runs next) --- .../Wallets/Send/SendConfirmationView.swift | 21 ++++++++------ BitkitTests/SendConfirmationSwipeTests.swift | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift index 097f5d0e74..82fa9ff5c3 100644 --- a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift +++ b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift @@ -3218,18 +3218,21 @@ private struct ConfirmSwipeLockModifier: ViewModifier { func body(content: Content) -> some View { content - .onAppear { lock.isVisible = true } + // Applied directly on appear and disappear: a screen covered by the PIN may see no change in between. + .onAppear { + lock.isVisible = true + hold(lock.runs > 0 || isSubmittingPayment) + } .onDisappear { - if isLocked { - SwipeBackState.isHeldByConfirmSwipe = false - onLockChange(false) - } lock.isVisible = false + hold(false) } - .onChange(of: isLocked) { _, isLocked in - SwipeBackState.isHeldByConfirmSwipe = isLocked - onLockChange(isLocked) - } + .onChange(of: isLocked) { _, isLocked in hold(isLocked) } + } + + private func hold(_ isLocked: Bool) { + SwipeBackState.isHeldByConfirmSwipe = isLocked + onLockChange(isLocked) } } diff --git a/BitkitTests/SendConfirmationSwipeTests.swift b/BitkitTests/SendConfirmationSwipeTests.swift index f7d14230c1..2a8d36fc31 100644 --- a/BitkitTests/SendConfirmationSwipeTests.swift +++ b/BitkitTests/SendConfirmationSwipeTests.swift @@ -28,6 +28,34 @@ final class SendConfirmationSwipeTests: XCTestCase { XCTAssertFalse(lock.isLocked(isSubmittingPayment: true), "The screen the payment moves on to is free") } + @MainActor + func testConfirmTakesItsHoldBackWhenARunningSwipeReturnsToIt() async throws { + var lock = ConfirmSwipeLock() + lock.begin() + var reported: [Bool] = [] + let confirm = Color.black.confirmSwipeLock(.constant(lock), isSubmittingPayment: false) { reported.append($0) } + let controller = UIHostingController(rootView: AnyView(confirm)) + let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844)) + window.windowScene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first + window.rootViewController = controller + window.makeKeyAndVisible() + defer { window.isHidden = true; window.rootViewController = nil; SwipeBackState.isHeldByConfirmSwipe = false } + + try await Task.sleep(for: .milliseconds(300)) + XCTAssertEqual(reported.last, true, "Showing Confirm while its swipe runs holds the sheet") + XCTAssertTrue(SwipeBackState.isHeldByConfirmSwipe) + + controller.rootView = AnyView(Color.black) + try await Task.sleep(for: .milliseconds(300)) + XCTAssertEqual(reported.last, false, "The screen the swipe moves on to, such as the PIN, is free") + XCTAssertFalse(SwipeBackState.isHeldByConfirmSwipe) + + controller.rootView = AnyView(confirm) + try await Task.sleep(for: .milliseconds(300)) + XCTAssertEqual(reported.last, true, "Returning to Confirm while the swipe still runs holds it again") + XCTAssertTrue(SwipeBackState.isHeldByConfirmSwipe) + } + @MainActor func testRestoredLoadingSwipeKeepsItsSpinnerInTheKnob() async throws { let confirmation = NavigationStack(path: .constant([true])) { From 6b4fda9e4739771407d1df3efe5621feb2039c2b Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 24 Nov 2026 22:57:52 +0100 Subject: [PATCH 4/7] fix: free the sheet only from the confirm holding it A confirm leaving no longer clears a hold the next confirm already took, such as an LNURL confirm paying on its own. Verified: none (unit suite runs next) --- Bitkit/Views/Wallets/Send/SendConfirmationView.swift | 4 ++++ BitkitTests/SendConfirmationSwipeTests.swift | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift index 82fa9ff5c3..a9a4c882d2 100644 --- a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift +++ b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift @@ -3211,6 +3211,7 @@ private struct ConfirmSwipeLockModifier: ViewModifier { @Binding var lock: ConfirmSwipeLock let isSubmittingPayment: Bool let onLockChange: (Bool) -> Void + @State private var isHolding = false private var isLocked: Bool { lock.isLocked(isSubmittingPayment: isSubmittingPayment) @@ -3231,6 +3232,9 @@ private struct ConfirmSwipeLockModifier: ViewModifier { } private func hold(_ isLocked: Bool) { + // Only the screen holding the sheet frees it: the next confirm may already hold it. + guard isLocked || isHolding else { return } + isHolding = isLocked SwipeBackState.isHeldByConfirmSwipe = isLocked onLockChange(isLocked) } diff --git a/BitkitTests/SendConfirmationSwipeTests.swift b/BitkitTests/SendConfirmationSwipeTests.swift index 2a8d36fc31..288602e1bf 100644 --- a/BitkitTests/SendConfirmationSwipeTests.swift +++ b/BitkitTests/SendConfirmationSwipeTests.swift @@ -33,7 +33,7 @@ final class SendConfirmationSwipeTests: XCTestCase { var lock = ConfirmSwipeLock() lock.begin() var reported: [Bool] = [] - let confirm = Color.black.confirmSwipeLock(.constant(lock), isSubmittingPayment: false) { reported.append($0) } + let confirm = SwipeLockHost(lock: lock) { reported.append($0) } let controller = UIHostingController(rootView: AnyView(confirm)) let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844)) window.windowScene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first @@ -434,3 +434,12 @@ final class SendConfirmationSwipeTests: XCTestCase { } } } + +private struct SwipeLockHost: View { + @State var lock: ConfirmSwipeLock + let onLockChange: (Bool) -> Void + + var body: some View { + Color.black.confirmSwipeLock($lock, isSubmittingPayment: false, onLockChange: onLockChange) + } +} From c0e048511de195d2161f1428ef150b87a8dd8866 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 24 Nov 2026 23:09:48 +0100 Subject: [PATCH 5/7] fix: report the confirm hold as it changes The lock is an observable object that reports each change at once, not on the next redraw, which a screen covered by the PIN may skip. Swipe back and the sheet count their holders, so one confirm leaving never frees another, and automatic payments hold too. Verified: none (unit suite runs next) --- .../UINavigationController+SwipeBack.swift | 6 +- .../Views/Wallets/Send/LnurlPayConfirm.swift | 12 +-- .../Wallets/Send/SendConfirmationView.swift | 95 +++++++++---------- Bitkit/Views/Wallets/Send/SendSheet.swift | 12 ++- BitkitTests/SendConfirmationSwipeTests.swift | 88 ++++++++--------- 5 files changed, 99 insertions(+), 114 deletions(-) diff --git a/Bitkit/Extensions/UINavigationController+SwipeBack.swift b/Bitkit/Extensions/UINavigationController+SwipeBack.swift index 4fe4cd6df1..a3a4699b40 100644 --- a/Bitkit/Extensions/UINavigationController+SwipeBack.swift +++ b/Bitkit/Extensions/UINavigationController+SwipeBack.swift @@ -5,8 +5,8 @@ import UIKit enum SwipeBackState { /// When false, the interactive pop gesture is disabled. Set by views that hide the back button. static var allowSwipeBack: Bool = true - /// True while a running swipe holds a send confirm screen; kept apart so other screens' own setting stays theirs. - static var isHeldByConfirmSwipe = false + /// Send confirm screens a running swipe holds; kept apart so other screens' own setting stays theirs. + static var confirmSwipeHolds = 0 } /// Re-enables the interactive swipe-back gesture when the navigation bar is hidden @@ -22,6 +22,6 @@ extension UINavigationController: @retroactive UIGestureRecognizerDelegate { public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { // Only allow swipe-back when not at root — avoids iOS 17+ freeze when re-pushing after swiping to root guard viewControllers.count > 1 else { return false } - return SwipeBackState.allowSwipeBack && !SwipeBackState.isHeldByConfirmSwipe + return SwipeBackState.allowSwipeBack && SwipeBackState.confirmSwipeHolds == 0 } } diff --git a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift index f9f44dc6e9..c043635a81 100644 --- a/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift +++ b/Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift @@ -111,7 +111,7 @@ struct LnurlPayConfirm: View { screenVisit = ConfirmScreenVisit() } } - .confirmSwipeLock($swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) + .confirmSwipeLock(swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) .onDisappear { screenVisit.leave() } @@ -121,7 +121,7 @@ struct LnurlPayConfirm: View { VStack { SheetHeader( title: reviewTitle, - showBackButton: !isSwipeLocked, + showBackButton: !swipeLock.isLocked, action: AnyView(SendContactHeaderAvatar()) ) @@ -188,7 +188,7 @@ struct LnurlPayConfirm: View { .dismissKeyboardOnReturn(text: $comment, isFocused: $isCommentFocused) .lineLimit(3 ... 3) // The comment stays as swiped while the swipe runs - .disabled(isSwipeLocked) + .disabled(swipeLock.isLocked) .onChange(of: comment) { _, newValue in let maxLength = Int(commentAllowed) if newValue.count > maxLength { @@ -223,10 +223,6 @@ struct LnurlPayConfirm: View { .sheetBackground() } - private var isSwipeLocked: Bool { - swipeLock.isLocked(isSubmittingPayment: isSubmittingPayment) - } - private var reviewTitle: String { paykitPaymentReviewTitle(context: app.contactPaymentContext, fallback: t("wallet__lnurl_p_title")) } @@ -244,6 +240,8 @@ struct LnurlPayConfirm: View { } hasStartedAutomaticPayment = true do { + swipeLock.begin() + defer { swipeLock.end() } try await submitPayment(isAutomatic: true) } catch is CancellationError { navigationPath.append(.failure(SendFailureContext( diff --git a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift index a9a4c882d2..4534caf5ae 100644 --- a/Bitkit/Views/Wallets/Send/SendConfirmationView.swift +++ b/Bitkit/Views/Wallets/Send/SendConfirmationView.swift @@ -410,7 +410,7 @@ struct SendConfirmationView: View { VStack(alignment: .leading, spacing: 0) { SheetHeader( title: reviewTitle, - showBackButton: !navigationPath.isEmpty && !isSwipeLocked, + showBackButton: !navigationPath.isEmpty && !swipeLock.isLocked, action: AnyView(SendContactHeaderAvatar(publicKey: preparingRequest?.counterparty)) ) @@ -533,7 +533,7 @@ struct SendConfirmationView: View { } } // The payment's inputs stay as swiped while the swipe runs - .allowsHitTesting(!isSwipeLocked) + .allowsHitTesting(!swipeLock.isLocked) } private var confirmationPresentation: some View { @@ -628,7 +628,7 @@ struct SendConfirmationView: View { screenVisit = ConfirmScreenVisit() } } - .confirmSwipeLock($swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) + .confirmSwipeLock(swipeLock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange) .onDisappear { screenVisit.leave() startWalletSwitch(context: nil) @@ -689,6 +689,8 @@ struct SendConfirmationView: View { ) else { return } hasStartedAutomaticPayment = true do { + swipeLock.begin() + defer { swipeLock.end() } try await submitPayment(isAutomatic: true) } catch is CancellationError { navigationPath.append(.failure(SendFailureContext( @@ -1111,10 +1113,6 @@ struct SendConfirmationView: View { } } - private var isSwipeLocked: Bool { - swipeLock.isLocked(isSubmittingPayment: isSubmittingPayment) - } - private func submitPayment(isAutomatic: Bool = false) async throws { guard !isSubmittingPayment else { return } guard !requiresAmountReview, preparingRequest == nil, !isRequestSetupPending, walletSwitchContext == nil, @@ -3177,69 +3175,66 @@ final class ConfirmScreenVisit { } /// Holds a confirm screen while a swipe of it, or the payment it started, runs, until it moves on to the next screen or -/// returns to Confirm: Back, swipe back, the sheet's drag and the payment's inputs wait meanwhile. -struct ConfirmSwipeLock: Equatable { +/// returns to Confirm: Back, swipe back, the sheet's drag and the payment's inputs wait meanwhile. Each change reports at +/// once, not on the next redraw, since a screen covered by the PIN may not redraw. +@MainActor +@Observable +final class ConfirmSwipeLock { private(set) var runs = 0 - var isVisible = false + private(set) var isVisible = false + private(set) var isSubmittingPayment = false + @ObservationIgnored var onLockChange: (Bool) -> Void = { _ in } + @ObservationIgnored private var isHolding = false - /// The sheet's `isSubmittingPayment` outlives this screen's state, so a payment still holds a rebuilt Confirm. - func isLocked(isSubmittingPayment: Bool) -> Bool { + var isLocked: Bool { (runs > 0 || isSubmittingPayment) && isVisible } - mutating func begin() { + func begin() { runs += 1 + report() } - mutating func end() { + func end() { runs = max(0, runs - 1) + report() } -} -extension View { - /// Tracks the screen's stay for `lock`, holds swipe back while it locks, and reports each change to the sheet. - func confirmSwipeLock( - _ lock: Binding, - isSubmittingPayment: Bool, - onLockChange: @escaping (Bool) -> Void - ) -> some View { - modifier(ConfirmSwipeLockModifier(lock: lock, isSubmittingPayment: isSubmittingPayment, onLockChange: onLockChange)) + func setVisible(_ isVisible: Bool) { + self.isVisible = isVisible + report() } -} - -private struct ConfirmSwipeLockModifier: ViewModifier { - @Binding var lock: ConfirmSwipeLock - let isSubmittingPayment: Bool - let onLockChange: (Bool) -> Void - @State private var isHolding = false - private var isLocked: Bool { - lock.isLocked(isSubmittingPayment: isSubmittingPayment) + func setSubmittingPayment(_ isSubmittingPayment: Bool) { + self.isSubmittingPayment = isSubmittingPayment + report() } - func body(content: Content) -> some View { - content - // Applied directly on appear and disappear: a screen covered by the PIN may see no change in between. - .onAppear { - lock.isVisible = true - hold(lock.runs > 0 || isSubmittingPayment) - } - .onDisappear { - lock.isVisible = false - hold(false) - } - .onChange(of: isLocked) { _, isLocked in hold(isLocked) } - } - - private func hold(_ isLocked: Bool) { - // Only the screen holding the sheet frees it: the next confirm may already hold it. - guard isLocked || isHolding else { return } + private func report() { + guard isLocked != isHolding else { return } isHolding = isLocked - SwipeBackState.isHeldByConfirmSwipe = isLocked + SwipeBackState.confirmSwipeHolds += isLocked ? 1 : -1 onLockChange(isLocked) } } +extension View { + /// Tracks the screen's stay and payment for `lock`, which tells the sheet of each change. + func confirmSwipeLock( + _ lock: ConfirmSwipeLock, + isSubmittingPayment: Bool, + onLockChange: @escaping (Bool) -> Void + ) -> some View { + onAppear { + lock.onLockChange = onLockChange + lock.setSubmittingPayment(isSubmittingPayment) + lock.setVisible(true) + } + .onDisappear { lock.setVisible(false) } + .onChange(of: isSubmittingPayment) { _, isSubmitting in lock.setSubmittingPayment(isSubmitting) } + } +} + /// Tracks the newest spending balance update quote on Confirm, so an older quote finishing late writes neither its fee nor /// its quote, and only the newest one holds the swipe. struct SparkUpdateQuoteRuns: Equatable { diff --git a/Bitkit/Views/Wallets/Send/SendSheet.swift b/Bitkit/Views/Wallets/Send/SendSheet.swift index ff4ad6c466..f383b821be 100644 --- a/Bitkit/Views/Wallets/Send/SendSheet.swift +++ b/Bitkit/Views/Wallets/Send/SendSheet.swift @@ -96,8 +96,12 @@ final class SendPresentationState { var hasValidatedAfterSync = false var incomingPaymentRequest: PaykitPaymentRequest? var isSubmittingPayment = false - /// True while a running swipe holds Confirm; the sheet's drag waits for it too. - var isConfirmLocked = false + /// Confirm screens a running swipe holds; the sheet's drag waits for them too. + var confirmSwipeHolds = 0 + var isConfirmLocked: Bool { + confirmSwipeHolds > 0 + } + var isAmountReviewRequired = false var paymentReview: UUID? var isReviewingUsdtPayment = false @@ -1131,7 +1135,7 @@ struct SendSheet: View { isAmountReviewRequired: $flow.isAmountReviewRequired, amountIsRoot: currentRoot == .amount, isSetupPending: flow.isSetupPending || flow.isFallbackFundingPending, - onLockChange: { flow.isConfirmLocked = $0 } + onLockChange: { flow.confirmSwipeHolds += $0 ? 1 : -1 } ) case .hardwareSign: let contactContext = app.contactPaymentContext @@ -1266,7 +1270,7 @@ struct SendSheet: View { requestPinCheck: requestPinCheck, prepareIncomingPaymentRequest: prepareIncomingPaymentRequest, routingCacheResetAttempted: flow.routingCacheResetAttempted, - onLockChange: { flow.isConfirmLocked = $0 } + onLockChange: { flow.confirmSwipeHolds += $0 ? 1 : -1 } ) case .lnurlWithdrawAmount: LnurlWithdrawAmount { diff --git a/BitkitTests/SendConfirmationSwipeTests.swift b/BitkitTests/SendConfirmationSwipeTests.swift index 288602e1bf..ac12f6eb56 100644 --- a/BitkitTests/SendConfirmationSwipeTests.swift +++ b/BitkitTests/SendConfirmationSwipeTests.swift @@ -4,56 +4,53 @@ import SwiftUI import XCTest final class SendConfirmationSwipeTests: XCTestCase { + @MainActor func testARunningSwipeHoldsConfirmUntilItMovesOnOrReturns() { - var lock = ConfirmSwipeLock() - lock.isVisible = true - XCTAssertFalse(lock.isLocked(isSubmittingPayment: false)) + let holdsBefore = SwipeBackState.confirmSwipeHolds + let lock = ConfirmSwipeLock() + var reported: [Bool] = [] + lock.onLockChange = { reported.append($0) } + lock.setVisible(true) + XCTAssertFalse(lock.isLocked) lock.begin() - XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "A running swipe holds Back, the sheet's drag and the inputs") - lock.isVisible = false - XCTAssertFalse(lock.isLocked(isSubmittingPayment: false), "The screen the swipe moves on to, such as the PIN, is free") - lock.isVisible = true - XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "Returning to Confirm while the swipe still runs holds it again") - + XCTAssertTrue(lock.isLocked, "A running swipe holds Back, the sheet's drag and the inputs") + XCTAssertEqual(SwipeBackState.confirmSwipeHolds, holdsBefore + 1) + lock.setVisible(false) + XCTAssertFalse(lock.isLocked, "The screen the swipe moves on to, such as the PIN, is free") lock.end() - XCTAssertFalse(lock.isLocked(isSubmittingPayment: false), "A finished swipe frees Confirm") - lock.end() - lock.begin() - XCTAssertTrue(lock.isLocked(isSubmittingPayment: false), "An extra end never frees a later swipe early") + lock.setVisible(true) + XCTAssertFalse(lock.isLocked, "A swipe that stopped while the PIN covered Confirm leaves it free on return") + lock.begin() + lock.setVisible(false) + lock.setVisible(true) + XCTAssertTrue(lock.isLocked, "Returning to Confirm while the swipe still runs holds it again") lock.end() - XCTAssertTrue(lock.isLocked(isSubmittingPayment: true), "A payment still running holds a Confirm rebuilt without the swipe") - lock.isVisible = false - XCTAssertFalse(lock.isLocked(isSubmittingPayment: true), "The screen the payment moves on to is free") + lock.setSubmittingPayment(true) + XCTAssertTrue(lock.isLocked, "A payment still running holds a Confirm rebuilt without the swipe") + lock.setSubmittingPayment(false) + + XCTAssertEqual(reported, [true, false, true, false, true, false, true, false]) + XCTAssertEqual(SwipeBackState.confirmSwipeHolds, holdsBefore, "Every hold is let go") } @MainActor - func testConfirmTakesItsHoldBackWhenARunningSwipeReturnsToIt() async throws { - var lock = ConfirmSwipeLock() - lock.begin() - var reported: [Bool] = [] - let confirm = SwipeLockHost(lock: lock) { reported.append($0) } - let controller = UIHostingController(rootView: AnyView(confirm)) - let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844)) - window.windowScene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first - window.rootViewController = controller - window.makeKeyAndVisible() - defer { window.isHidden = true; window.rootViewController = nil; SwipeBackState.isHeldByConfirmSwipe = false } - - try await Task.sleep(for: .milliseconds(300)) - XCTAssertEqual(reported.last, true, "Showing Confirm while its swipe runs holds the sheet") - XCTAssertTrue(SwipeBackState.isHeldByConfirmSwipe) - - controller.rootView = AnyView(Color.black) - try await Task.sleep(for: .milliseconds(300)) - XCTAssertEqual(reported.last, false, "The screen the swipe moves on to, such as the PIN, is free") - XCTAssertFalse(SwipeBackState.isHeldByConfirmSwipe) - - controller.rootView = AnyView(confirm) - try await Task.sleep(for: .milliseconds(300)) - XCTAssertEqual(reported.last, true, "Returning to Confirm while the swipe still runs holds it again") - XCTAssertTrue(SwipeBackState.isHeldByConfirmSwipe) + func testALeavingConfirmKeepsTheNextConfirmsHold() { + let holdsBefore = SwipeBackState.confirmSwipeHolds + let leaving = ConfirmSwipeLock() + let next = ConfirmSwipeLock() + leaving.setVisible(true) + leaving.begin() + next.setVisible(true) + next.setSubmittingPayment(true) + + leaving.setVisible(false) + XCTAssertEqual(SwipeBackState.confirmSwipeHolds, holdsBefore + 1, "The next confirm's payment still holds swipe back") + + leaving.end() + next.setVisible(false) + XCTAssertEqual(SwipeBackState.confirmSwipeHolds, holdsBefore) } @MainActor @@ -434,12 +431,3 @@ final class SendConfirmationSwipeTests: XCTestCase { } } } - -private struct SwipeLockHost: View { - @State var lock: ConfirmSwipeLock - let onLockChange: (Bool) -> Void - - var body: some View { - Color.black.confirmSwipeLock($lock, isSubmittingPayment: false, onLockChange: onLockChange) - } -} From 4fa8a721ea714f7670a266cea61b7be30b719dab Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Wed, 25 Nov 2026 00:10:45 +0100 Subject: [PATCH 6/7] test: drag only on a confirm opened from a link A confirm opened from a lightning: link is the sheet's root, with no Back or swipe back to try, so the journey drags the sheet only. Verified: J1 on a regtest simulator at c0e048511 (journey text only) --- journeys/send/update-spending-balance-payment.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/journeys/send/update-spending-balance-payment.xml b/journeys/send/update-spending-balance-payment.xml index 55378a0bf5..13ebba5dbb 100644 --- a/journeys/send/update-spending-balance-payment.xml +++ b/journeys/send/update-spending-balance-payment.xml @@ -6,7 +6,8 @@ Activity as a "Move to Spark" row, and the emptied channel closes in the background. If the payment fails after the move, the funds stay in Spark and the usual payment error shows. QuickPay never sends such a payment; it always opens the confirm screen. From the swipe until it moves on or returns to confirm, the confirm screen is locked: no - Back, no sheet dismiss and no edits. + Back, no sheet dismiss and no edits. On iOS a confirm screen opened from a link is the sheet's root, with no Back to + press, so only the sheet's drag applies there; a confirm reached from Amount also hides Back and swipe back. Precondition: dev build pointed at a local Spark regtest (spark-sdk regtest/local), QuickPay off, a wallet with an open channel to that stack's SSP Lightning node that can send about 30 000 sats and a Spark balance of about @@ -18,7 +19,7 @@ Verify the Confirm screen (id "SendConfirm") shows 50 000 sats with its details open on their own (Hide Details, id "SendConfirmToggleDetails") Verify the fee row shows the payment's own fee and the "Update fee" row (id "ReviewUpdateFee") shows an amount, without "up to", and that no "Route" row (id "ReviewSwapRoute") shows Swipe to pay (id "GRAB"); the payment is over half of the Spending balance, so verify the "Are You Sure?" dialog warns about sending over 50% of the balance and tap "Yes, Send" (id "DialogConfirm") - While the swipe still shows its loading state, swipe back from the left edge and drag the sheet down; verify the Confirm screen stays open + While the swipe still shows its loading state, drag the sheet down; verify the Confirm screen stays open Verify the Bitcoin Sent screen (id "SendSuccess") shows 50 000 Go back to Home and verify Activity lists a "Move to Spark" transfer row and the 50 000-sat Lightning payment Open Settings › Advanced › Lightning Connections and verify the channel is closing or closed From 535e5cf00c24e88d33039d3b2a35f344a8576361 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Wed, 25 Nov 2026 00:11:23 +0100 Subject: [PATCH 7/7] chore: note the confirm lock in the changelog Verified: none (changelog only) --- changelog.d/next/1418.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/next/1418.fixed.md diff --git a/changelog.d/next/1418.fixed.md b/changelog.d/next/1418.fixed.md new file mode 100644 index 0000000000..2b5122ee89 --- /dev/null +++ b/changelog.d/next/1418.fixed.md @@ -0,0 +1 @@ +Keep the payment confirm screen open while a swipe is paying, so leaving can't undo it silently.