PIVX Core  5.6.99
P2P Digital Currency
guitransactionsutils.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2022 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "guitransactionsutils.h"
6 
7 #include "bitcoinunits.h"
8 #include "optionsmodel.h"
9 
11 
12  QString ProcessSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, WalletModel *walletModel,
13  CClientUIInterface::MessageBoxFlags& informType, const QString &msgArg,
14  bool fPrepare)
15  {
16  QString retStr;
18  // This comment is specific to SendCoinsDialog usage of WalletModel::SendCoinsReturn.
19  // WalletModel::TransactionCheckFailed and WalletModel::TransactionCommitFailed
20  // are used only in WalletModel::sendCoins(). All others are used only in WalletModel::prepareTransaction()
21  switch (sendCoinsReturn.status) {
23  retStr = QObject::tr("The recipient address is not valid, please recheck.");
24  break;
26  retStr = QObject::tr("The amount to pay must be larger than 0.");
27  break;
29  retStr = QObject::tr("The amount to pay exceeds the available balance.");
30  break;
32  retStr = QObject::tr(
33  "The total amount to pay exceeds the available balance when the %1 transaction fee is included.").arg(msgArg);
34  break;
36  retStr = QObject::tr(
37  "Duplicate address found, can only send to each address once per send operation.");
38  break;
40  informType = CClientUIInterface::MSG_ERROR;
41  break;
43  retStr = QObject::tr("The transaction is not valid!");
44  informType = CClientUIInterface::MSG_ERROR;
45  break;
47  retStr = QString::fromStdString(sendCoinsReturn.commitRes.ToString());
48  informType = CClientUIInterface::MSG_ERROR;
49  break;
51  // Unlock is only need when the coins are send
52  if (!fPrepare) {
53  // Unlock wallet if it wasn't fully unlocked already
54  WalletModel::UnlockContext ctx(walletModel->requestUnlock());
55  if (!ctx.isValid()) {
56  retStr = QObject::tr(
57  "Error: The wallet was unlocked for staking only. Unlock canceled.");
58  }
59  } else
60  retStr = QObject::tr("Error: The wallet is unlocked for staking only. Fully unlock the wallet to send the transaction.");
61  break;
63  retStr = QObject::tr(
64  "A fee %1 times higher than %2 per kB is considered an insanely high fee.").arg(10000).arg(
67  break;
68  // included to prevent a compiler warning.
69  case WalletModel::OK:
70  default:
71  return retStr; // No issue
72  }
73 
74  return retStr;
75  }
76 
77  void ProcessSendCoinsReturnAndInform(PWidget* parent, const WalletModel::SendCoinsReturn& sendCoinsReturn, WalletModel* walletModel, const QString& msgArg, bool fPrepare)
78  {
80  QString informMsg = ProcessSendCoinsReturn(sendCoinsReturn, walletModel, informType, msgArg, fPrepare);
81  if (!informMsg.isEmpty()) parent->emitMessage(QObject::tr("Send Coins"), informMsg, informType, nullptr);
82  }
83 
84 }
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
MessageBoxFlags
Flags for CClientUIInterface::ThreadSafeMessageBox.
Definition: guiinterface.h:35
CAmount GetFeePerK() const
Definition: feerate.h:29
int getDisplayUnit()
Definition: optionsmodel.h:74
void emitMessage(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Definition: pwidget.cpp:67
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109
OptionsModel * getOptionsModel()
UnlockContext requestUnlock()
@ StakingOnlyUnlocked
Definition: walletmodel.h:128
@ AmountWithFeeExceedsBalance
Definition: walletmodel.h:123
@ TransactionCheckFailed
Definition: walletmodel.h:126
@ TransactionCreationFailed
Definition: walletmodel.h:125
@ AmountExceedsBalance
Definition: walletmodel.h:122
@ TransactionCommitFailed
Definition: walletmodel.h:127
std::string ToString() const
Definition: wallet.cpp:3489
void ProcessSendCoinsReturnAndInform(PWidget *parent, const WalletModel::SendCoinsReturn &sendCoinsReturn, WalletModel *walletModel, const QString &msgArg, bool fPrepare)
QString ProcessSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, WalletModel *walletModel, CClientUIInterface::MessageBoxFlags &informType, const QString &msgArg, bool fPrepare)
CWallet::CommitResult commitRes
Definition: walletmodel.h:200
CFeeRate minRelayTxFee
Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creati...
Definition: validation.cpp:108