Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ADD: show MAX sendable amount#8264

Merged
Overtorment merged 8 commits into
BlueWallet:masterfrom
adamSHA256:feature/show-max-sendable-amount
Feb 26, 2026
Merged

ADD: show MAX sendable amount#8264
Overtorment merged 8 commits into
BlueWallet:masterfrom
adamSHA256:feature/show-max-sendable-amount

Conversation

@adamSHA256

@adamSHA256 adamSHA256 commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #8265
When MAX is selected, display the calculated sendable amount below.

  • Works only for 1 recipient (Main goal of feature is this for atomic swap)
  • Shows ≈ prefix when recipient address is unknown (using P2TR estimate)
  • Shows exact amount when valid address is entered

When MAX is selected, display the calculated sendable amount below.
  - Works only for 1 recipient (Main goal of feature is this for atomic swap)
  - Shows ≈ prefix when recipient address is unknown (using P2TR estimate)
  - Shows exact amount when valid address is entered
  - Forces displayed amount into transaction (no recalculation on Next)
@ncoelho

ncoelho commented Jan 29, 2026

Copy link
Copy Markdown
Member

Add some screenshots please

@adamSHA256

Copy link
Copy Markdown
Contributor Author

I did in issue #8265 may I copy it too or link is enough?

@ncoelho

ncoelho commented Jan 29, 2026

Copy link
Copy Markdown
Member

I did in issue #8265 may I copy it too or link is enough?

Thanks, that is great!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a feature to display the calculated sendable amount when MAX is selected for atomic swap compatibility. When a user selects "Use Full Balance" (MAX), the actual BTC amount that will be sent is now displayed below the MAX label, making it easier to communicate the exact amount to a counterparty before receiving their address.

Changes:

  • Calculates and displays the maximum sendable amount (balance minus fee) when MAX is selected for single-recipient transactions
  • Uses P2TR dummy address for conservative fee estimation when no valid address is entered, showing ≈ prefix to indicate estimate
  • Shows exact amount when a valid address is entered
  • Commits to the displayed amount in transaction creation, with any remainder going to the fee
  • Adds long-press to copy functionality for the displayed amount

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
screen/send/SendDetails.tsx Adds maxSendableAmount calculation, updates fee estimation to use P2TR dummy for conservative estimates, modifies transaction creation to use explicit value when MAX is displayed
components/AmountInput.tsx Adds UI to display the MAX sendable amount with optional ≈ prefix, implements copy-to-clipboard on long press

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

editable={isEditable}
disabled={!isEditable}
inputAccessoryViewID={InputAccessoryAllFundsAccessoryViewID}
maxSendableAmount={index === scrollIndex.current ? maxSendableAmount : null}

Copilot AI Jan 31, 2026

Copy link

Choose a reason for hiding this comment

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

The condition index === scrollIndex.current appears unnecessary here since maxSendableAmount is already null when addresses.length !== 1 (line 116 in maxSendableAmount calculation). This means if there are multiple recipients, maxSendableAmount will already be null regardless of the scroll index.

Consider simplifying this to just maxSendableAmount={maxSendableAmount} or adding a comment explaining why the scroll index check is needed.

Suggested change
maxSendableAmount={index === scrollIndex.current ? maxSendableAmount : null}
maxSendableAmount={maxSendableAmount}

Copilot uses AI. Check for mistakes.
@limpbrains

Copy link
Copy Markdown
Collaborator

I suggest we align text in the middle, as we do for USD amount

Screenshot 2026-02-02 at 14 15 22

Overall looks good and works good. I would move maxSendableAmount calculation into recalc fees in effect useEffect, so we have all on the fly calculation in one place, but it is not important

@adamSHA256

Copy link
Copy Markdown
Contributor Author

I suggest we align text in the middle, as we do for USD amount

Screenshot 2026-02-02 at 14 15 22 Overall looks good and works good. I would move `maxSendableAmount` calculation into `recalc fees in effect` useEffect, so we have all on the fly calculation in one place, but it is not important

I did 3 lines edit, so it's in center line now. I don't have time today, but if you would move that calculation, I'll fix it in next days.
center

@ojokne ojokne 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.

LGTM

@adamSHA256

Copy link
Copy Markdown
Contributor Author

Pushed the refactor - moved maxSendableAmount calculation into the recalc fees in effect useEffect as @limpbrains suggested.

@Overtorment

Copy link
Copy Markdown
Member

@cursor review pls

@Overtorment

Copy link
Copy Markdown
Member

running full test suite here: #8285

@Overtorment

Copy link
Copy Markdown
Member

e2e test failed: ✕ can manage UTXO (Not enough balance)

test.mp4
test.mp4

@Overtorment

Copy link
Copy Markdown
Member

additionally, cursor complained:

Max sendable amount overestimated with dust UTXOs

High Severity

The maxSendableAmount is computed as balance - newFeePrecalc.current, where balance is the total of ALL UTXOs but newFeePrecalc.current is the fee calculated by coinSelectSplit, which skips detrimental UTXOs (those costing more in fees than they're worth). This overstates the sendable amount by the sum of those skipped UTXOs. When createPsbtTransaction then forces this inflated value via targets.push({ address, value: maxSendableAmount }), coinSelect also skips the detrimental UTXOs and can't find enough funds, causing a "Not enough balance" error on a MAX send.

@Overtorment Overtorment 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.

e2e failed

@adamSHA256

adamSHA256 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

Fixed two issues with maxSendableAmount:

  1. Used lutxo instead of balance for the calculation - balance includes frozen UTXOs and doesn't match what coinSelectSplit actually receives
  2. Removed forcing maxSendableAmount as the target value during tx creation - this caused "Not enough balance" when coinselect skipped detrimental (dust) UTXOs. Now maxSendableAmount is display-only and coinSelectSplit determines the actual amount.
    Tested with coin control and frozen UTXOs.

@Overtorment could you check it again if I do not miss anything?

@GladosBlueWallet

Copy link
Copy Markdown
Collaborator

Wake the fuck up samurai, we have PRs to merge

image

[all PRs for @Overtorment] https://github.com/BlueWallet/BlueWallet/pulls/review-requested/Overtorment

@GladosBlueWallet

Copy link
Copy Markdown
Collaborator

I opened a new PR to run the full test suite with all CI env vars/secrets available: #8327

Running all tests there.

@Overtorment Overtorment 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.

LGTM! running test-suite to make sure all is good and we can merge

@Overtorment Overtorment merged commit 8bb4ee9 into BlueWallet:master Feb 26, 2026
20 of 22 checks passed
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.

9 participants