Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Bitkit/Components/SwipeButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct SwipeButton: View {
var isComplete = false
/// Optional binding for swipe progress (0...1), e.g. to drive animations in the parent.
var swipeProgress: Binding<CGFloat>?
/// Each change puts a submitted knob back at the start, for a swipe whose screen moved on without the swipe throwing.
var resetCount = 0
let onComplete: () async throws -> Void

@State private var offset: CGFloat = 0
Expand Down Expand Up @@ -125,6 +127,11 @@ struct SwipeButton: View {
}
.frame(maxWidth: .infinity)
.frame(height: buttonHeight)
.onChange(of: resetCount) {
if isSubmitting {
reset()
}
}
Comment thread
ovitrif marked this conversation as resolved.
Resolved
}

private func reset() {
Expand Down
3 changes: 2 additions & 1 deletion Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ struct LnurlPayConfirm: View {
accentColor: .greenAccent,
isDisabled: isSparkUpdateQuoting,
isLoading: hasStartedAutomaticPayment || isSubmittingPayment,
isSubmitted: hasStartedAutomaticPayment
isSubmitted: hasStartedAutomaticPayment,
resetCount: swipeLock.idleReturns
) {
swipeLock.begin()
defer { swipeLock.end() }
Expand Down
9 changes: 8 additions & 1 deletion Bitkit/Views/Wallets/Send/SendConfirmationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ struct SendConfirmationView: View {
isSubmittingPayment: isSubmittingPayment
),
isSubmitted: hasStartedAutomaticPayment,
swipeProgress: $swipeProgress
swipeProgress: $swipeProgress,
resetCount: swipeLock.idleReturns
) {
swipeLock.begin()
defer { swipeLock.end() }
Expand Down Expand Up @@ -3183,6 +3184,9 @@ final class ConfirmSwipeLock {
private(set) var runs = 0
private(set) var isVisible = false
private(set) var isSubmittingPayment = false
/// Counts the returns to Confirm with nothing running, such as Back or Try again after a failed payment, which leave
/// the swipe as it ended.
private(set) var idleReturns = 0
@ObservationIgnored var onLockChange: (Bool) -> Void = { _ in }
@ObservationIgnored private var isHolding = false

Expand All @@ -3202,6 +3206,9 @@ final class ConfirmSwipeLock {

func setVisible(_ isVisible: Bool) {
self.isVisible = isVisible
if isVisible, runs == 0, !isSubmittingPayment {
idleReturns += 1
}
report()
}

Expand Down
23 changes: 23 additions & 0 deletions BitkitTests/SendConfirmationSwipeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ final class SendConfirmationSwipeTests: XCTestCase {
XCTAssertEqual(SwipeBackState.confirmSwipeHolds, holdsBefore, "Every hold is let go")
}

@MainActor
func testReturningToConfirmWithNothingRunningResetsTheSwipe() {
let lock = ConfirmSwipeLock()
lock.setVisible(true)
let shown = lock.idleReturns

lock.begin()
lock.setVisible(false)
lock.setVisible(true)
XCTAssertEqual(lock.idleReturns, shown, "A swipe still running keeps its knob")
lock.setVisible(false)
lock.end()
lock.setSubmittingPayment(true)
lock.setVisible(true)
XCTAssertEqual(lock.idleReturns, shown, "A payment still running keeps its knob")
lock.setVisible(false)
lock.setSubmittingPayment(false)

lock.setVisible(true)
XCTAssertEqual(lock.idleReturns, shown + 1, "Try again or Back after a failed payment takes a new swipe")
lock.setVisible(false)
}
Comment thread
ovitrif marked this conversation as resolved.
Resolved

@MainActor
func testALeavingConfirmKeepsTheNextConfirmsHold() {
let holdsBefore = SwipeBackState.confirmSwipeHolds
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1430.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Retrying a failed payment from the send confirmation screen takes a new swipe instead of leaving the slider spinning.
Loading