|
7 | 7 | #include "optionsmodel.h" |
8 | 8 |
|
9 | 9 | namespace GuiTransactionsUtils { |
10 | | - void ProcessSendCoinsReturn(PWidget *parent, const WalletModel::SendCoinsReturn &sendCoinsReturn, |
11 | | - WalletModel *walletModel, const QString &msgArg, bool fPrepare) { |
12 | | - bool fAskForUnlock = false; |
13 | | - |
14 | | - QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams; |
15 | | - // Default to a warning message, override if error message is needed |
16 | | - msgParams.second = CClientUIInterface::MSG_WARNING; |
17 | 10 |
|
| 11 | + QString ProcessSendCoinsReturn(PWidget::Translator *parent, const WalletModel::SendCoinsReturn &sendCoinsReturn, |
| 12 | + WalletModel *walletModel, CClientUIInterface::MessageBoxFlags& informType, const QString &msgArg, |
| 13 | + bool fPrepare) { |
| 14 | + QString retStr; |
| 15 | + informType = CClientUIInterface::MSG_WARNING; |
18 | 16 | // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn. |
19 | 17 | // WalletModel::TransactionCommitFailed is used only in WalletModel::sendCoins() |
20 | 18 | // all others are used only in WalletModel::prepareTransaction() |
21 | 19 | switch (sendCoinsReturn.status) { |
22 | 20 | case WalletModel::InvalidAddress: |
23 | | - msgParams.first = parent->translate("The recipient address is not valid, please recheck."); |
| 21 | + retStr = parent->translate("The recipient address is not valid, please recheck."); |
24 | 22 | break; |
25 | 23 | case WalletModel::InvalidAmount: |
26 | | - msgParams.first = parent->translate("The amount to pay must be larger than 0."); |
| 24 | + retStr = parent->translate("The amount to pay must be larger than 0."); |
27 | 25 | break; |
28 | 26 | case WalletModel::AmountExceedsBalance: |
29 | | - msgParams.first = parent->translate("The amount exceeds your balance."); |
| 27 | + retStr = parent->translate("The amount exceeds your balance."); |
30 | 28 | break; |
31 | 29 | case WalletModel::AmountWithFeeExceedsBalance: |
32 | | - msgParams.first = parent->translate( |
| 30 | + retStr = parent->translate( |
33 | 31 | "The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg); |
34 | 32 | break; |
35 | 33 | case WalletModel::DuplicateAddress: |
36 | | - msgParams.first = parent->translate( |
| 34 | + retStr = parent->translate( |
37 | 35 | "Duplicate address found, can only send to each address once per send operation."); |
38 | 36 | break; |
39 | 37 | case WalletModel::TransactionCreationFailed: |
40 | | - msgParams.first = parent->translate("Transaction creation failed!"); |
41 | | - msgParams.second = CClientUIInterface::MSG_ERROR; |
| 38 | + retStr = parent->translate("Transaction creation failed!"); |
| 39 | + informType = CClientUIInterface::MSG_ERROR; |
42 | 40 | break; |
43 | 41 | case WalletModel::TransactionCommitFailed: |
44 | | - msgParams.first = parent->translate( |
| 42 | + retStr = parent->translate( |
45 | 43 | "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."); |
46 | | - msgParams.second = CClientUIInterface::MSG_ERROR; |
| 44 | + informType = CClientUIInterface::MSG_ERROR; |
47 | 45 | break; |
48 | 46 | case WalletModel::AnonymizeOnlyUnlocked: |
49 | 47 | // Unlock is only need when the coins are send |
50 | | - if (!fPrepare) |
51 | | - fAskForUnlock = true; |
52 | | - else |
53 | | - msgParams.first = parent->translate("Error: The wallet is unlocked for staking only. Fully unlock the wallet to send the transaction."); |
| 48 | + if (!fPrepare) { |
| 49 | + // Unlock wallet if it wasn't fully unlocked already |
| 50 | + walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full, false); |
| 51 | + if (walletModel->getEncryptionStatus() != WalletModel::Unlocked) { |
| 52 | + retStr = parent->translate( |
| 53 | + "Error: The wallet was unlocked for staking only. Unlock canceled."); |
| 54 | + } |
| 55 | + } else |
| 56 | + retStr = parent->translate("Error: The wallet is unlocked for staking only. Fully unlock the wallet to send the transaction."); |
54 | 57 | break; |
55 | | - |
56 | 58 | case WalletModel::InsaneFee: |
57 | | - msgParams.first = parent->translate( |
| 59 | + retStr = parent->translate( |
58 | 60 | "A fee %1 times higher than %2 per kB is considered an insanely high fee.").arg(10000).arg( |
59 | 61 | BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), |
60 | 62 | ::minRelayTxFee.GetFeePerK())); |
61 | 63 | break; |
62 | | - // included to prevent a compiler warning. |
| 64 | + // included to prevent a compiler warning. |
63 | 65 | case WalletModel::OK: |
64 | 66 | default: |
65 | | - return; |
| 67 | + return retStr; // No issue |
66 | 68 | } |
67 | 69 |
|
68 | | - // Unlock wallet if it wasn't fully unlocked already |
69 | | - if (fAskForUnlock) { |
70 | | - walletModel->requestUnlock(AskPassphraseDialog::Context::Unlock_Full, false); |
71 | | - if (walletModel->getEncryptionStatus() != WalletModel::Unlocked) { |
72 | | - msgParams.first = parent->translate( |
73 | | - "Error: The wallet was unlocked only to anonymize coins. Unlock canceled."); |
74 | | - } else { |
75 | | - // Wallet unlocked |
76 | | - return; |
77 | | - } |
78 | | - } |
| 70 | + return retStr; |
| 71 | + } |
79 | 72 |
|
80 | | - parent->emitMessage(parent->translate("Send Coins"), msgParams.first, msgParams.second, 0); |
| 73 | + void ProcessSendCoinsReturnAndInform(PWidget* parent, const WalletModel::SendCoinsReturn& sendCoinsReturn, WalletModel* walletModel, const QString& msgArg, bool fPrepare) { |
| 74 | + CClientUIInterface::MessageBoxFlags informType; |
| 75 | + QString informMsg = ProcessSendCoinsReturn(parent, sendCoinsReturn, walletModel, informType, msgArg, fPrepare); |
| 76 | + if (!informMsg.isEmpty()) parent->emitMessage(parent->translate("Send Coins"), informMsg, informType, 0); |
81 | 77 | } |
82 | 78 |
|
| 79 | + |
83 | 80 | } |
0 commit comments