Skip to content

Conversation

@jvsena42
Copy link
Member

@jvsena42 jvsena42 commented Jan 29, 2026

Fixes #745

This PR fixes the "insufficient funds" error that occurs when transferring the maximum balance to spending.

Description

When users tried to transfer their full on-chain balance to Lightning (spending), they would sometimes encounter an "insufficient funds" error even though they had enough sats. This happened because:

  1. Fee estimation mismatch - The LSP fee was estimated using maxSendable amount, but order creation uses a different clientBalance value. Since lspBalance depends on clientBalanceSat, this caused off-by-few-sats discrepancies.

  2. Dust change handling - When the remaining change after the transfer would be below the dust limit (546 sats), the transaction would fail because Bitcoin nodes reject dust outputs.

Changes:

  • Implements two-pass fee estimation to match actual order creation logic
  • Adds dust detection that automatically uses sendAll when remaining change would be below dust limit

Reference: iOS fix PR #416

Preview

Screen_recording_20260129_085609.webm
not-dust.webm

QA Notes

1. MAX transfer to spending

  1. Have on-chain balance (e.g., 5000 sats)
  2. Go to Transfer > To Spending
  3. Press MAX button
  4. Tap Continue
  5. Verify amounts add up correctly on confirm screen
  6. Swipe to transfer
  7. Verify transfer succeeds without "Insufficient funds" error

2. Near-dust change scenarios

  1. Set up a balance where MAX transfer would leave 500-600 sats change
  2. Transfer MAX to spending
  3. Verify sendAll is used (no dust output created)

3. Regression - Partial transfers

  1. Transfer a partial amount (not MAX) to spending
  2. Verify transfer works normally
  3. Verify remaining on-chain balance is correct

@jvsena42 jvsena42 self-assigned this Jan 29, 2026
@claude
Copy link

claude bot commented Jan 29, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@jvsena42 jvsena42 requested a review from ovitrif January 29, 2026 12:08
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.

MAX transfer to spending causes insufficient error

2 participants