Changeset View
Changeset View
Standalone View
Standalone View
src/qt/sendcoinsdialog.cpp
Show First 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | void SendCoinsDialog::on_sendButton_clicked() { | ||||
// prepare transaction for getting txFee earlier | // prepare transaction for getting txFee earlier | ||||
WalletModelTransaction currentTransaction(recipients); | WalletModelTransaction currentTransaction(recipients); | ||||
WalletModel::SendCoinsReturn prepareStatus; | WalletModel::SendCoinsReturn prepareStatus; | ||||
// Always use a CCoinControl instance, use the CoinControlDialog instance if | // Always use a CCoinControl instance, use the CoinControlDialog instance if | ||||
// CoinControl has been enabled | // CoinControl has been enabled | ||||
CCoinControl ctrl; | CCoinControl ctrl; | ||||
if (model->getOptionsModel()->getCoinControlFeatures()) { | if (model->getOptionsModel()->getCoinControlFeatures()) { | ||||
ctrl = *CoinControlDialog::coinControl; | ctrl = *CoinControlDialog::coinControl(); | ||||
} | } | ||||
updateCoinControlState(ctrl); | updateCoinControlState(ctrl); | ||||
prepareStatus = model->prepareTransaction(currentTransaction, ctrl); | prepareStatus = model->prepareTransaction(currentTransaction, ctrl); | ||||
// process prepareStatus and on error generate message shown to user | // process prepareStatus and on error generate message shown to user | ||||
processSendCoinsReturn( | processSendCoinsReturn( | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | void SendCoinsDialog::on_sendButton_clicked() { | ||||
// now send the prepared transaction | // now send the prepared transaction | ||||
WalletModel::SendCoinsReturn sendStatus = | WalletModel::SendCoinsReturn sendStatus = | ||||
model->sendCoins(currentTransaction); | model->sendCoins(currentTransaction); | ||||
// process sendStatus and on error generate message shown to user | // process sendStatus and on error generate message shown to user | ||||
processSendCoinsReturn(sendStatus); | processSendCoinsReturn(sendStatus); | ||||
if (sendStatus.status == WalletModel::OK) { | if (sendStatus.status == WalletModel::OK) { | ||||
accept(); | accept(); | ||||
CoinControlDialog::coinControl->UnSelectAll(); | CoinControlDialog::coinControl()->UnSelectAll(); | ||||
coinControlUpdateLabels(); | coinControlUpdateLabels(); | ||||
Q_EMIT coinsSent(currentTransaction.getTransaction()->GetId()); | Q_EMIT coinsSent(currentTransaction.getTransaction()->GetId()); | ||||
} | } | ||||
fNewRecipientAllowed = true; | fNewRecipientAllowed = true; | ||||
} | } | ||||
void SendCoinsDialog::clear() { | void SendCoinsDialog::clear() { | ||||
// Remove entries until only one left | // Remove entries until only one left | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | void SendCoinsDialog::on_buttonMinimizeFee_clicked() { | ||||
updateFeeMinimizedLabel(); | updateFeeMinimizedLabel(); | ||||
minimizeFeeSection(true); | minimizeFeeSection(true); | ||||
} | } | ||||
void SendCoinsDialog::useAvailableBalance(SendCoinsEntry *entry) { | void SendCoinsDialog::useAvailableBalance(SendCoinsEntry *entry) { | ||||
// Get CCoinControl instance if CoinControl is enabled or create a new one. | // Get CCoinControl instance if CoinControl is enabled or create a new one. | ||||
CCoinControl coin_control; | CCoinControl coin_control; | ||||
if (model->getOptionsModel()->getCoinControlFeatures()) { | if (model->getOptionsModel()->getCoinControlFeatures()) { | ||||
coin_control = *CoinControlDialog::coinControl; | coin_control = *CoinControlDialog::coinControl(); | ||||
} | } | ||||
// Calculate available amount to send. | // Calculate available amount to send. | ||||
Amount amount = model->getBalance(&coin_control); | Amount amount = model->getBalance(&coin_control); | ||||
for (int i = 0; i < ui->entries->count(); ++i) { | for (int i = 0; i < ui->entries->count(); ++i) { | ||||
SendCoinsEntry *e = | SendCoinsEntry *e = | ||||
qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget()); | qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget()); | ||||
if (e && !e->isHidden() && e != entry) { | if (e && !e->isHidden() && e != entry) { | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// Coin Control: settings menu - coin control enabled/disabled by user | // Coin Control: settings menu - coin control enabled/disabled by user | ||||
void SendCoinsDialog::coinControlFeatureChanged(bool checked) { | void SendCoinsDialog::coinControlFeatureChanged(bool checked) { | ||||
ui->frameCoinControl->setVisible(checked); | ui->frameCoinControl->setVisible(checked); | ||||
// coin control features disabled | // coin control features disabled | ||||
if (!checked && model) { | if (!checked && model) { | ||||
CoinControlDialog::coinControl->SetNull(); | CoinControlDialog::coinControl()->SetNull(); | ||||
} | } | ||||
coinControlUpdateLabels(); | coinControlUpdateLabels(); | ||||
} | } | ||||
// Coin Control: button inputs -> show actual coin control dialog | // Coin Control: button inputs -> show actual coin control dialog | ||||
void SendCoinsDialog::coinControlButtonClicked() { | void SendCoinsDialog::coinControlButtonClicked() { | ||||
CoinControlDialog dlg(platformStyle); | CoinControlDialog dlg(platformStyle); | ||||
dlg.setModel(model); | dlg.setModel(model); | ||||
dlg.exec(); | dlg.exec(); | ||||
coinControlUpdateLabels(); | coinControlUpdateLabels(); | ||||
} | } | ||||
// Coin Control: checkbox custom change address | // Coin Control: checkbox custom change address | ||||
void SendCoinsDialog::coinControlChangeChecked(int state) { | void SendCoinsDialog::coinControlChangeChecked(int state) { | ||||
if (state == Qt::Unchecked) { | if (state == Qt::Unchecked) { | ||||
CoinControlDialog::coinControl->destChange = CNoDestination(); | CoinControlDialog::coinControl()->destChange = CNoDestination(); | ||||
ui->labelCoinControlChangeLabel->clear(); | ui->labelCoinControlChangeLabel->clear(); | ||||
} else { | } else { | ||||
// use this to re-validate an already entered address | // use this to re-validate an already entered address | ||||
coinControlChangeEdited(ui->lineEditCoinControlChange->text()); | coinControlChangeEdited(ui->lineEditCoinControlChange->text()); | ||||
} | } | ||||
ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); | ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked)); | ||||
} | } | ||||
// Coin Control: custom change address changed | // Coin Control: custom change address changed | ||||
void SendCoinsDialog::coinControlChangeEdited(const QString &text) { | void SendCoinsDialog::coinControlChangeEdited(const QString &text) { | ||||
if (model && model->getAddressTableModel()) { | if (model && model->getAddressTableModel()) { | ||||
// Default to no change address until verified | // Default to no change address until verified | ||||
CoinControlDialog::coinControl->destChange = CNoDestination(); | CoinControlDialog::coinControl()->destChange = CNoDestination(); | ||||
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); | ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); | ||||
const CTxDestination dest = | const CTxDestination dest = | ||||
DecodeDestination(text.toStdString(), model->getChainParams()); | DecodeDestination(text.toStdString(), model->getChainParams()); | ||||
if (text.isEmpty()) { | if (text.isEmpty()) { | ||||
// Nothing entered | // Nothing entered | ||||
ui->labelCoinControlChangeLabel->setText(""); | ui->labelCoinControlChangeLabel->setText(""); | ||||
Show All 12 Lines | if (model && model->getAddressTableModel()) { | ||||
this, tr("Confirm custom change address"), | this, tr("Confirm custom change address"), | ||||
tr("The address you selected for change is not part of " | tr("The address you selected for change is not part of " | ||||
"this wallet. Any or all funds in your wallet may be " | "this wallet. Any or all funds in your wallet may be " | ||||
"sent to this address. Are you sure?"), | "sent to this address. Are you sure?"), | ||||
QMessageBox::Yes | QMessageBox::Cancel, | QMessageBox::Yes | QMessageBox::Cancel, | ||||
QMessageBox::Cancel); | QMessageBox::Cancel); | ||||
if (btnRetVal == QMessageBox::Yes) { | if (btnRetVal == QMessageBox::Yes) { | ||||
CoinControlDialog::coinControl->destChange = dest; | CoinControlDialog::coinControl()->destChange = dest; | ||||
} else { | } else { | ||||
ui->lineEditCoinControlChange->setText(""); | ui->lineEditCoinControlChange->setText(""); | ||||
ui->labelCoinControlChangeLabel->setStyleSheet( | ui->labelCoinControlChangeLabel->setStyleSheet( | ||||
"QLabel{color:black;}"); | "QLabel{color:black;}"); | ||||
ui->labelCoinControlChangeLabel->setText(""); | ui->labelCoinControlChangeLabel->setText(""); | ||||
} | } | ||||
} else { | } else { | ||||
// Known change address | // Known change address | ||||
ui->labelCoinControlChangeLabel->setStyleSheet( | ui->labelCoinControlChangeLabel->setStyleSheet( | ||||
"QLabel{color:black;}"); | "QLabel{color:black;}"); | ||||
// Query label | // Query label | ||||
QString associatedLabel = | QString associatedLabel = | ||||
model->getAddressTableModel()->labelForAddress(text); | model->getAddressTableModel()->labelForAddress(text); | ||||
if (!associatedLabel.isEmpty()) { | if (!associatedLabel.isEmpty()) { | ||||
ui->labelCoinControlChangeLabel->setText(associatedLabel); | ui->labelCoinControlChangeLabel->setText(associatedLabel); | ||||
} else { | } else { | ||||
ui->labelCoinControlChangeLabel->setText(tr("(no label)")); | ui->labelCoinControlChangeLabel->setText(tr("(no label)")); | ||||
} | } | ||||
CoinControlDialog::coinControl->destChange = dest; | CoinControlDialog::coinControl()->destChange = dest; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Coin Control: update labels | // Coin Control: update labels | ||||
void SendCoinsDialog::coinControlUpdateLabels() { | void SendCoinsDialog::coinControlUpdateLabels() { | ||||
if (!model || !model->getOptionsModel()) { | if (!model || !model->getOptionsModel()) { | ||||
return; | return; | ||||
} | } | ||||
updateCoinControlState(*CoinControlDialog::coinControl); | updateCoinControlState(*CoinControlDialog::coinControl()); | ||||
// set pay amounts | // set pay amounts | ||||
CoinControlDialog::payAmounts.clear(); | CoinControlDialog::payAmounts.clear(); | ||||
CoinControlDialog::fSubtractFeeFromAmount = false; | CoinControlDialog::fSubtractFeeFromAmount = false; | ||||
for (int i = 0; i < ui->entries->count(); ++i) { | for (int i = 0; i < ui->entries->count(); ++i) { | ||||
SendCoinsEntry *entry = | SendCoinsEntry *entry = | ||||
qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget()); | qobject_cast<SendCoinsEntry *>(ui->entries->itemAt(i)->widget()); | ||||
if (entry && !entry->isHidden()) { | if (entry && !entry->isHidden()) { | ||||
SendCoinsRecipient rcp = entry->getValue(); | SendCoinsRecipient rcp = entry->getValue(); | ||||
CoinControlDialog::payAmounts.append(rcp.amount); | CoinControlDialog::payAmounts.append(rcp.amount); | ||||
if (rcp.fSubtractFeeFromAmount) { | if (rcp.fSubtractFeeFromAmount) { | ||||
CoinControlDialog::fSubtractFeeFromAmount = true; | CoinControlDialog::fSubtractFeeFromAmount = true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (CoinControlDialog::coinControl->HasSelected()) { | if (CoinControlDialog::coinControl()->HasSelected()) { | ||||
// actual coin control calculation | // actual coin control calculation | ||||
CoinControlDialog::updateLabels(model, this); | CoinControlDialog::updateLabels(model, this); | ||||
// show coin control stats | // show coin control stats | ||||
ui->labelCoinControlAutomaticallySelected->hide(); | ui->labelCoinControlAutomaticallySelected->hide(); | ||||
ui->widgetCoinControl->show(); | ui->widgetCoinControl->show(); | ||||
} else { | } else { | ||||
// hide coin control stats | // hide coin control stats | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |