Skip to content

fix: open confirm for requests with a fixed amount - #1198

Merged
jvsena42 merged 23 commits into
masterfrom
fix/scan-amount-to-confirm
Nov 5, 2026
Merged

jvsena42 merged 23 commits into
masterfrom
fix/scan-amount-to-confirm

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Twin: synonymdev/bitkit-android#1763
Companion: synonymdev/bitkit-e2e-tests#290 — updates send.e2e.ts for this route; the e2e gate needs it, so merge them together.

Rebased onto master after #1014 merged. #1014 fixes the fixed-price Payment Request routing from the Slack report, so this PR covers the BIP21 routing only.

This PR:

  1. Opens Confirm directly when an on-chain BIP21 request with an amount is scanned, pasted or opened as a link, and never opens Amount for it: the payee set the amount, so it cannot be edited
  2. Opens the USDT review directly for a USDT link or URI with an amount, with the same fixed amount

Description

  • Routes an on-chain BIP21 request with an amount of at least 547 sats to Confirm instead of Amount. The balance is checked when it is scanned. A smaller amount shows an "Amount Too Low" toast and opens nothing. Zero-amount requests and contact payments without an incoming request still open the editable Amount screen.
  • The scanned amount is fixed: tapping it on Confirm does nothing, as with a fixed Lightning amount, and no path leads back to Amount.
  • Runs the saved automatic coin selection on Confirm, so fees and inputs match the Amount route. Manual coin selection opens UTXO selection on swipe. The swipe stays disabled until the coins are chosen and, on every on-chain Confirm, until the fee calculation finishes, so a swipe can no longer skip the fee warnings or record a zero fee.
  • When coin selection fails because Savings is below the amount, Confirm switches to the first paired hardware wallet whose balance covers it. Any other coin-selection failure, or a failed hardware fee preview for the initial source, shows the error and leaves Confirm (steps back, or closes the sheet when Confirm is the first screen). A preview failure after the user switches funding source keeps Confirm open so another source can be picked.
  • Resets the amount, max-send flag and coin choices from an earlier recipient when a scan inside the send sheet opens Confirm directly, so the invoice amount is the one sent.
  • A USDT link or URI with a positive amount quotes on entry and opens a review with the amount fixed. The fixed amount belongs to the recipient that set it; another recipient gets the editable Amount step. A failed quote shows its error and Try Again on that review, and Back returns to the recipient step. uint256=0 counts as no amount.

Out of Scope

  • Lightning bolt11 routing is unchanged.
  • Opening a rejected link (over the balance or below the minimum) while a Confirm is open leaves that Confirm with a blank amount behind the toast; this predates this PR.

Design

N/A — no new screens. The USDT review shows a loading state while the quote runs, using the existing review layout.

Preview

BIP21 with an amount opens Confirm and sends 10 000 sats:

01-bip21-amount-opens-confirm-and-sends.mp4

Below the minimum, the link shows Amount Too Low and opens nothing:

USDT link with an amount opens the fixed review; with no USDT the quote error and Try Again show there:

r9-fixed-amount.mp4

Savings below the amount: Confirm moves to a paired Trezor that covers it:

Zero-amount BIP21 still opens Amount:

02-bip21-no-amount-opens-amount.mp4

QA Notes

Setup

  • bitkit-docker on local regtest, E2E_BUILD debug build on a simulator, wallet funded from the local bitcoind. Clipboard set with xcrun simctl pbcopy. Hardware cases used the Trezor User Env emulator over Bridge.

Journeys

  • J1: new scan-onchain-amount-to-confirm.xml — pasted BIP21 with an amount opens Confirm without Amount, tapping the amount keeps Confirm open, the send completes, and a below-minimum link shows Amount Too Low
  • J2: new scan-onchain-no-amount-to-amount.xml — pasted BIP21 without an amount still opens Amount
  • J3: updated onchain-accepted-result.xml — the fixed-amount bitcoin: link opens Confirm directly
  • J4: updated rbf-own-send.xml — the bitcoin: link with an amount opens the review screen directly
  • J5: updated usdt-payment-links-and-scans.xml — a USDT link with an amount opens the fixed review

