Repository navigation
fix: show insufficient savings when the hardware fallback cannot pay the fee - #1228
Conversation
…the fee 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>
|
J1 evidence (iPhone 17 simulator, Bridge Trezor B = 19,928,006 sats, Savings 0). master 2d5744b, scan B − 30: Confirm switches to the Trezor, then shows "Please try again. Failed to compose hardware transfer" and stays with the swipe disabled (last frame). This PR, scan B − 30: Insufficient Savings toast, and the sheet closes 13.7 s after the scan. This PR, scan B − 20,000: Confirm from the Trezor, 209-sat fee, swipe enabled. Recordings: master pr_master_over.mp4 · this PR pr_fix_over.mp4 |
[Medium impact] The PR appears safe to merge, with no new actionable issues found. SummaryThe PR shows Insufficient Savings and leaves Confirm when the hardware wallet chosen after Savings fails cannot cover the fee.
Reviews (3) · Last reviewed commit: "fix: treat a compose shortfall above the..." · Reviewed by Greptile |
|
Placed in 3.2.0 with its twin: a non-blocking fix found after the 3.1 cut. I filed #1229 to track it under the milestone and added |
talosmachina
left a comment
There was a problem hiding this comment.
1 finding (1 P1). When Savings cannot pay a scanned fixed amount and Confirm falls back to a hardware wallet whose fee preview then fails, this shows Insufficient Savings and closes the sheet instead of Try again. Reviewed 95af2fd, full tier, static: per the repo's Bitkit track rules an auto review does not build bitkit-ios, and iOS does not build on Linux.
What I checked, and 4 candidates I ruled out
Read in full: SendConfirmationView.swift (fallback selection, selectFundingSource, calculateTransactionFee, leaveAfterPreparationFailure, the hwSend.walletId onChange), HwFundingSigner.preparePreview, HwWalletManager.estimateOfflineFundingMiningFee and composeFundingTransactionInternal, bitkit-core onchain/compose.rs, the twin synonymdev/bitkit-android#1790.
CI: SwiftFormat, validate, build-local green; Run Tests, integration and e2e still pending at review time.
Ruled out
- Stale fallback id after a manual switch:
selectFundingSourceclears it first, and the fallback path sets it after the call, so a user-picked source never carries it. - Superseded or cancelled preview hitting the new branch: the catch returns early on
!isCurrentSend()andCancellationError, and a successful preview clears the id. - Toast copy and identifier:
other__pay_insufficient_savingsand its description exist, andInsufficientSavingsToastmatches the Android tag the shared journey asserts. leaveAfterPreparationFailurewith a fixed amount:canEditAmountis false for a BIP21 amount, so it pops Confirm or hides the sheet, which matches J1's expected result.- Cold reader: the finding stood; it rated it P2. I kept P1 because the wrong outcome is a user told they lack funds and the sheet closed on a transient network failure.
Merge confidence: 3/5, one P1 on the error path of the fallback wallet's preview.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runtime does not report a reasoning setting for this session)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 95af2fd against 2d5744b.
When the automatic Savings-to-hardware fallback cannot cover the fee, Confirm now shows Insufficient Savings and leaves instead of a generic error with a disabled swipe; a manual switch or a successful preview clears the fallback marker. One Low finding:
Low: hardwareWalletCovering still returns the first hardware wallet whose balance covers the amount, in stored order. With several devices, a smaller one can be chosen, fail on the fee, and end the send as Insufficient Savings although a larger wallet could pay. Consider choosing the wallet with the largest funding balance (as Android does) or trying the next covering wallet first.
Review details
Claude Opus 5.5, effort high
pwltr
left a comment
There was a problem hiding this comment.
Reviewed commit 95af2fd.
Potential Medium: establish insufficient funds before choosing the fallback error. The new catch branch treats every preview failure for the automatically selected hardware wallet as insufficient Savings. The marker only checks wallet identity, while preview preparation can also fail for account, backend or transaction-composition errors. A funded wallet can therefore receive a misleading “more bitcoin is needed” message and leave confirmation without its actionable error. Use a verified affordability failure before applying that toast/navigation policy; preserve ordinary error handling when affordability is unknown. This is a candidate from static source tracing, not a reproduced failure.
Review details
General review
Model: GPT-6.1 Sol
Reasoning effort: high
…each Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 2 evidence. iPhone 17 simulator, Bridge Trezor B = 19,928,006 sats, Savings 0. The app at 1df0d9a (d1578e1 adds only the multi-wallet pick, which can't be driven with one emulator). Electrum down, scan B − 20,000 (the Trezor can pay). The app's Electrum server pointed at a local proxy, which I killed after the balance synced. The preview fails with
Scan B − 30: Insufficient Savings toast; the sheet closes 15 s after the scan. Scan B − 20,000, Electrum up: Confirm from the Trezor, 209-sat fee, swipe enabled, 18 s after the scan. Recording of the Electrum-down run: r2_fix_electrum_down.mp4 The simulator's Electrum setting was reset to default afterwards. |
|
Replies to pwltr's reviews: Potential Medium (insufficient funds before the fallback error): confirmed, the same finding as the thread above. Fixed in 1df0d9a: the toast is gated on the amount exceeding the balance minus the fee reserve, and any other preview failure keeps Try again. Device proof with Electrum unreachable: #1228 (comment) Low (first covering wallet, not the largest): confirmed, and in scope. On master a failed fallback left Confirm open for a manual switch; this PR ends the send, so picking a smaller wallet first is now worse. Fixed in d1578e1: Confirm falls back to the wallet with the largest balance, as Android's |
talosmachina
left a comment
There was a problem hiding this comment.
Re-review of d1578e1 after 95af2fd. 1 earlier finding: fixed. 0 new findings. When Savings cannot pay a scanned fixed amount, Confirm now falls back to the paired hardware wallet with the largest balance. A failed fee preview of that wallet shows Insufficient Savings and closes the sheet only when the amount leaves less than HwFundingSigner.feeReserve of its balance. Full tier, static: iOS does not build on Linux, so Run Tests is the gate for SendConfirmationSwipeTests.
What I checked, and 3 candidates I ruled out
Earlier finding
- Insufficient Savings for any preview failure: fixed in
1df0d9ad0.isSavingsFallbackShortOfFeenow also requiresamountSats > balanceSats - feeReserveSats, andbalanceSats < feeReserveSatsis checked first so the subtraction cannot underflow. An Electrum or account failure on an amount with room for the fee takes the Try again branch, which the author showed on a simulator with Electrum unreachable. Electrum failing on an amount that is within the reserve of the balance (1,200 vB at the confirmation rate) still reads as Insufficient Savings. That window is narrow, and in it the funds really are near the limit.
Read in full: SendConfirmationView.swift at d1578e1 (selectFundingSource, the UTXO-selection fallback, calculateTransactionFee and its catch, the hwSend.walletId onChange), HwFundingSigner.feeReserve, HwWalletManager.fundingBalance, SendConfirmationSwipeTests.swift.
CI at d1578e1: SwiftFormat, validate, Greptile green; Run Tests, Run Integration Tests and build-local pending at review time.
Ruled out
- Largest wallet fails where a smaller one could pay (Greptile): this needs two paired hardware wallets, the amount inside the larger one's fee reserve but payable by the smaller one, and the larger one's coins fragmented enough to lose its fee lead. Outside that, a failed preview of the largest wallet keeps Try again with Confirm open (
afterFundingSwitch: true), and the user can switch source. The pick matches the Android twin'ssortedByDescending { it.fundingBalanceSats }. - Reserve smaller than a many-input fee (Greptile): this happens on a fallback wallet whose fee needs more than 1,200 vB. There it gives master's behaviour (Try again, Confirm stays open). So the gap is a limit on how far this fix reaches, not a regression it adds.
- Fee rate mismatch between the switch and the catch: the catch runs only after
confirmationFeeRateis non-nil, sofeeReservetakes its rate-times-vbytes branch, which is the same reserve the funding switch uses forinitialAvailableSats.
Merge confidence: 4/5, no open findings, but the money path is covered by unit tests that Run Tests has not finished yet and the largest-wallet pick was not driven on a device.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not report it)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Correction to my round-2 evidence comment (#1228 (comment)): the simulator's Electrum setting was not reset then. The reset was not saved. I reset it now and confirmed it in the app log: |
talosmachina
left a comment
There was a problem hiding this comment.
Re-review of 9eafe12 after d1578e1. Earlier findings: none open. 0 new findings. A failed fee preview of the Savings fallback hardware wallet now also counts as Insufficient Savings when the compose itself reports the shortfall, which covers a fee above the 1,200 vB reserve that Greptile raised. Full tier, static: iOS does not build on Linux, so Run Tests is the gate for SendConfirmationSwipeTests.
What I checked, and 3 candidates I ruled out
Earlier points
- Insufficient Savings for any preview failure (my P1 at
95af2fd): still fixed. The new text match sits after the fallback-id guard, so a wallet the user picked keeps Try again whatever the error says, and the test asserts that with the shortfall text (fallback: nil). - Reserve smaller than a many-input fee (Greptile P2, which I had ruled out as master's behaviour rather than a regression): now covered. Traced the text end to end: bitkit-core
0.8.0-rc11(thePackage.resolvedpin) builds the PSBT with bdk0.30.2,finish_psbtmapsbuilder.finish()errors withformat!("{}", e), and bdk'sError::InsufficientFundsdisplays asInsufficient funds: {} sat available of {} sat needed.composeFundingTransactionInternalputs the firstComposeResult.errorintoAppError.debugMessage, and neitherHwFundingSigner.estimateOfflineFundingMiningFeenorpreparePreviewrewraps it, so(error as? AppError)?.debugMessagereaches the check intact.
Read in full: the diff d1578e1..9eafe12, calculateTransactionFee and its catch, isSavingsFallbackShortOfFee, HwWalletManager.composeFundingTransactionInternal and estimateOfflineFundingMiningFee, HwFundingSigner.preparePreview, AppError, bitkit-core onchain/compose.rs at the pinned revision, bdk 0.30.2 error.rs.
CI at 9eafe12: SwiftFormat, validate, Greptile green; Run Tests, Run Integration Tests and build-local pending at review time. At d1578e1 Run Tests was cancelled by the next push, so no head since 95af2fd has a finished unit run yet.
Ruled out
- Text match breaks on a core bump: the string is bdk's, not bitkit-core's, and bitkit-core's own
test_compose_insufficient_fundsasserts only theErrorvariant. A bump that changes the text falls back to the reserve check, which is thed1578e1behaviour, not a regression. - A non-funds failure carrying the phrase: Electrum, account and fee-rate failures come out of
compose_innerasAccountInfoErrortext or theFee rate must be...message; none containsinsufficient funds. - Compose shortfall on coins the balance counts but the compose cannot spend: the result is the honest one, since this wallet cannot pay the amount, and before this commit the same case read as Try again with Confirm left open.
Merge confidence: 4/5, no open findings; the change is small and the error text is traced to its source, but Run Tests has not finished on any head since 95af2fd and the compose-shortfall case was not driven on a device.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not report it)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 9eafe12. Two Medium candidates from static source traces; neither has runtime reproduction or completed follow-up verification.
Medium candidate — Check spendability before choosing the largest wallet. The automatic fallback selects the highest gross balance, which can be fragmented enough to fail payment-plus-fee selection while a smaller wallet can pay. A failed preview dismisses confirmation without trying the payable alternative. See SendConfirmationView.swift:1217–1220 and 2200–2216.
Medium candidate — Preserve network failures when affordability is unknown. The new insufficient-funds predicate can classify an Electrum connection failure as a funds shortfall when headroom is below the conservative 1,200-vbyte reserve, even though the actual transaction fee could fit. See SendConfirmationView.swift:1238 and 2200–2216.
Review details
General review
Model: GPT-6.1 Sol
Reasoning effort: high
|
Replies to pwltr's review of 9eafe12 (#1228 (review)). No code change for either. Medium: check spendability before choosing the largest wallet. Declined as marginal, the same case as Greptile's thread (#1228 (comment)).
Medium: an Electrum failure inside the reserve reads as a shortfall. The case can happen. Declined, because the fix removes the guard that the main fix relies on.
Leaving both for you to decide. |
ben-kaufman
left a comment
There was a problem hiding this comment.
The earlier preview-error and fee-shortfall issues are fixed. The remaining multiple-wallet and near-balance error cases are accepted tradeoffs.
I did not rerun local app tests or J1. Physical-device and BLE flows remain unverified. Both independent security passes are incomplete after provider authentication failures.
Reviewer model: claude-opus-5-5, gpt-6.1-sol
Reasoning effort: high for both







Closes #1229
Twin: synonymdev/bitkit-android#1790
Scanning an on-chain request with Savings unable to pay, for an amount a paired hardware wallet's balance covers but not with the network fee, left the Confirm screen on the hardware wallet. Its fee preview failed with "Please try again. Failed to compose hardware transfer", and the swipe stayed disabled. Android's twin fixes the same check.
Description
SendConfirmationView: when the hardware wallet Confirm switched to because Savings could not pay fails its fee preview, and the compose reports the shortfall or the amount leaves less than the fee reserve, show the Insufficient Savings toast and close the sheet. This is the same result as a scan with no wallet that can pay. Any other preview failure (Electrum unreachable, a missing account) keeps master's Try again handling, and so does a hardware wallet the user picks. The check reuses the preview Confirm already runs, so the path where the hardware wallet can pay gets no extra compose.SendConfirmationView.hardwareWalletCovering: fall back to the hardware wallet with the largest balance, as Android does, instead of the first one whose balance covers the amount.scan-onchain-amount-over-spendable.xml, ported from Android.Out of Scope
AppViewModel.validateOnchainBalance: the scan-time check still compares against the raw hardware balance. A pre-check there would add a 12–15 s hardware compose to every scan the hardware wallet can pay.Design
N/A — no UI changes; reuses the existing Insufficient Savings toast.
Preview
See Evidence.
QA Notes
Setup
TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325, staging regtest.bitkit-docker, paired as injourneys/hardware-wallet/README.md.Journeys
scan-onchain-amount-over-spendable.xml— an amount the hardware balance covers but not with the fee shows Insufficient Savings and closes the sheet; an amount it can pay opens Confirm from the Trezor with a feeManual Tests
N/A
Automated Checks
SendConfirmationSwipeTests.swift— a failed preview of the Savings fallback wallet counts as Insufficient Savings only when the compose reports the shortfall or the amount leaves less than the fee reserve; a wallet the user picks keeps Try again; the fallback is the largest covering walletSendConfirmationSwipeTests.swift— 24 tests, 0 failuresEvidence
J1 at 0a6e338, iPhone 17 simulator (iOS 26.5), Bridge Trezor with B = 19,928,006 sats, Savings 0:
Round 2, at 1df0d9a (d1578e1 changes only the multi-wallet pick): B − 30 shows Insufficient Savings and the sheet closes in 15 s. B − 20,000 reaches Confirm with a 209-sat fee in 18 s. With the app's Electrum unreachable, B − 20,000 shows "Please try again. Failed to compose hardware transfer", as master's code does in the same setup (#1228 (comment)).
Gaps
Models used
claude-opus-5-5(reasoning: Not exposed)claude-opus-5-5(reasoning: Not exposed)🤖 Generated with Claude Code