qt: Display txfee in first sendCoinsDialog message box

Signed-off-by: Jonas Schnelli <jonas.schnelli@include7.ch>
This commit is contained in:
Jonas Schnelli
2013-08-30 20:04:48 +02:00
committed by Wladimir J. van der Laan
parent 329de9bb64
commit 9e8904f6ae
7 changed files with 207 additions and 47 deletions

View File

@@ -97,9 +97,18 @@ void SendCoinsDialog::on_sendButton_clicked()
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
if (rcp.authenticatedMerchant.isEmpty())
{
QString address = rcp.address;
QString to = GUIUtil::HtmlEscape(rcp.label);
formatted.append(tr("<b>%1</b> to %2 (%3)").arg(amount, to, address));
QString recipientElement = QString("<b>%1</b> ").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount));
recipientElement.append(tr("to"));
if(rcp.label.length() > 0)
{
recipientElement.append(QString(" %1 <span style='font-size:8px;'>%2</span><br />").arg(GUIUtil::HtmlEscape(rcp.label), rcp.address)); // add address with label
}
else
{
recipientElement.append(QString(" %1<br />").arg(rcp.address)); // add address WITHOUT label
}
formatted.append(recipientElement);
}
else
{
@@ -110,16 +119,6 @@ void SendCoinsDialog::on_sendButton_clicked()
fNewRecipientAllowed = false;
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
tr("Are you sure you want to send %1?").arg(formatted.join(tr(" and "))),
QMessageBox::Yes|QMessageBox::Cancel,
QMessageBox::Cancel);
if(retval != QMessageBox::Yes)
{
fNewRecipientAllowed = true;
return;
}
WalletModel::UnlockContext ctx(model->requestUnlock());
if(!ctx.isValid())
@@ -129,8 +128,11 @@ void SendCoinsDialog::on_sendButton_clicked()
return;
}
WalletModel::SendCoinsReturn sendstatus = model->sendCoins(recipients);
switch(sendstatus.status)
// prepare transaction for getting txFee earlier
WalletModelTransaction currentTransaction(recipients);
WalletModel::SendCoinsReturn prepareStatus = model->prepareTransaction(currentTransaction);
switch(prepareStatus.status)
{
case WalletModel::InvalidAddress:
QMessageBox::warning(this, tr("Send Coins"),
@@ -150,7 +152,7 @@ void SendCoinsDialog::on_sendButton_clicked()
case WalletModel::AmountWithFeeExceedsBalance:
QMessageBox::warning(this, tr("Send Coins"),
tr("The total exceeds your balance when the %1 transaction fee is included.").
arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), sendstatus.fee)),
arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())),
QMessageBox::Ok, QMessageBox::Ok);
break;
case WalletModel::DuplicateAddress:
@@ -163,6 +165,51 @@ void SendCoinsDialog::on_sendButton_clicked()
tr("Error: Transaction creation failed!"),
QMessageBox::Ok, QMessageBox::Ok);
break;
case WalletModel::Aborted: // User aborted, nothing to do
case WalletModel::OK:
case WalletModel::TransactionCommitFailed:
break;
}
if(prepareStatus.status != WalletModel::OK) {
fNewRecipientAllowed = true;
return;
}
qint64 txFee = currentTransaction.getTransactionFee();
QString questionString = tr("Are you sure you want to send?");
questionString.append("<br /><br />%1");
if(txFee > 0)
{
// append fee string if a fee is required
questionString.append("<hr /><span style='color:#aa0000;'>");
questionString.append(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
questionString.append("</span> ");
questionString.append(tr("added as transaction fee"));
}
if(txFee > 0 || recipients.count() > 1)
{
// add total amount string if there are more then one recipients or a fee is required
questionString.append("<hr />");
questionString.append(tr("Total Amount %1").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTotalTransactionAmount()+txFee)));
}
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
questionString.arg(formatted.join("<br />")),
QMessageBox::Yes|QMessageBox::Cancel,
QMessageBox::Cancel);
if(retval != QMessageBox::Yes)
{
fNewRecipientAllowed = true;
return;
}
// now send the prepared transaction
WalletModel::SendCoinsReturn sendstatus = model->sendCoins(currentTransaction);
switch(sendstatus.status)
{
case WalletModel::TransactionCommitFailed:
QMessageBox::warning(this, tr("Send Coins"),
tr("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."),
@@ -173,6 +220,8 @@ void SendCoinsDialog::on_sendButton_clicked()
case WalletModel::OK:
accept();
break;
default:
break;
}
fNewRecipientAllowed = true;
}