Manual Tests

N/A

Automated Checks

  • PaymentNavigationHelperTests — on-chain BIP21 with an amount opens Confirm from both entry points, zero amount opens Amount, contact payments keep Amount, incoming on-chain requests open Confirm, the 547-sat minimum
  • SendConfirmationSwipeTests — a scanned amount cannot be edited; the swipe waits for coins and the newest fee calculation; a failed hardware preview leaves Confirm only for its initial source; Savings below the amount moves to a covering hardware wallet, and any other coin-selection failure does not
  • WalletViewModelSendTests — restoring the scanned amount clears coins chosen for an edited amount
  • UsdtPaymentLinkTests — the fixed USDT amount stays with the recipient that set it
  • ScannerManagerTests — delayed-image case moved to 1 000 sats, above the new minimum
  • UsdtWalletUITests — a USDT URI with an amount opens the fixed review
  • Latest local run (1730836): SendConfirmationSwipeTests, SendConfirmationLifecycleTests, PaymentNavigationHelperTests 71/71, checked in the xcresult. SwiftFormat clean.

Evidence

Gaps

  • A transient coin-selection failure with enough Savings (1730836) was not driven; the unit test covers it.
  • A hardware preview failure after a funding switch (af79332) needs a second funded hardware wallet holding less than the amount; not driven.
  • The funding-switch race fixed in d4f7682 needs a switch inside a ~40 ms fee calculation; covered by a unit test only.
  • USDT success branch: the wallet has no USDT, so only the quote-error review was reached.
  • J3 and J4 were driven only up to Confirm.
  • e2e: @send_1 and @send_2 are updated in test: expect review screen for bip21 with an amount bitkit-e2e-tests#290; the iOS e2e gate passed against that branch.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: Not exposed)
  • Implementation: claude-opus-5-5 (reasoning: Not exposed)
  • Review: Not performed

🤖 Generated with Claude Code

@ovitrif ovitrif added this to the 3.2.0 milestone Nov 3, 2026
@ovitrif

ovitrif commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Added to the 3.2.0 milestone with its Android twin synonymdev/bitkit-android#1763: this fix was opened after the 3.1.0 cut and closes no issue, so this PR carries the milestone itself.

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

Fixed-amount Bitcoin requests open Confirm directly. USDT requests open review with the amount locked.

  • On-chain requests with a fixed amount open Confirm directly.
  • Amount-bearing USDT requests open a fixed-amount review.

Reviews (9) · Last reviewed commit: "fix: move to a hardware wallet only when..." · Reviewed by Greptile

@jvsena42 jvsena42 self-assigned this Nov 3, 2026
@jvsena42
jvsena42 requested review from a team, ben-kaufman and pwltr and removed request for a team November 3, 2026 13:55
@jvsena42
jvsena42 marked this pull request as draft November 3, 2026 13:56
@jvsena42
jvsena42 requested a review from talosmachina November 3, 2026 13:57

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

1 finding (1 P1). Routes a BIP21 request with an amount, and a converted Payment Request that only Bitcoin can pay, straight to Confirm. Reviewed f751a46, full tier, statically: iOS does not build on this reviewer's Linux host, so nothing was compiled or run here.

What I checked, and 5 candidates I ruled out

Read: the full diff, plus PaymentNavigationHelper (all three route functions), AppViewModel.handleScannedData (contact and BIP21 branches), SendSheet setup, cleanup and performPaymentValidationAfterSync, SendConfirmationView task, fee calculation and wallet switch, SendAmountView.onContinue, WalletViewModel.setUtxoSelection
Call sites traced: appropriateSendRoute (ScannerManager, SendEnterManuallyView, AppScene), openPaymentSheet (scanner, clipboard, deep link, Shop), paykitPaymentTerms readers
CI: lint, translations and build-local green; unit tests, integration tests and the @ios_gate e2e shard still running at review time

