Skip to content

Elements-qt: Use available balance from the currently selected asset #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,21 +777,25 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
// Include watch-only for wallets without private key
m_coin_control->fAllowWatchOnly = model->wallet().privateKeysDisabled() && !model->wallet().hasExternalSigner();

SendAssetsRecipient recipient = entry->getValue();
// Calculate available amount to send.
CAmount amount = valueFor(model->wallet().getAvailableBalance(*m_coin_control), ::policyAsset);
CAmount amount = valueFor(model->wallet().getAvailableBalance(*m_coin_control), recipient.asset);
for (int i = 0; i < ui->entries->count(); ++i) {
SendCoinsEntry* e = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if (e && !e->isHidden() && e != entry && e->getValue().asset == ::policyAsset) {
if (e && !e->isHidden() && e != entry && e->getValue().asset == recipient.asset) {
amount -= e->getValue().asset_amount;
}
}

if (amount > 0) {
entry->checkSubtractFeeFromAmount();
entry->setAmount(amount);
if (recipient.asset == ::policyAsset) {
entry->checkSubtractFeeFromAmount();
}
recipient.asset_amount = amount;
} else {
entry->setAmount(0);
recipient.asset_amount = 0;
}
entry->setValue(recipient);
}

void SendCoinsDialog::updateFeeSectionControls()
Expand Down