11#include " sendcoinsdialog.h"
22#include " ui_sendcoinsdialog.h"
33
4- #include " walletmodel.h"
54#include " bitcoinunits.h"
65#include " optionsmodel.h"
76#include " sendcoinsentry.h"
87#include " guiutil.h"
98#include " askpassphrasedialog.h"
109#include " base58.h"
10+ #include " ui_interface.h"
1111
1212#include < QMessageBox>
1313#include < QTextDocument>
@@ -136,41 +136,9 @@ void SendCoinsDialog::on_sendButton_clicked()
136136 // prepare transaction for getting txFee earlier
137137 WalletModelTransaction currentTransaction (recipients);
138138 WalletModel::SendCoinsReturn prepareStatus = model->prepareTransaction (currentTransaction);
139-
140- QString strSendCoins = tr (" Send Coins" );
141- switch (prepareStatus.status )
142- {
143- case WalletModel::InvalidAddress:
144- QMessageBox::warning (this , strSendCoins,
145- tr (" The recipient address is not valid, please recheck." ));
146- break ;
147- case WalletModel::InvalidAmount:
148- QMessageBox::warning (this , strSendCoins,
149- tr (" The amount to pay must be larger than 0." ));
150- break ;
151- case WalletModel::AmountExceedsBalance:
152- QMessageBox::warning (this , strSendCoins,
153- tr (" The amount exceeds your balance." ));
154- break ;
155- case WalletModel::AmountWithFeeExceedsBalance:
156- QMessageBox::warning (this , strSendCoins,
157- tr (" The total exceeds your balance when the %1 transaction fee is included." ).
158- arg (BitcoinUnits::formatWithUnit (model->getOptionsModel ()->getDisplayUnit (), currentTransaction.getTransactionFee ())));
159- break ;
160- case WalletModel::DuplicateAddress:
161- QMessageBox::warning (this , strSendCoins,
162- tr (" Duplicate address found, can only send to each address once per send operation." ));
163- break ;
164- case WalletModel::TransactionCreationFailed:
165- QMessageBox::warning (this , strSendCoins,
166- tr (" Error: Transaction creation failed!" ));
167- break ;
168- case WalletModel::TransactionCommitFailed:
169- case WalletModel::OK:
170- case WalletModel::Aborted: // User aborted, nothing to do
171- default :
172- break ;
173- }
139+ // process prepareStatus and on error generate message shown to user
140+ processSendCoinsReturn (prepareStatus,
141+ BitcoinUnits::formatWithUnit (model->getOptionsModel ()->getDisplayUnit (), currentTransaction.getTransactionFee ()));
174142
175143 if (prepareStatus.status != WalletModel::OK) {
176144 fNewRecipientAllowed = true ;
@@ -208,19 +176,13 @@ void SendCoinsDialog::on_sendButton_clicked()
208176 }
209177
210178 // now send the prepared transaction
211- WalletModel::SendCoinsReturn sendstatus = model->sendCoins (currentTransaction);
212- switch (sendstatus.status )
179+ WalletModel::SendCoinsReturn sendStatus = model->sendCoins (currentTransaction);
180+ // process sendStatus and on error generate message shown to user
181+ processSendCoinsReturn (sendStatus);
182+
183+ if (sendStatus.status == WalletModel::OK)
213184 {
214- case WalletModel::TransactionCommitFailed:
215- QMessageBox::warning (this , strSendCoins,
216- 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." ));
217- break ;
218- case WalletModel::OK:
219185 accept ();
220- break ;
221- case WalletModel::Aborted: // User aborted, nothing to do
222- default :
223- break ;
224186 }
225187 fNewRecipientAllowed = true ;
226188}
@@ -356,16 +318,16 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
356318 const payments::PaymentDetails& details = rv.paymentRequest .getDetails ();
357319 if (details.has_expires () && (int64)details.expires () < GetTime ())
358320 {
359- QMessageBox::warning ( this , strSendCoins ,
360- tr ( " Payment request expired " ) );
321+ emit message (strSendCoins, tr ( " Payment request expired " ) ,
322+ CClientUIInterface::MSG_WARNING );
361323 return false ;
362324 }
363325 }
364326 else {
365327 CBitcoinAddress address (rv.address .toStdString ());
366328 if (!address.IsValid ()) {
367- QMessageBox::warning ( this , strSendCoins ,
368- tr ( " Invalid payment address %1 " ). arg (rv. address ) );
329+ emit message (strSendCoins, tr ( " Invalid payment address %1 " ). arg (rv. address ) ,
330+ CClientUIInterface::MSG_WARNING );
369331 return false ;
370332 }
371333 }
@@ -389,3 +351,47 @@ void SendCoinsDialog::updateDisplayUnit()
389351{
390352 setBalance (model->getBalance (), 0 , 0 );
391353}
354+
355+ void SendCoinsDialog::processSendCoinsReturn (const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg)
356+ {
357+ QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams;
358+ // Default to a warning message, override if error message is needed
359+ msgParams.second = CClientUIInterface::MSG_WARNING;
360+
361+ // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn.
362+ // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins()
363+ // all others are used only in WalletModel::prepareTransaction()
364+ switch (sendCoinsReturn.status )
365+ {
366+ case WalletModel::InvalidAddress:
367+ msgParams.first = tr (" The recipient address is not valid, please recheck." );
368+ break ;
369+ case WalletModel::InvalidAmount:
370+ msgParams.first = tr (" The amount to pay must be larger than 0." );
371+ break ;
372+ case WalletModel::AmountExceedsBalance:
373+ msgParams.first = tr (" The amount exceeds your balance." );
374+ break ;
375+ case WalletModel::AmountWithFeeExceedsBalance:
376+ msgParams.first = tr (" The total exceeds your balance when the %1 transaction fee is included." ).arg (msgArg);
377+ break ;
378+ case WalletModel::DuplicateAddress:
379+ msgParams.first = tr (" Duplicate address found, can only send to each address once per send operation." );
380+ break ;
381+ case WalletModel::TransactionCreationFailed:
382+ msgParams.first = tr (" Transaction creation failed!" );
383+ msgParams.second = CClientUIInterface::MSG_ERROR;
384+ break ;
385+ case WalletModel::TransactionCommitFailed:
386+ 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." );
387+ msgParams.second = CClientUIInterface::MSG_ERROR;
388+ break ;
389+ // OK and Aborted are included to prevent a compiler warning.
390+ case WalletModel::OK:
391+ case WalletModel::Aborted:
392+ default :
393+ return ;
394+ }
395+
396+ emit message (tr (" Send Coins" ), msgParams.first , msgParams.second );
397+ }
0 commit comments