Ruled out

  • Stale amount from an earlier recipient on the deep link, clipboard and Shop paths: each opens a new sheet whose setUpSend calls wallet.resetSendState, and Confirm's ensureSendAmountFromScannedInvoicesIfNeeded then fills the invoice amount. Only the in-sheet scan reuses wallet state, and that is the path prepareFixedAmountOnchainSend covers. Manual entry resets before decoding.
  • Hardware wallet send skips the preview Amount used to build: calculateTransactionFee calls hwSend.preparePreview on Confirm itself, and the new coin selection guards on !hwSend.isActive.
  • Bound Bitcoin terms rejected later by the amount checks: fixedBitcoinPaymentTerms returns exactly request.payment(using:) for the same method, so acceptsPaymentAmount(..., paymentTerms:) and returnToAmountReviewIfNeeded compare equal values; an expired quote is refused by isValid and falls back to Amount.
  • Terms bound while USDT can still pay: the guard requires USDT off or no USDT endpoint, and the binding only runs when paykitUsesUsdt is false; the tests cover both sides.
  • Swipe racing the new coin selection: real, but already raised in Greptile's thread on SendConfirmationView.swift:428, so not repeated here.

Merge confidence: 3/5, one P1 (the @ios_gate e2e spec still expects the Amount step), and unit and e2e CI had not finished.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the review runtime does not report an effort setting)

@jvsena42

jvsena42 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Direct Confirm from bitcoin:…?amount=0.0001 after cc8fce9 (local regtest, fresh wallet with 500 000 sats): Confirm opens, the swipe stays disabled until Branch and Bound coin selection and the 143-sat fee finish (about 0.57 s after the sheet appears), then the swipe sends 10 000 sats with the selected coin.

direct-confirm-swipe.mp4

@jvsena42

jvsena42 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Amount → Confirm after edefd08 (local regtest): Continue, then an immediate swipe. Coins were chosen at 14:20:49.933 and the 143-sat fee at .974, and the send went out at 50.955. Tx 2df859… reached the mempool with 143 sats fee.

amount-confirm-early-swipe.mp4

@pwltr pwltr 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.

Reviewed commit edefd08 through independent general and security review, targeted finding verification and peer comparison. The Debug simulator build, lint and 39 scoped tests passed.

[P2] Switching funding sources during fee calculation can leave sending disabled

If a Savings fee calculation is still running when the user switches to Spending or hardware, the newer calculation advances feeCalculationId without clearing isCalculatingOnchainFee. The old calculation then refuses to clear it because its ID is stale. The retained flag disables both the swipe and manual submission. Clear or transfer the loading state when a calculation is superseded, including early-return paths. This is the same issue already reported by ben-kaufman, confirmed separately by source tracing.

[P3] Direct confirmation skips the app’s minimum-amount check

A positive plain BIP21 amount now routes directly to Confirm, bypassing Amount’s 547-sat minimum. With manual coin selection, neither Confirm nor the picker restores that validation gate before submission. Apply the same minimum validation to direct confirmation. This confirms the missing application check; it does not establish how the native library will reject a sub-minimum transaction.

Review details

General review
Model: Claude Opus 5.5
Reasoning effort: xhigh

Security review
Model: Kimi K3
Reasoning effort: high

Finding verification, peer comparison and scoped validation
Model: GPT-6.1-sol
Reasoning effort: xhigh

@jvsena42
jvsena42 marked this pull request as draft November 4, 2026 08:44
@jvsena42

jvsena42 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

After 1d5294f (local regtest): bitcoin:…?amount=0.000005 (500 sats) opens Amount at 500 with Continue disabled. ?amount=0.00000547 (547 sats, Env.dustLimit) opens Confirm.

below-minimum-opens-amount.mp4

@jvsena42

