Skip to content

fix: use fast fee for savings transfer#1091

Merged
jvsena42 merged 11 commits into
masterfrom
fix/1034-savings-transfer-fast-fee
Jul 21, 2026
Merged

fix: use fast fee for savings transfer#1091
jvsena42 merged 11 commits into
masterfrom
fix/1034-savings-transfer-fast-fee

Conversation

@piotr-iohk

@piotr-iohk piotr-iohk commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1034

This PR makes savings → spending channel funding use a faster on-chain fee rate, matching the “~10 minutes” copy and iOS behavior.

Description

  • Defaults savings → spending funding to the fast fee tier instead of the settings default.
  • Reserves a fast send-all mining fee when sizing max transfer, so “transfer all” leaves room to pay the order on-chain (fixes the tight-balance failure mode seen in multi_address_2).
  • Aligns send-all with iOS: drain only for real dust change; fixed-send failures toast without surprise-draining the wallet.
  • Prepares and shows the real mining fee on confirm before swipe, and pays funding from viewModelScope so broadcast + paid-order caching are not cancelled by Compose scope teardown.

Preview

N/A

QA Notes

Manual Tests

  • 1. Funded savings wallet → Transfer → Spending → confirm max amount: funding tx uses a fast-tier sat/vB (check explorer), not the settings mid/default when that mid is ~1.
  • 2. Transfer → Spending → use max → confirm: order is sized with mining-fee headroom and funding succeeds (no coin-selection / insufficient-funds toast on a normal fee market).
  • 3. Tight multi-UTXO balance (transfer all) → Transfer → Spending → confirm: channel funding progresses; leftover is not left as an unaffordable fixed send.
  • 4. regression: Transfer → Spending with a partial amount well below balance: still funds with a normal (non-drain) send when change is above dust.

Automated Checks

  • Unit tests added: fast mining-fee reserve on max sizing; dust send-all; no drain when normal fee leaves non-dust change; fixed-send failure without drain, in TransferViewModelTest.kt.
  • Local: just test file TransferViewModelTest.
  • CI: standard compile, unit test, and detekt checks run by the PR bot. E2E multi_address_2 should pass once this lands on the resolved e2e branch.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR updates savings-to-spending transfers to use fast on-chain fees. The main changes are:

  • Reserves one fast mining fee when calculating the maximum transfer.
  • Prepares coin selection and mining fees before confirmation.
  • Drains the wallet only when fixed sending would create dust.
  • Shows the mining fee and waits for fee preparation before confirmation.
  • Adds tests for fee fallback, maximum sizing, and send-all behavior.

Confidence Score: 5/5

This looks safe to merge.

  • The maximum calculation now starts from raw spendable balance and reserves one fast mining fee.
  • Fee-estimation failure now uses an explicit fallback reserve.
  • No blocking issue remains in the updated fee-reservation flow.

Important Files Changed

Filename Overview
app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Uses fast-fee reservation, prepared coin selection, and dust-aware wallet draining for savings transfers.
app/src/main/java/to/bitkit/repositories/LightningRepo.kt Adds a repository wrapper for algorithm-specific UTXO selection.
app/src/main/java/to/bitkit/ui/screens/transfer/SpendingConfirmScreen.kt Displays the prepared mining fee and blocks confirmation until it is ready.
app/src/test/java/to/bitkit/viewmodels/TransferViewModelTest.kt Adds coverage for fast-fee reservation, fallback sizing, dust draining, and fixed sends.

Reviews (3): Last reviewed commit: "Merge branch 'master' into fix/1034-savi..." | Re-trigger Greptile

Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt
@piotr-iohk
piotr-iohk marked this pull request as draft July 17, 2026 10:34
Co-authored-by: Cursor <cursoragent@cursor.com>
@piotr-iohk
piotr-iohk marked this pull request as ready for review July 17, 2026 10:37
@piotr-iohk
piotr-iohk requested a review from jvsena42 July 17, 2026 10:42
@piotr-iohk piotr-iohk self-assigned this Jul 17, 2026
@piotr-iohk piotr-iohk added this to the 2.5.0 milestone Jul 17, 2026
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
@piotr-iohk
piotr-iohk marked this pull request as draft July 20, 2026 12:40
@piotr-iohk
piotr-iohk marked this pull request as ready for review July 20, 2026 14:13
@piotr-iohk
piotr-iohk requested a review from jvsena42 July 20, 2026 14:21
Comment thread app/src/main/java/to/bitkit/ui/screens/transfer/SpendingConfirmScreen.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt Fixed
@jvsena42
jvsena42 self-requested a review July 21, 2026 10:45

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good, just need some style changes

Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt
Comment thread app/src/main/java/to/bitkit/ui/ContentView.kt Outdated
Comment thread app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt
@jvsena42
jvsena42 enabled auto-merge July 21, 2026 12:07
@piotr-iohk
piotr-iohk requested a review from jvsena42 July 21, 2026 12:13
@jvsena42
jvsena42 merged commit eeeaaf1 into master Jul 21, 2026
18 checks passed
@jvsena42
jvsena42 deleted the fix/1034-savings-transfer-fast-fee branch July 21, 2026 12:46
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.

[Bug]: Transfer to spending should use 'fast' transaction speed

3 participants