fix(pos-app): cancel payment when leaving scan screen via back - #609
Conversation
Wire the scan screen's cancel logic into a `beforeRemove` navigation listener so the hardware back button, header back arrow and swipe-back gesture all cancel the open payment, not just the on-screen Cancel button. Guard with `hasNavigatedRef` so success/failure navigations never cancel, and block the Android hardware back while the header back and gesture are hidden. Bump android versionCode 2 -> 3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
Claude finished @ignaciosantise's task in 2m 38s —— View job Review checklist
Found 2 issue(s)Issue 1:
|
There was a problem hiding this comment.
Pull request overview
This PR ensures any in-progress POS payment is consistently cancelled at the gateway when the user leaves the scan screen via navigation back actions (hardware back, header back, or swipe-back), instead of only via the on-screen Cancel button. It centralizes the cancel-on-leave behavior and prevents unintended cancels during success/failure routing.
Changes:
- Add a single
beforeRemovenavigation listener on the scan screen to cancel pending payments on any “leave screen” action (with guards to avoid cancelling on terminal navigation). - Add an
enabledflag touseDisableBackButtonand use it on the scan screen to block Android hardware back when back/gesture UI is hidden. - Bump Android
versionCodefrom 2 → 3.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dapps/pos-app/hooks/use-disable-back-button.ts | Adds an enabled parameter so hardware-back blocking can be toggled by screen state. |
| dapps/pos-app/app/scan.tsx | Centralizes cancel-on-leave via beforeRemove, guards terminal navigations, and blocks Android hardware back when back UI is hidden. |
| dapps/pos-app/app.json | Increments Android versionCode to reflect the release change. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Hold cancelPendingPayment in a ref so the beforeRemove listener registers once for the screen's lifetime instead of re-registering on every status poll. Drop "Try again" from the cancel-failure toast since the user has already left the scan screen by the time it rejects. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@claude review |
|
Claude finished @ignaciosantise's task in 2m 18s —— View job Review checklist
🔄 Incremental Review (continuing from prior auto-review) Both previously flagged issues are resolved in the current commits:
The Found 1 issue(s)Issue 1: Payment opened at gateway not cancelled when user backs out during in-flight
|
Close the remaining leak: if the user leaves the scan screen while the initial startPayment create call is still in flight, paymentId state doesn't exist yet for the beforeRemove listener to cancel. Track the leave in a ref and cancel the freshly opened payment when the call resolves, skipping the now-unmounted state updates and terminal routing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@claude review |
|
Claude finished @ignaciosantise's task in 1m 25s —— View job Review checklist
🔄 Incremental Review (continuing from prior reviews) Previously flagged issue is resolved in the current commits:
✅ No new issues found in latest commits. The |
Summary
Pressing back on the POS scan screen previously left the payment open at the gateway — only the on-screen Cancel button cancelled it. This wires the cancel logic into a single
beforeRemovenavigation listener so the hardware back button, header back arrow, and swipe-back gesture all cancel the payment uniformly.Success and failure navigations are guarded by
hasNavigatedRef(set before routing), so reaching a terminal state never triggers a cancel. The Android hardware back button is now also blocked while the header back and gesture are hidden (e.g. duringprocessing). Also bumps AndroidversionCode2 → 3.Flow
flowchart TD A[User on scan screen] --> B{How do they leave?} B -->|Hardware back / header back / swipe| C[beforeRemove listener] B -->|Cancel button| D[resetNavigation] --> C B -->|Payment succeeds/fails| E[hasNavigatedRef = true] --> F[Navigate to result] --> C C --> G{hasNavigatedRef or already cancelled?} G -->|Yes| H[Skip - no cancel] G -->|No| I{status undefined or requires_action?} I -->|Yes| J[cancelPayment] I -->|No| H