jvsena42 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Replying to the review on edefd08:

  • [P2] Switching funding sources during fee calculation: fixed in d4f7682. The same finding is in the thread at fix: open confirm for requests with a fixed amount #1198 (comment). Only the newest calculation can hold the swipe now (onchainFeeCalculationId compared with feeCalculationId), so a superseded calculation can no longer leave it disabled. Covered by testOnlyTheNewestFeeCalculationHoldsTheSwipe. The race window itself was not driven on a device.
  • [P3] Direct confirmation skips the minimum: fixed in 1d5294f. onchainInvoiceRoute opens Confirm only at Env.dustLimit (547 sats) or more, the same bar SendAmountView.isValidAmount uses for on-chain. Below it, Amount opens and shows why it cannot continue. Tests testOnchainInvoiceBelowMinimumOpensAmount and testOnchainInvoiceAtMinimumOpensConfirm. On the simulator, 500 sats opens Amount with Continue disabled and 547 sats opens Confirm (video: fix: open confirm for requests with a fixed amount #1198 (comment)). Android twin: openOnchainConfirmForInvoiceAmount already requires validateAmount, which rejects dust, and main scanner onchain scan with dust amount opens amount sheet covers it.

@jvsena42
jvsena42 marked this pull request as ready for review November 4, 2026 09:04
@jvsena42
jvsena42 requested review from ben-kaufman and pwltr November 4, 2026 09:04
@jvsena42

jvsena42 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Rebase reminder: #1014 fixes the same Paykit routing root cause, and it merged into master first (f75f2d5, 2026-11-04 09:08 UTC). This PR now conflicts with master in:

  • PaymentNavigationHelper.swift
  • AppViewModel.swift
  • SendConfirmationView.swift
  • PaymentNavigationHelperTests.swift
  • SendConfirmationSwipeTests.swift
  • journeys/payment-requests/README.md
  • journeys/payment-requests/fixed-price-bitcoin.xml

Before merging, rebase onto master:

jvsena42 and others added 4 commits November 4, 2026 06:16
A BIP21 request with an amount now opens Confirm instead of Amount when
scanned, pasted or opened as a link. Confirm runs the saved automatic coin
selection when it is reached without Amount and opens Amount if selection
fails. In-sheet scans that open Confirm directly drop the amount and coin
choices left by an earlier recipient. Zero-amount requests and contact
payments still open Amount.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
auto-merge was automatically disabled November 4, 2026 21:30

Pull request was converted to draft

jvsena42 and others added 3 commits November 4, 2026 18:34
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 4, 2026 21:48
@jvsena42
jvsena42 enabled auto-merge November 4, 2026 21:48

@pwltr pwltr 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.

Reviewed commit e29bdc5.

Medium — keep hardware funding selectable when Savings cannot fund a fixed request. With Autopilot, insufficient Savings and a sufficiently funded hardware wallet, an ordinary positive-amount Bitcoin scan or deep link passes the balance check but starts confirmation with Savings selected. If that coin selection fails, Confirm is popped or the sheet is dismissed before a funding-selection surface is preserved. The user must restart through a hardware-wallet entry despite already having enough funds. Keep Confirm or another funding-selection surface available on this failure. The pinned base opened Amount first, where hardware funding could be selected before confirmation. Confirmed by static path tracing; not reproduced on a device.

Review details

General review: GPT-6.1 Sol / high (Codex).

Finding verification: GPT-6.1 Sol / high (Codex).

jvsena42 and others added 2 commits November 4, 2026 19:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42

jvsena42 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

On pwltr's Medium finding at e29bdc5 (hardware funding when Savings can't fund a fixed request): fixed in 3b7b5c3.

