Repository navigation
fix: compose a hardware-funded request once - #1221
Conversation
Choosing the hardware wallet for a payment request now composes the exact payment instead of a send-max, and hands its fee to the confirmation, which reuses it while the wallet, address, amount, fee rate and balance match. The confirmation no longer runs a second compose for the same payment. Fixes #1187 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge; no actionable new issues were found. SummaryHardware-funded requests reuse the fee from the compose that selected the wallet, avoiding a second compose before confirmation.
Reviews (2) · Last reviewed commit: "fix: key the hardware fee preview on the..." · Reviewed by Greptile |
|
Placed in 3.2.0 with its twin: #1187 was already in the milestone, and the twin synonymdev/bitkit-android#1785 closes synonymdev/bitkit-android#1786. |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Composes a hardware-funded payment request once: selectHardwareFundingSourceIfNeeded now composes the exact payment per wallet, largest balance first, and seeds that fee into HwSendCoordinator. preparePreview then reuses it while the wallet, payment and balance are unchanged. Reviewed 0092df0, full tier. Static review: iOS does not build on this machine, so this is reasoned from the code and from CI. Twin: synonymdev/bitkit-android#1785.
CI is red because of this diff. SwiftFormat fails the indent rule on Bitkit/Views/Wallets/Send/SendSheet.swift:604-608, which are the guard let amount = try? request.payment(...) continuation lines this PR re-indented. The same lint passes on master, so restoring the previous indentation (or running swiftformat on the file) clears it. build-local failed earlier, at "Verify current PR merge checkout" ("Checked-out merge does not match the PR's current base and head"), so that run checked nothing in the code. Unit and integration tests were still running.
What I checked, and 4 candidates I ruled out
Read: the HwFundingSigner.swift diff with selectWallet, seedPreview, preparePreview and ComposedPreview; the whole selectHardwareFundingSourceIfNeeded loop in SendSheet.swift; every reader of hwSend.availableSats (SendAmountView, SendConfirmationView warnings, SendFeeRate, SendFeeCustom).
Ruled out
seedPreviewracingselectWallet:seedPreviewreturns early unlessselectWalletactually switched to that wallet. WhenselectWalletrefuses (an operation is in flight), nothing is seeded and the confirmation composes as before.- Stale reuse:
preparePreviewcompares wallet, request (address, sats, fee rate) and a balance read before composing.selectWalletclears the cache, so a switch or a fee-rate change composes again. initialAvailableSatsset to balance minus this payment's fee: the compose succeeding proves it coversamountSats.SendFeeRateandSendFeeCustomcallrefreshAvailablebefore the max-send path reads it.- A failed exact compose skipping a payable wallet: the error falls through to the existing
maxSpendableFundingestimate for the same wallet, so the old selection still applies.
Merge confidence: 1/5, because CI fails on the change itself (the SwiftFormat lint on SendSheet.swift:604-608). Once that is fixed and the test jobs pass, nothing else here would hold it back.
Reviewer model: claude-opus-5-5
Reasoning effort: Unknown (the runner does not report the setting to the review session)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed commit 0092df0.
Potential fee-preview mismatch: preview reuse is keyed by payment details and total hardware-wallet balance, which does not identify the spending inputs. If the inputs change without changing the total, returning to confirmation for the same payment may retain an old fee preview while signing composes a different fee. This could make the app confirmation and fee warnings stale. Device approval still occurs. This remains a source-review candidate; it has not been reproduced at runtime.
Review details
General review: GPT-6.1 Sol / high.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review round 1, pushed at 1f8643f:
|
talosmachina
left a comment
There was a problem hiding this comment.
Re-review of 1f8643f after 0092df0. 0 earlier findings, 0 new. The fee preview is now keyed on HwWalletManager.fundingStateFingerprint (the funding account's balance plus its sorted transaction ids) instead of the balance alone, and the SendSheet.swift guard is back to the indentation master has. Full tier, static: iOS does not build on this machine, so this is reasoned from the code and from CI.
CI: the SwiftFormat failure from my last review is fixed (SwiftFormat passes at 1f8643f). Run Tests, Run Integration Tests and build-local were still running when this was written.
What I checked, and 3 candidates I ruled out
Read: git diff 0092df0..1f8643f, the whole of fundingStateFingerprint next to fundingBalance, handleWatcherEvent (it replaces the watcher's transactionDetails on every event, so the fingerprint reads the current list), and both call sites. SendSheet.selectHardwareFundingSourceIfNeeded reads it before its compose, and so does HwSendCoordinator.preparePreview, so a change during the compose invalidates the result in both places.
The point @pwltr raised (same total, different coins): covered now. A spend plus a top-up back to the same total adds txids, so the fingerprint changes and preparePreview composes again. testFundingStateChangesWithTransactionsAtTheSameBalance and testCoordinatorPreviewComposesAgainWhenFundingStateChanges check this.
Ruled out
Hasheris seeded per process: the fingerprint lives only in memory, inComposedPreview, and is compared within one run, never persisted.- A watcher event carrying a partial
transactionDetailslist: that changes the fingerprint and leads to an extra compose, never a stale fee. It fails safe. - A transaction confirming leaves txids and balance unchanged: the coin set is the same, and signing composes again before the device approves, so a stale preview could not reach the signed fee anyway.
Merge confidence: 4/5, no findings and the new tests cover the change, but the unit and integration runs at 1f8643f had not finished and nothing was built here.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runtime does not report a setting for this session)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 1f8643f against f7ecae9.
Looks good. The guard indentation is restored and SwiftFormat passes, which resolves my earlier Low finding. The reused hardware fee preview is now keyed on the funding account's balance and transactions, read before composing, so a different coin set recomposes. No new findings.
Review details
Claude Opus 5.5, effort high
Choosing the hardware wallet for a payment request now composes the exact payment instead of a send-max, and HwWalletRepo shares exact-fee composes for the same payment and balance, so the confirm fee reuses it. Hardware sends estimate only the selected speed; the other speeds are estimated when the speed picker opens. The source selection no longer starts a fee refresh that the confirm navigation cancels. Twin of synonymdev/bitkit-ios#1221 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #1187
Twin: synonymdev/bitkit-android#1785
This PR makes a payment request funded from a hardware wallet run one compose instead of two, so the confirmation is ready about one compose (about 7 s on the Docker regtest setup) sooner.
Description
SendSheet: when Savings cannot cover a request, the hardware wallet is now chosen by composing the exact payment (largest balance first) instead of a send-max compose. A successful compose proves the wallet can pay and gives the fee. If it fails, the old max-spendable compose still runs so the insufficient-funds check is unchanged.HwSendCoordinator:seedPreviewstores that fee, andpreparePreviewreuses a stored fee while the wallet, address, amount, fee rate and wallet balance (standing in for the UTXO set) all match. Its own compose result is stored the same way, so a repeated preview for the same payment does not compose again. Changing any input composes again.Review round 1
HwWalletManager.fundingStateFingerprint), not the balance alone, so different coins at the same total compose again (1f8643f).SendSheet.swiftguard continuation lines are back to master's indentation; CI's SwiftFormat 0.64.0 rejected the 0.64.4 re-indent (c002e75).Out of Scope
composeTransaction: each call opens a new Electrum client and fully syncs a fresh wallet (compose.rs:69-70). Reusing a synced wallet is a separate follow-up in bitkit-core.SendFeeRate: opening the speed picker composes a fee for every speed, and its selection refreshes the max-spendable amount, so a speed change on a hardware send still runs several composes (about 10 in the device run). That path is unchanged here; reusing the stored fee there is a separate change.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
bitkit-docker, Trezor emulator paired through Trezor Bridge as in hardware-wallet.Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
composeTransactionbefore the confirmation is ready, and the swipe is accepted about one compose after Confirm shows — compose timing from the app log is not in CapabilitiescomposeTransactionAutomated Checks
HwWalletManagerFundingTests.swift— the funding state changes when the transactions change at the same balance, and ignores other address typesHwFundingSignerTests.swift— a changed funding state composes the preview againHwFundingSignerTests.swift— a seeded fee is reused for the same payment; a changed fee rate composes again; repeated previews compose once; switching wallets drops the stored feeEvidence
HwFundingSignerTestsandSendConfirmationLifecycleTestson the iPhone 17 simulator (iOS 26.5) at 4cb45d0: 78 tests, 0 failures.swiftformat --linton the changed files: 0 files require formatting.Device run at 0092df0, Debug
E2E_BUILD,E2E_BACKEND=staging, regtest, iPhone 17e simulator (iOS 26.5), Trezor emulator over Bridge (Savings 0, Trezor 24,242,671 sats), requests fromtools/paykit-fixture-sender(synonymdev/bitkit-e2e-tests):composeTransaction(7.41 s) finished 11:32:06.9, and the confirmation showed the enabled Swipe To Pay arrow; no further compose in the next 20 s. A first request the same way also ran exactly one compose (8.32 s). The issue measured about 15 s with two composes.composeTransaction(8.11 s), then ready to swipe.Round 1 at 1f8643f:
HwFundingSignerTests,HwWalletManagerFundingTests,SendConfirmationLifecycleTestson the iPhone 17 simulator, 84 cases passed (xcresult).Gaps
Models used
claude-opus-5-5(reasoning: Not exposed)claude-opus-5-5(reasoning: Not exposed)🤖 Generated with Claude Code