sendcoinsdialog.h raw
1 // Copyright (c) 2011-2022 The Limenka 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 #ifndef LIMENKA_QT_SENDCOINSDIALOG_H
6 #define LIMENKA_QT_SENDCOINSDIALOG_H
7
8 #include <qt/clientmodel.h>
9 #include <qt/walletmodel.h>
10
11 #include <QDialog>
12 #include <QMessageBox>
13 #include <QString>
14 #include <QTimer>
15
16 class PlatformStyle;
17 class SendCoinsEntry;
18 class SendCoinsRecipient;
19 enum class SynchronizationState;
20 namespace wallet {
21 class CCoinControl;
22 } // namespace wallet
23
24 namespace Ui {
25 class SendCoinsDialog;
26 }
27
28 QT_BEGIN_NAMESPACE
29 class QUrl;
30 QT_END_NAMESPACE
31
32 /** Dialog for sending limenkas */
33 class SendCoinsDialog : public QDialog
34 {
35 Q_OBJECT
36
37 public:
38 explicit SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent = nullptr);
39 ~SendCoinsDialog();
40
41 void setClientModel(ClientModel *clientModel);
42 void setModel(WalletModel *model);
43
44 /** Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907).
45 */
46 QWidget *setupTabChain(QWidget *prev);
47
48 void setAddress(const QString &address);
49 void pasteEntry(const SendCoinsRecipient &rv);
50 bool handlePaymentRequest(const SendCoinsRecipient &recipient);
51
52 // Only used for testing-purposes
53 wallet::CCoinControl* getCoinControl() { return m_coin_control.get(); }
54
55 public Q_SLOTS:
56 void clear();
57 void reject() override;
58 void accept() override;
59 SendCoinsEntry *addEntry();
60 void updateTabsAndLabels();
61 void setBalance(const interfaces::WalletBalances& balances);
62
63 Q_SIGNALS:
64 void coinsSent(const uint256& txid);
65
66 private:
67 Ui::SendCoinsDialog *ui;
68 ClientModel* clientModel{nullptr};
69 WalletModel* model{nullptr};
70 std::unique_ptr<wallet::CCoinControl> m_coin_control;
71 std::unique_ptr<WalletModelTransaction> m_current_transaction;
72 bool fNewRecipientAllowed{true};
73 bool fFeeMinimized{true};
74 const PlatformStyle *platformStyle;
75
76 // Copy PSBT to clipboard and offer to save it.
77 void presentPSBT(PartiallySignedTransaction& psbt);
78 // Process WalletModel::SendCoinsReturn and generate a pair consisting
79 // of a message and message flags for use in Q_EMIT message().
80 // Additional parameter msgArg can be used via .arg(msgArg).
81 void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString());
82 void minimizeFeeSection(bool fMinimize);
83 // Format confirmation message
84 bool PrepareSendText(QString& question_string, QString& informative_text, QString& detailed_text);
85 /* Sign PSBT using external signer.
86 *
87 * @param[in,out] psbtx the PSBT to sign
88 * @param[in,out] mtx needed to attempt to finalize
89 * @param[in,out] complete whether the PSBT is complete (a successfully signed multisig transaction may not be complete)
90 *
91 * @returns false if any failure occurred, which may include the user rejection of a transaction on the device.
92 */
93 bool signWithExternalSigner(PartiallySignedTransaction& psbt, CMutableTransaction& mtx, bool& complete);
94 void updateFeeMinimizedLabel();
95 void updateCoinControlState();
96
97 private Q_SLOTS:
98 void sendButtonClicked(bool checked);
99 void on_buttonChooseFee_clicked();
100 void on_buttonMinimizeFee_clicked();
101 void removeEntry(SendCoinsEntry* entry);
102 void useAvailableBalance(SendCoinsEntry* entry);
103 void refreshBalance();
104 void coinControlFeatureChanged(bool);
105 void coinControlButtonClicked();
106 #if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
107 void coinControlChangeChecked(Qt::CheckState);
108 #else
109 void coinControlChangeChecked(int);
110 #endif
111 void coinControlChangeEdited(const QString &);
112 void coinControlUpdateLabels();
113 void coinControlClipboardQuantity();
114 void coinControlClipboardAmount();
115 void coinControlClipboardFee();
116 void coinControlClipboardAfterFee();
117 void coinControlClipboardBytes();
118 void coinControlClipboardChange();
119 void updateFeeSectionControls();
120 void updateNumberOfBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state);
121 void updateSmartFeeLabel();
122
123 Q_SIGNALS:
124 // Fired when a message should be reported to the user
125 void message(const QString &title, const QString &message, unsigned int style);
126 };
127
128
129 #define SEND_CONFIRM_DELAY 3
130 #define ADDRESS_REUSE_OVERRIDE_DELAY 10
131
132 class SendConfirmationDialog : public QMessageBox
133 {
134 Q_OBJECT
135
136 public:
137 bool m_delete_on_close{false};
138 QString confirmButtonText{tr("Send")};
139 QMessageBox::StandardButton m_yes_button{QMessageBox::Yes};
140 QMessageBox::StandardButton m_cancel_button{QMessageBox::Cancel};
141
142 SendConfirmationDialog(const QString& title, const QString& text, const QString& informative_text = "", const QString& detailed_text = "", int secDelay = SEND_CONFIRM_DELAY, bool enable_send = true, bool always_show_unsigned = true, QWidget* parent = nullptr);
143 /* Returns QMessageBox::Cancel, QMessageBox::Yes when "Send" is
144 clicked and QMessageBox::Save when "Create Unsigned" is clicked. */
145 int exec() override;
146
147 private Q_SLOTS:
148 void countDown();
149 void updateButtons();
150
151 private:
152 QAbstractButton *yesButton;
153 QAbstractButton *m_psbt_button;
154 QTimer countDownTimer;
155 int secDelay;
156 bool m_enable_save;
157 bool m_enable_send;
158 QString m_psbt_button_text{tr("Create Unsigned")};
159 };
160
161 #endif // LIMENKA_QT_SENDCOINSDIALOG_H
162