When automatic coin selection fails on a fixed-amount Confirm because Savings can't cover the amount, Confirm now switches to the first paired hardware wallet whose balance covers it (hardwareWalletCovering), instead of leaving. The switch runs that wallet's fee preview. If the preview fails, Confirm stays with the error (af79332), so another source can still be picked. If no hardware wallet covers the amount, the earlier exit with the error stays. Android does the same at scan time (bitkit-android#1763, 46cd209).

On the simulator, with Savings at 209 714 sats and a paired "Bitkit Test Trezor" at 549 577: a bitcoin:…?amount=0.003 link (300 000 sats) opens Confirm. Coin selection on Savings fails ("Coin selection failed to find suitable UTXOs"), and Confirm switches to the Trezor, showing From "Bitkit Test Trezor" and a 209-sat fee, with the swipe enabled. Nothing was sent.

Test: SendConfirmationSwipeTests.testAFixedAmountSavingsCannotPayMovesToAHardwareWalletThatCovers.

CI on e29bdc5: Run Tests failed in two classes.

  • ScannerManagerTests.testDelayedImageCannotOverwriteNewerScanInSameSend scanned a 200-sat amount, which 122d07a now rejects as below the minimum. 6a06f57 moves it to 1 000 sats, so it still checks that a delayed image can't overwrite a newer scan.
  • PubkyImageCacheTests (avatar disk cache) passes locally. This PR doesn't touch that code.

SendConfirmationSwipeTests, SendConfirmationLifecycleTests, ScannerManagerTests and PaymentNavigationHelperTests pass, 82/82.

@jvsena42
jvsena42 requested a review from pwltr November 4, 2026 22:39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42

jvsena42 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

CI on 6a06f57: UsdtWalletUITests.testReceiveAndInvalidPaymentStaySeparateFromBitcoin failed because of this PR. It typed a USDT URI with uint256=1.23e6 and expected the editable Amount number pad, but a URI with an amount now opens the fixed review. f39ae55 updates the test:

  • the URI now opens the fixed review (UsdtConfirmLoading) showing $ 1.23, with no number pad
  • the six-decimal cap is still checked: Back, then a different recipient, opens the editable Amount step with 1.23 prefilled, and digits 4 to 8 give $ 1.234567

The test passes locally, 1/1.

@pwltr pwltr 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.

Reviewed f39ae55 against f75f2d5.

When Savings cannot pay a fixed amount, Confirm now moves to a hardware wallet that can, and a failing hardware preview after that switch keeps Confirm with the error. One Low finding:

Low: in selectCoinsForDirectOnchainSendIfNeeded (SendConfirmationView.swift:2032), the switch runs for any coin-selection error, not only when Savings is short, and skips the error toast. A transient selection failure with enough Savings moves the payment to a hardware wallet without saying why. Consider switching only when the spendable on-chain balance is below the amount, and otherwise keeping the toast.

Review details

Claude Opus 5.5, effort high

@jvsena42
jvsena42 marked this pull request as draft November 5, 2026 09:34
auto-merge was automatically disabled November 5, 2026 09:34

Pull request was converted to draft

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42

jvsena42 commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

On the Low finding in the review of f39ae55 (hardware switch on any coin-selection error): fixed in 1730836.

It reproduced in the code. selectCoinsForDirectOnchainSendIfNeeded switched to a covering hardware wallet for every error from setUtxoSelection, such as a transient LDK failure, with no toast. hardwareWalletCovering now takes the spendable Savings balance and returns a wallet only when Savings is below the amount. Every other failure shows the "Try again" toast with the error and leaves Confirm, as before 3b7b5c3. This matches Android (synonymdev/bitkit-android#1763, 46cd209), which switches only when validateAmount fails for Savings.

Test: SendConfirmationSwipeTests.testACoinSelectionFailureWithEnoughSavingsDoesNotMoveToAHardwareWallet. With 209 714 sats in Savings and a 549 577 sat device, amounts of 10 000 and 209 714 get no hardware wallet. Before the fix, the helper had no Savings input and returned the device for both. testAFixedAmountSavingsCannotPayMovesToAHardwareWalletThatCovers still passes for 300 000. SendConfirmationSwipeTests, SendConfirmationLifecycleTests and PaymentNavigationHelperTests pass, 71/71, checked in the xcresult. SwiftFormat is clean.

Not driven on a device: a transient coin-selection failure can't be triggered on demand from the app. The Savings-short path is unchanged from the 3b7b5c3 device run.

@jvsena42
jvsena42 marked this pull request as ready for review November 5, 2026 09:37
@jvsena42
jvsena42 enabled auto-merge November 5, 2026 09:37
@jvsena42
jvsena42 requested a review from pwltr November 5, 2026 09:37

@pwltr pwltr 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.

Reviewed 1730836 against f75f2d5.

The hardware fallback now runs only when Savings is short of the amount, and other coin-selection failures show their error. This resolves my earlier Low finding. No new findings.

Review details

Claude Opus 5.5, effort high

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.

5 participants