fix(send): resolve source balance by address, not list index

GetAvailableBalance() read state.addresses[s_selected_from_idx], but the index
desyncs from s_from_address (the value actually debited) after an address-list
refresh, and is left at -1 when the source is chosen from another tab's "Send
from this address" — which made the sufficiency check see a 0 balance and wrongly
block a valid send. Look the balance up by matching the source address string.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 14:18:16 -05:00
parent 5c883d4b91
commit 8f22db5eea

View File

@@ -130,6 +130,15 @@ static void ClearFormWithUndo() {
static double GetAvailableBalance(App* app) {
const auto& state = app->getWalletState();
// Resolve the balance by the source ADDRESS STRING (the value actually debited on send),
// not a stored list index. The index desyncs from s_from_address after an address-list
// refresh, and is left at -1 when the source is chosen from another tab ("Send from this
// address") — which previously made the sufficiency check see 0 and block a valid send.
if (s_from_address[0] != '\0') {
for (const auto& a : state.addresses) {
if (a.address == s_from_address) return a.balance;
}
}
if (s_selected_from_idx >= 0 && s_selected_from_idx < static_cast<int>(state.addresses.size())) {
return state.addresses[s_selected_from_idx].balance;
}