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.cpp113
1 files changed, 75 insertions, 38 deletions
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 9086f6614e..809eff9c27 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,31 @@ void SendCoinsDialog::on_sendButton_clicked()
QStringList formatted;
foreach(const SendCoinsRecipient &rcp, recipients)
{
- QString amount = BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount);
+ QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
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));
+ 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
{
-#if QT_VERSION < 0x050000
- QString merchant = Qt::escape(rcp.authenticatedMerchant);
-#else
- QString merchant = rcp.authenticatedMerchant.toHtmlEscaped();
-#endif
+ QString merchant = GUIUtil::HtmlEscape(rcp.authenticatedMerchant);
formatted.append(tr("<b>%1</b> to %2").arg(amount, merchant));
}
}
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,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"),
@@ -158,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(BitcoinUnits::BTC, sendstatus.fee)),
+ arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())),
QMessageBox::Ok, QMessageBox::Ok);
break;
case WalletModel::DuplicateAddress:
@@ -171,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."),
@@ -181,6 +220,8 @@ void SendCoinsDialog::on_sendButton_clicked()
case WalletModel::OK:
accept();
break;
+ default:
+ break;
}
fNewRecipientAllowed = true;
}
@@ -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);
}