diff options
| author | CryptAxe <[email protected]> | 2017-08-19 22:04:56 -0700 |
|---|---|---|
| committer | João Barbosa <[email protected]> | 2017-09-13 01:24:07 +0100 |
| commit | d052e3847c84fc89f3a3ec6ddef15bbe836d755d (patch) | |
| tree | 4afc8b1a28d19a2533d4f90e935f051797878bb7 /src/qt/sendcoinsdialog.cpp | |
| parent | Merge #11310: [tests] Test listwallets RPC (diff) | |
| download | discoin-d052e3847c84fc89f3a3ec6ddef15bbe836d755d.tar.xz discoin-d052e3847c84fc89f3a3ec6ddef15bbe836d755d.zip | |
[qt] Add use available balance in send coins dialog
Diffstat (limited to 'src/qt/sendcoinsdialog.cpp')
| -rw-r--r-- | src/qt/sendcoinsdialog.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 05c5ccbfe..ce88c305e 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -410,6 +410,7 @@ SendCoinsEntry *SendCoinsDialog::addEntry() entry->setModel(model); ui->entries->addWidget(entry); connect(entry, SIGNAL(removeEntry(SendCoinsEntry*)), this, SLOT(removeEntry(SendCoinsEntry*))); + connect(entry, SIGNAL(useAvailableBalance(SendCoinsEntry*)), this, SLOT(useAvailableBalance(SendCoinsEntry*))); connect(entry, SIGNAL(payAmountChanged()), this, SLOT(coinControlUpdateLabels())); connect(entry, SIGNAL(subtractFeeFromAmountChanged()), this, SLOT(coinControlUpdateLabels())); @@ -607,6 +608,31 @@ void SendCoinsDialog::on_buttonMinimizeFee_clicked() minimizeFeeSection(true); } +void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry) +{ + // Get CCoinControl instance if CoinControl is enabled or create a new one. + CCoinControl coin_control; + if (model->getOptionsModel()->getCoinControlFeatures()) { + coin_control = *CoinControlDialog::coinControl; + } + + // Calculate available amount to send. + CAmount amount = model->getBalance(&coin_control); + 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) { + amount -= e->getValue().amount; + } + } + + if (amount > 0) { + entry->checkSubtractFeeFromAmount(); + entry->setAmount(amount); + } else { + entry->setAmount(0); + } +} + void SendCoinsDialog::setMinimumFee() { ui->radioCustomPerKilobyte->setChecked(true); |