aboutsummaryrefslogtreecommitdiff
path: root/src/qt/sendcoinsdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/sendcoinsdialog.cpp')
-rw-r--r--src/qt/sendcoinsdialog.cpp169
1 files changed, 103 insertions, 66 deletions
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 9086f6614e..3fd4a26e76 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -63,12 +63,12 @@ SendCoinsDialog::~SendCoinsDialog()
void SendCoinsDialog::on_sendButton_clicked()
{
+ if(!model || !model->getOptionsModel())
+ return;
+
QList<SendCoinsRecipient> recipients;
bool valid = true;
- if(!model)
- return;
-
for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
@@ -94,40 +94,37 @@ void SendCoinsDialog::on_sendButton_clicked()
QStringList formatted;
foreach(const SendCoinsRecipient &rcp, recipients)
{
- QString amount = BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount);
+ // generate bold amount string
+ QString amount = "<b>" + BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
+ amount.append("</b>");
+ // generate monospace address string
+ QString address = "<span style='font-family: monospace;'>" + rcp.address;
+ address.append("</span>");
+
+ QString recipientElement;
+
if (rcp.authenticatedMerchant.isEmpty())
{
- QString address = rcp.address;
-#if QT_VERSION < 0x050000
- QString to = Qt::escape(rcp.label);
-#else
- QString to = rcp.label.toHtmlEscaped();
-#endif
- formatted.append(tr("<b>%1</b> to %2 (%3)").arg(amount, to, address));
+ if(rcp.label.length() > 0) // label with address
+ {
+ recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.label));
+ recipientElement.append(QString(" (%1)").arg(address));
+ }
+ else // just address
+ {
+ recipientElement = tr("%1 to %2").arg(amount, address);
+ }
}
- else
+ else // just merchant
{
-#if QT_VERSION < 0x050000
- QString merchant = Qt::escape(rcp.authenticatedMerchant);
-#else
- QString merchant = rcp.authenticatedMerchant.toHtmlEscaped();
-#endif
- formatted.append(tr("<b>%1</b> to %2").arg(amount, merchant));
+ recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant));
}
+
+ formatted.append(recipientElement);
}
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())
@@ -137,50 +134,94 @@ 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);
+
+ QString strSendCoins = tr("Send Coins");
+ switch(prepareStatus.status)
{
case WalletModel::InvalidAddress:
- QMessageBox::warning(this, tr("Send Coins"),
- tr("The recipient address is not valid, please recheck."),
- QMessageBox::Ok, QMessageBox::Ok);
+ QMessageBox::warning(this, strSendCoins,
+ tr("The recipient address is not valid, please recheck."));
break;
case WalletModel::InvalidAmount:
- QMessageBox::warning(this, tr("Send Coins"),
- tr("The amount to pay must be larger than 0."),
- QMessageBox::Ok, QMessageBox::Ok);
+ QMessageBox::warning(this, strSendCoins,
+ tr("The amount to pay must be larger than 0."));
break;
case WalletModel::AmountExceedsBalance:
- QMessageBox::warning(this, tr("Send Coins"),
- tr("The amount exceeds your balance."),
- QMessageBox::Ok, QMessageBox::Ok);
+ QMessageBox::warning(this, strSendCoins,
+ tr("The amount exceeds your balance."));
break;
case WalletModel::AmountWithFeeExceedsBalance:
- QMessageBox::warning(this, tr("Send Coins"),
+ QMessageBox::warning(this, strSendCoins,
tr("The total exceeds your balance when the %1 transaction fee is included.").
- arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, sendstatus.fee)),
- QMessageBox::Ok, QMessageBox::Ok);
+ arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())));
break;
case WalletModel::DuplicateAddress:
- QMessageBox::warning(this, tr("Send Coins"),
- tr("Duplicate address found, can only send to each address once per send operation."),
- QMessageBox::Ok, QMessageBox::Ok);
+ QMessageBox::warning(this, strSendCoins,
+ tr("Duplicate address found, can only send to each address once per send operation."));
break;
case WalletModel::TransactionCreationFailed:
- QMessageBox::warning(this, tr("Send Coins"),
- tr("Error: Transaction creation failed!"),
- QMessageBox::Ok, QMessageBox::Ok);
+ QMessageBox::warning(this, strSendCoins,
+ tr("Error: Transaction creation failed!"));
break;
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."),
- QMessageBox::Ok, QMessageBox::Ok);
- break;
+ case WalletModel::OK:
case WalletModel::Aborted: // User aborted, nothing to do
+ default:
+ 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, strSendCoins,
+ 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."));
break;
case WalletModel::OK:
accept();
break;
+ case WalletModel::Aborted: // User aborted, nothing to do
+ default:
+ break;
}
fNewRecipientAllowed = true;
}
@@ -310,22 +351,22 @@ void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
{
+ QString strSendCoins = tr("Send Coins");
if (!rv.authenticatedMerchant.isEmpty()) {
// Expired payment request?
const payments::PaymentDetails& details = rv.paymentRequest.getDetails();
if (details.has_expires() && (int64)details.expires() < GetTime())
{
- QMessageBox::warning(this, tr("Send Coins"),
- tr("Payment request expired"));
+ QMessageBox::warning(this, strSendCoins,
+ tr("Payment request expired"));
return false;
}
}
else {
CBitcoinAddress address(rv.address.toStdString());
if (!address.IsValid()) {
- QString strAddress(address.ToString().c_str());
- QMessageBox::warning(this, tr("Send Coins"),
- tr("Invalid payment address %1").arg(strAddress));
+ QMessageBox::warning(this, strSendCoins,
+ tr("Invalid payment address %1").arg(rv.address));
return false;
}
}
@@ -338,18 +379,14 @@ void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint
{
Q_UNUSED(unconfirmedBalance);
Q_UNUSED(immatureBalance);
- if(!model || !model->getOptionsModel())
- return;
- int unit = model->getOptionsModel()->getDisplayUnit();
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
+ if(model && model->getOptionsModel())
+ {
+ ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance));
+ }
}
void SendCoinsDialog::updateDisplayUnit()
{
- if(model && model->getOptionsModel())
- {
- // Update labelBalance with the current balance and the current unit
- ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->getBalance()));
- }
+ setBalance(model->getBalance(), 0, 0);
}