Skip to content

Commit 2dd6604

Browse files
committed
qml: Clear Send form after sending transaciton
1 parent 5dc69cd commit 2dd6604

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/qml/models/sendrecipient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ void SendRecipient::clear()
7575
Q_EMIT addressChanged();
7676
Q_EMIT labelChanged();
7777
Q_EMIT messageChanged();
78+
Q_EMIT amount()->amountChanged();
7879
}

src/qml/models/sendrecipientslistmodel.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,25 @@ QString SendRecipientsListModel::totalAmount() const
118118
{
119119
return BitcoinAmount::satsToBtcString(m_totalAmount);
120120
}
121+
122+
void SendRecipientsListModel::clear()
123+
{
124+
beginResetModel();
125+
for (auto* recipient : m_recipients) {
126+
delete recipient;
127+
}
128+
m_recipients.clear();
129+
m_current = 0;
130+
m_totalAmount = 0;
131+
132+
auto* recipient = new SendRecipient(this);
133+
connect(recipient->amount(), &BitcoinAmount::amountChanged,
134+
this, &SendRecipientsListModel::updateTotalAmount);
135+
m_recipients.append(recipient);
136+
endResetModel();
137+
138+
Q_EMIT countChanged();
139+
Q_EMIT totalAmountChanged();
140+
Q_EMIT currentRecipientChanged();
141+
Q_EMIT currentIndexChanged();
142+
}

src/qml/models/sendrecipientslistmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SendRecipientsListModel : public QAbstractListModel
3737
Q_INVOKABLE void next();
3838
Q_INVOKABLE void prev();
3939
Q_INVOKABLE void remove();
40+
Q_INVOKABLE void clear();
4041

4142
int currentIndex() const { return m_current + 1; }
4243
void setCurrentIndex(int row);

src/qml/models/walletqmlmodel.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ WalletQmlModel::WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObje
2626
m_wallet = std::move(wallet);
2727
m_activity_list_model = new ActivityListModel(this);
2828
m_coins_list_model = new CoinsListModel(this);
29-
m_current_recipient = new SendRecipient(this);
3029
m_send_recipients = new SendRecipientsListModel(this);
3130
}
3231

@@ -35,15 +34,13 @@ WalletQmlModel::WalletQmlModel(QObject* parent)
3534
{
3635
m_activity_list_model = new ActivityListModel(this);
3736
m_coins_list_model = new CoinsListModel(this);
38-
m_current_recipient = new SendRecipient(this);
3937
m_send_recipients = new SendRecipientsListModel(this);
4038
}
4139

4240
WalletQmlModel::~WalletQmlModel()
4341
{
4442
delete m_activity_list_model;
4543
delete m_coins_list_model;
46-
delete m_current_recipient;
4744
delete m_send_recipients;
4845
if (m_current_transaction) {
4946
delete m_current_transaction;
@@ -103,7 +100,7 @@ std::unique_ptr<interfaces::Handler> WalletQmlModel::handleTransactionChanged(Tr
103100

104101
bool WalletQmlModel::prepareTransaction()
105102
{
106-
if (!m_wallet || !m_current_recipient) {
103+
if (!m_wallet || !m_send_recipients || m_send_recipients->recipients().empty()) {
107104
return false;
108105
}
109106

src/qml/models/walletqmlmodel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class WalletQmlModel : public QObject
2727
Q_PROPERTY(QString balance READ balance NOTIFY balanceChanged)
2828
Q_PROPERTY(ActivityListModel* activityListModel READ activityListModel CONSTANT)
2929
Q_PROPERTY(CoinsListModel* coinsListModel READ coinsListModel CONSTANT)
30-
Q_PROPERTY(SendRecipient* sendRecipient READ sendRecipient CONSTANT)
3130
Q_PROPERTY(SendRecipientsListModel* recipients READ sendRecipientList CONSTANT)
3231
Q_PROPERTY(WalletQmlModelTransaction* currentTransaction READ currentTransaction NOTIFY currentTransactionChanged)
3332

@@ -40,7 +39,6 @@ class WalletQmlModel : public QObject
4039
QString balance() const;
4140
ActivityListModel* activityListModel() const { return m_activity_list_model; }
4241
CoinsListModel* coinsListModel() const { return m_coins_list_model; }
43-
SendRecipient* sendRecipient() const { return m_send_recipients->currentRecipient(); }
4442
SendRecipientsListModel* sendRecipientList() const { return m_send_recipients; }
4543
WalletQmlModelTransaction* currentTransaction() const { return m_current_transaction; }
4644
Q_INVOKABLE bool prepareTransaction();
@@ -76,7 +74,6 @@ class WalletQmlModel : public QObject
7674
ActivityListModel* m_activity_list_model{nullptr};
7775
CoinsListModel* m_coins_list_model{nullptr};
7876
SendRecipientsListModel* m_send_recipients{nullptr};
79-
SendRecipient* m_current_recipient{nullptr};
8077
WalletQmlModelTransaction* m_current_transaction{nullptr};
8178
wallet::CCoinControl m_coin_control;
8279
};

src/qml/pages/main.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ ApplicationWindow {
110110
main.pop()
111111
}
112112
onTransactionSent: {
113-
walletController.selectedWallet.sendRecipient.clear()
113+
walletController.selectedWallet.recipients.clear()
114114
main.pop()
115115
sendResult.open()
116116
}
@@ -124,7 +124,7 @@ ApplicationWindow {
124124
main.pop()
125125
}
126126
onTransactionSent: {
127-
walletController.selectedWallet.sendRecipient.clear()
127+
walletController.selectedWallet.recipients.clear()
128128
main.pop()
129129
sendResult.open()
130130
}

0 commit comments

Comments
 (0)