1
1
#include " sendcoinsdialog.h"
2
2
#include " ui_sendcoinsdialog.h"
3
3
4
- #include " walletmodel.h"
5
4
#include " bitcoinunits.h"
6
5
#include " optionsmodel.h"
7
6
#include " sendcoinsentry.h"
8
7
#include " guiutil.h"
9
8
#include " askpassphrasedialog.h"
10
9
#include " base58.h"
10
+ #include " ui_interface.h"
11
11
12
12
#include < QMessageBox>
13
13
#include < QTextDocument>
@@ -136,41 +136,9 @@ void SendCoinsDialog::on_sendButton_clicked()
136
136
// prepare transaction for getting txFee earlier
137
137
WalletModelTransaction currentTransaction (recipients);
138
138
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 ()));
174
142
175
143
if (prepareStatus.status != WalletModel::OK) {
176
144
fNewRecipientAllowed = true ;
@@ -208,19 +176,13 @@ void SendCoinsDialog::on_sendButton_clicked()
208
176
}
209
177
210
178
// 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)
213
184
{
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:
219
185
accept ();
220
- break ;
221
- case WalletModel::Aborted: // User aborted, nothing to do
222
- default :
223
- break ;
224
186
}
225
187
fNewRecipientAllowed = true ;
226
188
}
@@ -356,16 +318,16 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
356
318
const payments::PaymentDetails& details = rv.paymentRequest .getDetails ();
357
319
if (details.has_expires () && (int64)details.expires () < GetTime ())
358
320
{
359
- QMessageBox::warning ( this , strSendCoins ,
360
- tr ( " Payment request expired " ) );
321
+ emit message (strSendCoins, tr ( " Payment request expired " ) ,
322
+ CClientUIInterface::MSG_WARNING );
361
323
return false ;
362
324
}
363
325
}
364
326
else {
365
327
CBitcoinAddress address (rv.address .toStdString ());
366
328
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 );
369
331
return false ;
370
332
}
371
333
}
@@ -389,3 +351,47 @@ void SendCoinsDialog::updateDisplayUnit()
389
351
{
390
352
setBalance (model->getBalance (), 0 , 0 );
391
353
}
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