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.cpp133
1 files changed, 73 insertions, 60 deletions
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 00cea463ef..b9c5eb08d6 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -1,18 +1,22 @@
+// Copyright (c) 2011-2013 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
#include "sendcoinsdialog.h"
#include "ui_sendcoinsdialog.h"
-#include "walletmodel.h"
#include "bitcoinunits.h"
-#include "addressbookpage.h"
+#include "guiutil.h"
#include "optionsmodel.h"
#include "sendcoinsentry.h"
-#include "guiutil.h"
-#include "askpassphrasedialog.h"
+#include "walletmodel.h"
+
#include "base58.h"
+#include "ui_interface.h"
#include <QMessageBox>
-#include <QTextDocument>
#include <QScrollBar>
+#include <QTextDocument>
SendCoinsDialog::SendCoinsDialog(QWidget *parent) :
QDialog(parent),
@@ -103,7 +107,7 @@ void SendCoinsDialog::on_sendButton_clicked()
QString recipientElement;
- if (rcp.authenticatedMerchant.isEmpty())
+ if (!rcp.paymentRequest.IsInitialized()) // normal payment
{
if(rcp.label.length() > 0) // label with address
{
@@ -115,10 +119,14 @@ void SendCoinsDialog::on_sendButton_clicked()
recipientElement = tr("%1 to %2").arg(amount, address);
}
}
- else // just merchant
+ else if(!rcp.authenticatedMerchant.isEmpty()) // secure payment request
{
recipientElement = tr("%1 to %2").arg(amount, GUIUtil::HtmlEscape(rcp.authenticatedMerchant));
}
+ else // insecure payment request
+ {
+ recipientElement = tr("%1 to %2").arg(amount, address);
+ }
formatted.append(recipientElement);
}
@@ -137,41 +145,9 @@ void SendCoinsDialog::on_sendButton_clicked()
// 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, strSendCoins,
- tr("The recipient address is not valid, please recheck."));
- break;
- case WalletModel::InvalidAmount:
- QMessageBox::warning(this, strSendCoins,
- tr("The amount to pay must be larger than 0."));
- break;
- case WalletModel::AmountExceedsBalance:
- QMessageBox::warning(this, strSendCoins,
- tr("The amount exceeds your balance."));
- break;
- case WalletModel::AmountWithFeeExceedsBalance:
- QMessageBox::warning(this, strSendCoins,
- tr("The total exceeds your balance when the %1 transaction fee is included.").
- arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee())));
- break;
- case WalletModel::DuplicateAddress:
- 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, strSendCoins,
- tr("Error: Transaction creation failed!"));
- break;
- case WalletModel::TransactionCommitFailed:
- case WalletModel::OK:
- case WalletModel::Aborted: // User aborted, nothing to do
- default:
- break;
- }
+ // process prepareStatus and on error generate message shown to user
+ processSendCoinsReturn(prepareStatus,
+ BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee()));
if(prepareStatus.status != WalletModel::OK) {
fNewRecipientAllowed = true;
@@ -209,19 +185,13 @@ void SendCoinsDialog::on_sendButton_clicked()
}
// now send the prepared transaction
- WalletModel::SendCoinsReturn sendstatus = model->sendCoins(currentTransaction);
- switch(sendstatus.status)
+ WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction);
+ // process sendStatus and on error generate message shown to user
+ processSendCoinsReturn(sendStatus);
+
+ if (sendStatus.status == WalletModel::OK)
{
- 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;
}
@@ -352,22 +322,21 @@ void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
{
QString strSendCoins = tr("Send Coins");
- if (!rv.authenticatedMerchant.isEmpty()) {
+ if (rv.paymentRequest.IsInitialized()) {
// Expired payment request?
const payments::PaymentDetails& details = rv.paymentRequest.getDetails();
- if (details.has_expires() && (int64)details.expires() < GetTime())
+ if (details.has_expires() && (int64_t)details.expires() < GetTime())
{
- QMessageBox::warning(this, strSendCoins,
- tr("Payment request expired"));
+ emit message(strSendCoins, tr("Payment request expired"),
+ CClientUIInterface::MSG_WARNING);
return false;
}
}
else {
CBitcoinAddress address(rv.address.toStdString());
if (!address.IsValid()) {
- QString strAddress(address.ToString().c_str());
- QMessageBox::warning(this, strSendCoins,
- tr("Invalid payment address %1").arg(strAddress));
+ emit message(strSendCoins, tr("Invalid payment address %1").arg(rv.address),
+ CClientUIInterface::MSG_WARNING);
return false;
}
}
@@ -391,3 +360,47 @@ void SendCoinsDialog::updateDisplayUnit()
{
setBalance(model->getBalance(), 0, 0);
}
+
+void SendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg)
+{
+ QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams;
+ // Default to a warning message, override if error message is needed
+ msgParams.second = CClientUIInterface::MSG_WARNING;
+
+ // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn.
+ // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins()
+ // all others are used only in WalletModel::prepareTransaction()
+ switch(sendCoinsReturn.status)
+ {
+ case WalletModel::InvalidAddress:
+ msgParams.first = tr("The recipient address is not valid, please recheck.");
+ break;
+ case WalletModel::InvalidAmount:
+ msgParams.first = tr("The amount to pay must be larger than 0.");
+ break;
+ case WalletModel::AmountExceedsBalance:
+ msgParams.first = tr("The amount exceeds your balance.");
+ break;
+ case WalletModel::AmountWithFeeExceedsBalance:
+ msgParams.first = tr("The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg);
+ break;
+ case WalletModel::DuplicateAddress:
+ msgParams.first = tr("Duplicate address found, can only send to each address once per send operation.");
+ break;
+ case WalletModel::TransactionCreationFailed:
+ msgParams.first = tr("Transaction creation failed!");
+ msgParams.second = CClientUIInterface::MSG_ERROR;
+ break;
+ case WalletModel::TransactionCommitFailed:
+ msgParams.first = tr("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.");
+ msgParams.second = CClientUIInterface::MSG_ERROR;
+ break;
+ // OK and Aborted are included to prevent a compiler warning.
+ case WalletModel::OK:
+ case WalletModel::Aborted:
+ default:
+ return;
+ }
+
+ emit message(tr("Send Coins"), msgParams.first, msgParams.second);
+}