Skip to content

Commit 22cdf93

Browse files
author
MarcoFalke
committed
Merge #11316: [qt] Add use available balance in send coins dialog (CryptAxe, promag)
d052e38 [qt] Add use available balance in send coins dialog (CryptAxe) Pull request description: This is an alternative to #11098 to handle #11033 where a new button `Use available balance` is added to each entry. When activated, the available balance is calculated by using the coin control (if any) and then it's subtracted the remaining recipient amounts. If this amount is positive then the `Subtract fee from amount` is automatically selected. Comparing to #11098, this has the advantage to avoid the fair amount division over the recipients and allows to fine adjust the amounts in multiple iterations. Started from @CryptAxe commit 89e9eda to credit some code. <img width="965" alt="screen shot 2017-09-13 at 01 32 44" src="https://user-images.githubusercontent.com/3534524/30354518-e1bee31c-9824-11e7-9354-300aa63cdfd0.png"> <img width="964" alt="screen shot 2017-09-13 at 01 44 57" src="https://user-images.githubusercontent.com/3534524/30354598-5731ac9c-9825-11e7-9d5f-8781988ed219.png"> Tree-SHA512: 01d20c13fd8b6c2a0ca1d74d3a9027c6922e6dccd3b08e59d5a72636be7072ed5eca7ebc5d431299497dd3374e83753220ad4174d8bc46dadb4b2f54973036a5
2 parents 76b3349 + d052e38 commit 22cdf93

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

src/qt/forms/sendcoinsentry.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
</widget>
164164
</item>
165165
<item row="2" column="1">
166-
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1">
166+
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
167167
<item>
168168
<widget class="BitcoinAmountField" name="payAmount"/>
169169
</item>
@@ -177,6 +177,13 @@
177177
</property>
178178
</widget>
179179
</item>
180+
<item>
181+
<widget class="QPushButton" name="useAvailableBalanceButton">
182+
<property name="text">
183+
<string>Use available balance</string>
184+
</property>
185+
</widget>
186+
</item>
180187
</layout>
181188
</item>
182189
<item row="3" column="0">

src/qt/sendcoinsdialog.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ SendCoinsEntry *SendCoinsDialog::addEntry()
402402
entry->setModel(model);
403403
ui->entries->addWidget(entry);
404404
connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*)));
405+
connect(entry, SIGNAL(useAvailableBalance(SendCoinsEntry*)), this, SLOT(useAvailableBalance(SendCoinsEntry*)));
405406
connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels()));
406407
connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels()));
407408

@@ -599,6 +600,31 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked()
599600
minimizeFeeSection(true);
600601
}
601602

603+
void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
604+
{
605+
// Get CCoinControl instance if CoinControl is enabled or create a new one.
606+
CCoinControl coin_control;
607+
if (model->getOptionsModel()->getCoinControlFeatures()) {
608+
coin_control = *CoinControlDialog::coinControl;
609+
}
610+
611+
// Calculate available amount to send.
612+
CAmount amount = model->getBalance(&coin_control);
613+
for (int i = 0; i < ui->entries->count(); ++i) {
614+
SendCoinsEntry* e = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
615+
if (e && !e->isHidden() && e != entry) {
616+
amount -= e->getValue().amount;
617+
}
618+
}
619+
620+
if (amount > 0) {
621+
entry->checkSubtractFeeFromAmount();
622+
entry->setAmount(amount);
623+
} else {
624+
entry->setAmount(0);
625+
}
626+
}
627+
602628
void SendCoinsDialog::setMinimumFee()
603629
{
604630
ui->customFee->setValue(GetRequiredFee(1000));

src/qt/sendcoinsdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private Q_SLOTS:
7676
void on_buttonChooseFee_clicked();
7777
void on_buttonMinimizeFee_clicked();
7878
void removeEntry(SendCoinsEntry* entry);
79+
void useAvailableBalance(SendCoinsEntry* entry);
7980
void updateDisplayUnit();
8081
void coinControlFeatureChanged(bool);
8182
void coinControlButtonClicked();

src/qt/sendcoinsentry.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
4848
connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
4949
connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
5050
connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
51+
connect(ui->useAvailableBalanceButton, SIGNAL(clicked()), this, SLOT(useAvailableBalanceClicked()));
5152
}
5253

5354
SendCoinsEntry::~SendCoinsEntry()
@@ -112,11 +113,21 @@ void SendCoinsEntry::clear()
112113
updateDisplayUnit();
113114
}
114115

116+
void SendCoinsEntry::checkSubtractFeeFromAmount()
117+
{
118+
ui->checkboxSubtractFeeFromAmount->setChecked(true);
119+
}
120+
115121
void SendCoinsEntry::deleteClicked()
116122
{
117123
Q_EMIT removeEntry(this);
118124
}
119125

126+
void SendCoinsEntry::useAvailableBalanceClicked()
127+
{
128+
Q_EMIT useAvailableBalance(this);
129+
}
130+
120131
bool SendCoinsEntry::validate()
121132
{
122133
if (!model)
@@ -228,6 +239,11 @@ void SendCoinsEntry::setAddress(const QString &address)
228239
ui->payAmount->setFocus();
229240
}
230241

242+
void SendCoinsEntry::setAmount(const CAmount &amount)
243+
{
244+
ui->payAmount->setValue(amount);
245+
}
246+
231247
bool SendCoinsEntry::isClear()
232248
{
233249
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();

src/qt/sendcoinsentry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SendCoinsEntry : public QStackedWidget
3838

3939
void setValue(const SendCoinsRecipient &value);
4040
void setAddress(const QString &address);
41+
void setAmount(const CAmount &amount);
4142

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

4950
public Q_SLOTS:
5051
void clear();
52+
void checkSubtractFeeFromAmount();
5153

5254
Q_SIGNALS:
5355
void removeEntry(SendCoinsEntry *entry);
56+
void useAvailableBalance(SendCoinsEntry* entry);
5457
void payAmountChanged();
5558
void subtractFeeFromAmountChanged();
5659

5760
private Q_SLOTS:
5861
void deleteClicked();
62+
void useAvailableBalanceClicked();
5963
void on_payTo_textChanged(const QString &address);
6064
void on_addressBookButton_clicked();
6165
void on_pasteButton_clicked();

0 commit comments

Comments
 (0)