Skip to content

Commit 3653501

Browse files
committed
Merge pull request #3391
3380713 [Qt] coin control change address handling update (Philip Kaufmann)
2 parents 9e508b5 + 3380713 commit 3653501

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
449449
}
450450
}
451451

452-
QString sPriorityLabel = "";
452+
QString sPriorityLabel = tr("none");
453453
int64_t nAmount = 0;
454454
int64_t nPayFee = 0;
455455
int64_t nAfterFee = 0;
@@ -593,18 +593,18 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
593593
l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); // Change
594594

595595
// turn labels "red"
596-
l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000
597-
l6->setStyleSheet((!AllowFree(dPriority)) ? "color:red;" : ""); // Priority < "medium"
598-
l7->setStyleSheet((fLowOutput) ? "color:red;" : ""); // Low Output = "yes"
599-
l8->setStyleSheet((nChange > 0 && nChange < CENT) ? "color:red;" : ""); // Change < 0.01BTC
596+
l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000
597+
l6->setStyleSheet((dPriority > 0 && !AllowFree(dPriority)) ? "color:red;" : ""); // Priority < "medium"
598+
l7->setStyleSheet((fLowOutput) ? "color:red;" : ""); // Low Output = "yes"
599+
l8->setStyleSheet((nChange > 0 && nChange < CENT) ? "color:red;" : ""); // Change < 0.01BTC
600600

601601
// tool tips
602602
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
603603
toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::nMinTxFee)) + "<br /><br />";
604604
toolTip1 += tr("Can vary +/- 1 byte per input.");
605605

606606
QString toolTip2 = tr("Transactions with higher priority are more likely to get included into a block.") + "<br /><br />";
607-
toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\"") + "<br /><br />";
607+
toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\".") + "<br /><br />";
608608
toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::nMinTxFee));
609609

610610
QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)) + "<br /><br />";

src/qt/sendcoinsdialog.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -546,44 +546,45 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
546546
// Coin Control: custom change address changed
547547
void SendCoinsDialog::coinControlChangeEdited(const QString& text)
548548
{
549-
if (model)
549+
if (model && model->getAddressTableModel())
550550
{
551-
CoinControlDialog::coinControl->destChange = CBitcoinAddress(text.toStdString()).Get();
551+
// Default to no change address until verified
552+
CoinControlDialog::coinControl->destChange = CNoDestination();
553+
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
554+
555+
CBitcoinAddress addr = CBitcoinAddress(text.toStdString());
552556

553-
// label for the change address
554-
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");
555-
if (text.isEmpty())
557+
if (text.isEmpty()) // Nothing entered
558+
{
556559
ui->labelCoinControlChangeLabel->setText("");
557-
else if (!CBitcoinAddress(text.toStdString()).IsValid())
560+
}
561+
else if (!addr.IsValid()) // Invalid address
558562
{
559-
// invalid change address
560-
CoinControlDialog::coinControl->destChange = CNoDestination();
561-
562563
ui->lineEditCoinControlChange->setValid(false);
563-
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
564564
ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address"));
565565
}
566-
else
566+
else // Valid address
567567
{
568-
QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
569-
if (!associatedLabel.isEmpty())
570-
ui->labelCoinControlChangeLabel->setText(associatedLabel);
571-
else
568+
CPubKey pubkey;
569+
CKeyID keyid;
570+
addr.GetKeyID(keyid);
571+
if (!model->getPubKey(keyid, pubkey)) // Unknown change address
572572
{
573-
CPubKey pubkey;
574-
CKeyID keyid;
575-
CBitcoinAddress(text.toStdString()).GetKeyID(keyid);
576-
if (model->getPubKey(keyid, pubkey))
577-
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
573+
ui->lineEditCoinControlChange->setValid(false);
574+
ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
575+
}
576+
else // Known change address
577+
{
578+
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");
579+
580+
// Query label
581+
QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
582+
if (!associatedLabel.isEmpty())
583+
ui->labelCoinControlChangeLabel->setText(associatedLabel);
578584
else
579-
{
580-
// unknown change address
581-
CoinControlDialog::coinControl->destChange = CNoDestination();
582-
583-
ui->lineEditCoinControlChange->setValid(false);
584-
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
585-
ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
586-
}
585+
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
586+
587+
CoinControlDialog::coinControl->destChange = addr.Get();
587588
}
588589
}
589590
}

0 commit comments

Comments
 (0)