Skip to content
Merged
16 changes: 14 additions & 2 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5470,8 +5470,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)
Expand Down
26 changes: 26 additions & 0 deletions app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9531,6 +9531,32 @@ 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)
val onchainInfo = mock<IBtInfoOnchain>()
val btInfo = mock<IBtInfo>()
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))
whenever(hwWalletRepo.estimateFundingMiningFee(any(), any(), any(), any()))
.thenReturn(Result.failure(Exception("insufficient funds for amount and fee")))
Comment thread
jvsena42 marked this conversation as resolved.
Resolved

sut.showScannerSheet()
sut.onScannerSheetResult(input)
advanceUntilIdle()

assertFalse(sut.currentSheet.value is Sheet.Send)
verify(hwWalletRepo, atLeast(1)).estimateFundingMiningFee(any(), any(), eq(9_000uL), any())
val toasts = argumentCaptor<Toast>()
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)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1790.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions journeys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | 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. |
Expand Down
1 change: 1 addition & 0 deletions journeys/hardware-wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
22 changes: 22 additions & 0 deletions journeys/hardware-wallet/scan-onchain-amount-over-spendable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<journey name="scan onchain amount over hardware spendable">
<description>
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").
</description>
<actions>
<action>Read the paired Trezor's balance B from its home tile and pick an amount A with B - 100 &lt; A &lt; B, written in BTC</action>
<action>Run adb shell am start -a android.intent.action.VIEW -d "bitcoin:&lt;regtest address&gt;?amount=&lt;A&gt;" to.bitkit.dev</action>
<action>Verify the Insufficient Savings toast (testTag "InsufficientSavingsToast") appears (screenshot), and neither the Send Amount screen (testTag "SendNumberField") nor the Confirm screen (testTag "ReviewAmount") opens</action>
<action>Pick an amount below B by at least 2 000 sats and run the same deep link with it</action>
<action>Verify the Confirm screen opens with the Trezor as the funding source and the amount shown (testTag "ReviewAmount"); close the sheet without sending</action>
</actions>
</journey>
Loading