Skip to content

Commit

Permalink
[Qt] Add spend all button to the SendCoinsDialog
Browse files Browse the repository at this point in the history
Get the balance of the wallet (with CoinControl if enabled).
Then divide the amount available by all of the SendCoinEntry(s) and
check the subtract fee from amount checkbox for all SendCoinEntry(s).
  • Loading branch information
CryptAxe committed Aug 20, 2017
1 parent 2621673 commit 89e9eda
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/qt/forms/sendcoinsdialog.ui
Expand Up @@ -1223,6 +1223,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonSendAll">
<property name="text">
<string>Send All</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
Expand Down
28 changes: 28 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Expand Up @@ -607,6 +607,34 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
minimizeFeeSection(true);
}

void SendCoinsDialog::on_buttonSendAll_clicked()
{
// Get CCoinControl instance if CoinControl is enabled or create a new one
CCoinControl coinControl;
if (model->getOptionsModel()->getCoinControlFeatures())
coinControl = *CoinControlDialog::coinControl;

// Calculate total amount to spend
CAmount nTotalAmount = model->getBalance(&coinControl);

// Calculate amount per entry
int nEntries = ui->entries->count();
CAmount nAmountPerEntry = (nEntries ? (nTotalAmount / nEntries) : nTotalAmount);

for(int i = 0; i < nEntries; ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if(entry)
{
// Check subtract fee from amount checkbox
entry->checkSubtractFeeFromAmount();

// Set new amount for entry
entry->setAmount(nAmountPerEntry);
}
}
}

void SendCoinsDialog::setMinimumFee()
{
ui->radioCustomPerKilobyte->setChecked(true);
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsdialog.h
Expand Up @@ -75,6 +75,7 @@ private Q_SLOTS:
void on_sendButton_clicked();
void on_buttonChooseFee_clicked();
void on_buttonMinimizeFee_clicked();
void on_buttonSendAll_clicked();
void removeEntry(SendCoinsEntry* entry);
void updateDisplayUnit();
void coinControlFeatureChanged(bool);
Expand Down
10 changes: 10 additions & 0 deletions src/qt/sendcoinsentry.cpp
Expand Up @@ -112,6 +112,11 @@ void SendCoinsEntry::clear()
updateDisplayUnit();
}

void SendCoinsEntry::checkSubtractFeeFromAmount()
{
ui->checkboxSubtractFeeFromAmount->setChecked(true);
}

void SendCoinsEntry::deleteClicked()
{
Q_EMIT removeEntry(this);
Expand Down Expand Up @@ -228,6 +233,11 @@ void SendCoinsEntry::setAddress(const QString &address)
ui->payAmount->setFocus();
}

void SendCoinsEntry::setAmount(const CAmount &amount)
{
ui->payAmount->setValue(amount);
}

bool SendCoinsEntry::isClear()
{
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/sendcoinsentry.h
Expand Up @@ -38,6 +38,7 @@ class SendCoinsEntry : public QStackedWidget

void setValue(const SendCoinsRecipient &value);
void setAddress(const QString &address);
void setAmount(const CAmount &amount);

/** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases
* (issue https://bugreports.qt-project.org/browse/QTBUG-10907).
Expand All @@ -48,6 +49,7 @@ class SendCoinsEntry : public QStackedWidget

public Q_SLOTS:
void clear();
void checkSubtractFeeFromAmount();

Q_SIGNALS:
void removeEntry(SendCoinsEntry *entry);
Expand Down

0 comments on commit 89e9eda

Please sign in to comment.