Skip to content

Commit

Permalink
Merge pull request #3391
Browse files Browse the repository at this point in the history
3380713 [Qt] coin control change address handling update (Philip Kaufmann)
  • Loading branch information
laanwj committed Dec 20, 2013
2 parents 9e508b5 + 3380713 commit 3653501
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
}
}

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

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

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

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

QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)) + "<br /><br />";
Expand Down
57 changes: 29 additions & 28 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,44 +546,45 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
// Coin Control: custom change address changed
void SendCoinsDialog::coinControlChangeEdited(const QString& text)
{
if (model)
if (model && model->getAddressTableModel())
{
CoinControlDialog::coinControl->destChange = CBitcoinAddress(text.toStdString()).Get();
// Default to no change address until verified
CoinControlDialog::coinControl->destChange = CNoDestination();
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");

CBitcoinAddress addr = CBitcoinAddress(text.toStdString());

// label for the change address
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");
if (text.isEmpty())
if (text.isEmpty()) // Nothing entered
{
ui->labelCoinControlChangeLabel->setText("");
else if (!CBitcoinAddress(text.toStdString()).IsValid())
}
else if (!addr.IsValid()) // Invalid address
{
// invalid change address
CoinControlDialog::coinControl->destChange = CNoDestination();

ui->lineEditCoinControlChange->setValid(false);
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address"));
}
else
else // Valid address
{
QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
if (!associatedLabel.isEmpty())
ui->labelCoinControlChangeLabel->setText(associatedLabel);
else
CPubKey pubkey;
CKeyID keyid;
addr.GetKeyID(keyid);
if (!model->getPubKey(keyid, pubkey)) // Unknown change address
{
CPubKey pubkey;
CKeyID keyid;
CBitcoinAddress(text.toStdString()).GetKeyID(keyid);
if (model->getPubKey(keyid, pubkey))
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
ui->lineEditCoinControlChange->setValid(false);
ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
}
else // Known change address
{
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");

// Query label
QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
if (!associatedLabel.isEmpty())
ui->labelCoinControlChangeLabel->setText(associatedLabel);
else
{
// unknown change address
CoinControlDialog::coinControl->destChange = CNoDestination();

ui->lineEditCoinControlChange->setValid(false);
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
}
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));

CoinControlDialog::coinControl->destChange = addr.Get();
}
}
}
Expand Down

0 comments on commit 3653501

Please sign in to comment.