From 363bf6ceaab6b60bd82147128a6ce9d7a8e1b42a Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 14:41:12 -0300 Subject: [PATCH 1/7] fix: show insufficient funds when no hardware wallet covers a scan Co-Authored-By: Claude Opus 5.5 --- .../java/to/bitkit/viewmodels/AppViewModel.kt | 16 ++++++++++++++-- .../viewmodels/AppViewModelSendFlowTest.kt | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt b/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt index 1d6d166319..e9b3bd7660 100644 --- a/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt +++ b/app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt @@ -5441,8 +5441,20 @@ class AppViewModel @Inject constructor( return true } // Savings cannot cover it but a hardware wallet can, so pay from that instead of opening Amount. - if (!validateAmount(amount) && _sendUiState.value.hardwareWalletId == null) { - selectHardwareFundingSourceForAmount(amount, walletGeneration) + // The balance check above counts raw hardware balances, so no wallet may cover it once fees are taken. + if ( + !validateAmount(amount) && + _sendUiState.value.hardwareWalletId == null && + !selectHardwareFundingSourceForAmount(amount, walletGeneration) + ) { + toast( + type = Toast.ToastType.ERROR, + title = context.getString(R.string.other__pay_insufficient_savings), + description = context.getString(R.string.other__pay_insufficient_savings_description), + testTag = "InsufficientSavingsToast", + ) + clearActiveContactPaymentContext() + return true } if (!validateAmount(amount)) return false requireCurrentPaymentPreparation(walletGeneration) diff --git a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt index 81c6d613bc..ea5fa6d234 100644 --- a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt +++ b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt @@ -9529,6 +9529,24 @@ class AppViewModelSendFlowTest : BaseUnitTest() { assertEquals(20_000uL, sut.sendUiState.value.amount) } + @Test + fun `main scanner onchain scan the hardware balance but not its spendable covers shows insufficient funds`() = + test { + val input = stubOnchainAmountScan(amountSats = 9_000u) + balanceState.value = BalanceState(maxSendOnchainSats = 0u) + hwWallets.value = persistentListOf(hardwareWallet(fundingBalanceSats = 10_000uL)) + whenever(hwWalletRepo.maxSpendableFunding(any(), any(), any())).thenReturn(Result.success(8_000uL)) + + sut.showScannerSheet() + sut.onScannerSheetResult(input) + advanceUntilIdle() + + assertFalse(sut.currentSheet.value is Sheet.Send) + val toasts = argumentCaptor() + verify(toastManager, atLeast(1)).enqueue(toasts.capture()) + assertTrue(toasts.allValues.any { it.testTag == "InsufficientSavingsToast" }) + } + @Test fun `speed change keeps a scanned hardware amount that equals the hardware maximum`() = test { val input = stubOnchainAmountScan(amountSats = 48_000u) From ace05c414fa2e6c90e995eb5cff0e37ffce28002 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 14:41:12 -0300 Subject: [PATCH 2/7] docs: add journey for a scan over hardware spendable Co-Authored-By: Claude Opus 5.5 --- journeys/hardware-wallet/README.md | 1 + .../scan-onchain-amount-over-spendable.xml | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 journeys/hardware-wallet/scan-onchain-amount-over-spendable.xml diff --git a/journeys/hardware-wallet/README.md b/journeys/hardware-wallet/README.md index ae12fd1e29..f5147f2c90 100644 --- a/journeys/hardware-wallet/README.md +++ b/journeys/hardware-wallet/README.md @@ -77,6 +77,7 @@ the other three rely on, and `passphrase-settings-remove.xml` removes it again. | `settings-hardware-wallets.xml` | Payments count row, Hardware Wallets screen list, rename sheet, Add button sheet/back dismiss, per-row delete confirm + re-pair | | `detail-overview.xml` | Detail screen overview, Transfer placeholder when funded, activity, Remove confirm + forget | | `send-onchain.xml` | Normal Send flow funded by Trezor: source selection, guarded preparation, device signing, broadcast, success, and activity | +| `scan-onchain-amount-over-spendable.xml` | Scanned on-chain amount the Trezor balance covers but not after fees: Insufficient Savings toast instead of a locked Amount screen | | `receive-onchain.xml` | Trezor Receive tab: current address and QR display plus exact on-device address verification | | `passphrase-pairing.xml` | Passphrase button on Paired → Enter Passphrase → Passphrase Funds Found; second home tile, own label, no passphrase in logs | | `passphrase-duplicate.xml` | Re-entering a watched passphrase reports "already added" and adds no tile | diff --git a/journeys/hardware-wallet/scan-onchain-amount-over-spendable.xml b/journeys/hardware-wallet/scan-onchain-amount-over-spendable.xml new file mode 100644 index 0000000000..a617825d1f --- /dev/null +++ b/journeys/hardware-wallet/scan-onchain-amount-over-spendable.xml @@ -0,0 +1,22 @@ + + + Verifies that an on-chain BIP21 request whose amount a paired hardware wallet's balance covers, + but not once the network fee is taken, shows the Insufficient Savings toast instead of opening + the Send Amount screen with a fixed amount that cannot be changed or continued. Nothing is + broadcast. + Precondition: an onboarded dev wallet with 0 sats in Savings and a paired Bridge emulator (see + README.md) whose native-segwit account holds a confirmed regtest balance B of at least 10 000 + sats, read from its home tile. Use an amount between B minus 100 sats and B, which the balance + covers but the balance minus any non-zero fee does not, and a regtest address the wallet does + not own. Start on the wallet home screen. + The Send Amount screen is identified by its number field (testTag "SendNumberField"), the + Confirm screen by its amount (testTag "ReviewAmount"). + + + Read the paired Trezor's balance B from its home tile and pick an amount A with B - 100 < A < B, written in BTC + Run adb shell am start -a android.intent.action.VIEW -d "bitcoin:<regtest address>?amount=<A>" to.bitkit.dev + Verify the Insufficient Savings toast (testTag "InsufficientSavingsToast") appears (screenshot), and neither the Send Amount screen (testTag "SendNumberField") nor the Confirm screen (testTag "ReviewAmount") opens + Pick an amount below B by at least 2 000 sats and run the same deep link with it + Verify the Confirm screen opens with the Trezor as the funding source and the amount shown (testTag "ReviewAmount"); close the sheet without sending + + From 3118c17840628c5bb22eddd9ea3d615c08a81a3b Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 14:41:49 -0300 Subject: [PATCH 3/7] chore: add changelog fragment for the scan fix Co-Authored-By: Claude Opus 5.5 --- changelog.d/next/1790.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/next/1790.fixed.md diff --git a/changelog.d/next/1790.fixed.md b/changelog.d/next/1790.fixed.md new file mode 100644 index 0000000000..a8b35187ec --- /dev/null +++ b/changelog.d/next/1790.fixed.md @@ -0,0 +1 @@ +Show an insufficient funds message when a scanned Bitcoin request is more than a hardware wallet can pay after fees, instead of opening an amount screen that cannot continue. From 8e1618ed9db5a770cf5351d7c3d41d18f735cc5b Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 15:49:56 -0300 Subject: [PATCH 4/7] docs: list the hardware scan journey as not ported to ios Co-Authored-By: Claude Opus 5.5 --- journeys/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/journeys/README.md b/journeys/README.md index 5770c36ac8..d4e9b97cfc 100644 --- a/journeys/README.md +++ b/journeys/README.md @@ -151,6 +151,7 @@ Known differences in the corpus, as of the iOS port (synonymdev/bitkit-ios#691): | `hardware-wallet/usb-reconnect.xml` | `reconnect.xml` — over Bridge, since iOS cannot do WebUSB | | `cjit-notifications/non-cjit-channel-no-payment-notification.xml` | not ported — iOS dropped its CJIT notification suite with the Blocktank sunset; this one checks Android's channel-ready notification on a Manual Setup channel | | `hardware-wallet/receive-onchain.xml`, `hardware-wallet/send-onchain.xml` | not ported | +| `hardware-wallet/scan-onchain-amount-over-spendable.xml` | not ported — iOS checks the same raw hardware balance at scan time, but opens Confirm, switches to the hardware wallet there and fails its fee preview with a Try again toast instead of showing Insufficient Savings; port the journey with that fix | | `activity/date-range-rapid-month-taps.xml` | not ported — iOS has no activity journey suite, and the rapid month tap behaviour was not checked there | | `coin-selection/manual-coin-selection.xml` | not ported — iOS has the screen (`SendUtxoSelectionView`) but no accessibility identifiers on it yet | | `coin-selection/manual-wallet-switch.xml` | same file, journey name and actions; iOS can open the picker on the wallet switch, Android on the next swipe. The iOS picker has no accessibility identifiers, so assert its visible "Coin Selection" title. | From 2ee82c274deb3135bde94607cfc91010dfebda6a Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 16:04:59 -0300 Subject: [PATCH 5/7] test: fail the exact compose in the unaffordable scan test Co-Authored-By: Claude Opus 5.5 --- .../test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt index 80778d13ea..14fdc57bfd 100644 --- a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt +++ b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt @@ -9538,6 +9538,8 @@ class AppViewModelSendFlowTest : BaseUnitTest() { balanceState.value = BalanceState(maxSendOnchainSats = 0u) hwWallets.value = persistentListOf(hardwareWallet(fundingBalanceSats = 10_000uL)) whenever(hwWalletRepo.maxSpendableFunding(any(), any(), any())).thenReturn(Result.success(8_000uL)) + whenever(hwWalletRepo.estimateFundingMiningFee(any(), any(), any(), any())) + .thenReturn(Result.failure(Exception("insufficient funds for amount and fee"))) sut.showScannerSheet() sut.onScannerSheetResult(input) From 6f5ee70e69bbc709d0c4ee7f650b4330c57f65dc Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 5 Nov 2026 19:08:39 -0300 Subject: [PATCH 6/7] docs: note the ios port of the over-spendable scan journey Co-Authored-By: Claude Opus 5.5 --- journeys/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/journeys/README.md b/journeys/README.md index d4e9b97cfc..217bca25e7 100644 --- a/journeys/README.md +++ b/journeys/README.md @@ -151,7 +151,7 @@ Known differences in the corpus, as of the iOS port (synonymdev/bitkit-ios#691): | `hardware-wallet/usb-reconnect.xml` | `reconnect.xml` — over Bridge, since iOS cannot do WebUSB | | `cjit-notifications/non-cjit-channel-no-payment-notification.xml` | not ported — iOS dropped its CJIT notification suite with the Blocktank sunset; this one checks Android's channel-ready notification on a Manual Setup channel | | `hardware-wallet/receive-onchain.xml`, `hardware-wallet/send-onchain.xml` | not ported | -| `hardware-wallet/scan-onchain-amount-over-spendable.xml` | not ported — iOS checks the same raw hardware balance at scan time, but opens Confirm, switches to the hardware wallet there and fails its fee preview with a Try again toast instead of showing Insufficient Savings; port the journey with that fix | +| `hardware-wallet/scan-onchain-amount-over-spendable.xml` | ported with synonymdev/bitkit-ios#1228 — iOS opens Confirm and switches to the hardware wallet there, then shows Insufficient Savings and closes the sheet when its fee preview fails | | `activity/date-range-rapid-month-taps.xml` | not ported — iOS has no activity journey suite, and the rapid month tap behaviour was not checked there | | `coin-selection/manual-coin-selection.xml` | not ported — iOS has the screen (`SendUtxoSelectionView`) but no accessibility identifiers on it yet | | `coin-selection/manual-wallet-switch.xml` | same file, journey name and actions; iOS can open the picker on the wallet switch, Android on the next swipe. The iOS picker has no accessibility identifiers, so assert its visible "Coin Selection" title. | From 6d644d35239fe0c4e6ae4424f15e337a5c8acee5 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Fri, 6 Nov 2026 06:05:37 -0300 Subject: [PATCH 7/7] test: attempt the exact hardware compose in the over-spendable scan test Co-Authored-By: Claude Opus 5.5 --- .../java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt index 14fdc57bfd..f19870423c 100644 --- a/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt +++ b/app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt @@ -9535,6 +9535,11 @@ class AppViewModelSendFlowTest : BaseUnitTest() { fun `main scanner onchain scan the hardware balance but not its spendable covers shows insufficient funds`() = test { val input = stubOnchainAmountScan(amountSats = 9_000u) + val onchainInfo = mock() + val btInfo = mock() + whenever(onchainInfo.feeRates).thenReturn(FeeRates(fast = 5u, mid = 3u, slow = 1u)) + whenever(btInfo.onchain).thenReturn(onchainInfo) + whenever(blocktankRepo.blocktankState).thenReturn(MutableStateFlow(BlocktankState(info = btInfo))) balanceState.value = BalanceState(maxSendOnchainSats = 0u) hwWallets.value = persistentListOf(hardwareWallet(fundingBalanceSats = 10_000uL)) whenever(hwWalletRepo.maxSpendableFunding(any(), any(), any())).thenReturn(Result.success(8_000uL)) @@ -9546,6 +9551,7 @@ class AppViewModelSendFlowTest : BaseUnitTest() { advanceUntilIdle() assertFalse(sut.currentSheet.value is Sheet.Send) + verify(hwWalletRepo, atLeast(1)).estimateFundingMiningFee(any(), any(), eq(9_000uL), any()) val toasts = argumentCaptor() verify(toastManager, atLeast(1)).enqueue(toasts.capture()) assertTrue(toasts.allValues.any { it.testTag == "InsufficientSavingsToast" })