Skip to content

Commit 6928080

Browse files
committed
[GUI][Model] * TransactionRecord implementing isAnyColdStakingType to know if the tx is a cold staking tx in any way.
* txArrived signal now including the isAnyColdStakingType flag to prevent reiterative calls (and thereby cs_wallet locks in the UI thread) when the information was already cached.
1 parent 75968f9 commit 6928080

11 files changed

+43
-14
lines changed

src/qt/pivx/coldstakingmodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ ColdStakingModel::ColdStakingModel(WalletModel* _model,
1717

1818
void ColdStakingModel::updateCSList() {
1919
refresh();
20-
emit dataChanged(index(0, 0, QModelIndex()), index(rowCount(), COLUMN_COUNT, QModelIndex()) );
20+
QMetaObject::invokeMethod(this, "emitDataSetChanged", Qt::QueuedConnection);
21+
}
22+
23+
void ColdStakingModel::emitDataSetChanged() {
24+
emit dataChanged(index(0, 0, QModelIndex()), index(cachedDelegations.size(), COLUMN_COUNT, QModelIndex()) );
2125
}
2226

2327
void ColdStakingModel::refresh() {
@@ -40,7 +44,7 @@ void ColdStakingModel::refresh() {
4044
continue;
4145

4246
// it's spendable only when this wallet has the keys to spend it, a.k.a is the owner
43-
delegation.isSpendable = pwalletMain->IsMine(out) & ISMINE_SPENDABLE_DELEGATED;
47+
delegation.isSpendable = utxo.fSpendable;
4448
delegation.cachedTotalAmount += out.nValue;
4549
delegation.delegatedUtxo.insert(txId, utxo.i);
4650

src/qt/pivx/coldstakingmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class ColdStakingModel : public QAbstractTableModel
7070

7171
void refresh();
7272

73+
public slots:
74+
void emitDataSetChanged();
7375

7476
private:
7577
WalletModel* model = nullptr;

src/qt/pivx/coldstakingwidget.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void ColdStakingWidget::loadWalletModel(){
228228

229229
}
230230

231-
void ColdStakingWidget::onTxArrived(const QString& hash) {
232-
if (walletModel->isDelegatedToOrFromMe(hash) || walletModel->isP2CSSpend(hash)) {
231+
void ColdStakingWidget::onTxArrived(const QString& hash, const bool& isCoinStake, const bool& isCSAnyType) {
232+
if (isCSAnyType) {
233233
tryRefreshDelegations();
234234
}
235235
}
@@ -328,7 +328,7 @@ void ColdStakingWidget::onContactsClicked(){
328328
}
329329

330330
if (isContactOwnerSelected) {
331-
menuContacts->setWalletModel(walletModel, AddressTableModel::Send);
331+
menuContacts->setWalletModel(walletModel, AddressTableModel::Receive);
332332
} else {
333333
menuContacts->setWalletModel(walletModel, AddressTableModel::Delegators);
334334
}
@@ -344,6 +344,11 @@ void ColdStakingWidget::onDelegateSelected(bool delegate){
344344
if (menu && menu->isVisible()) {
345345
menu->hide();
346346
}
347+
348+
if (menuAddresses && menuAddresses->isVisible()) {
349+
menuAddresses->hide();
350+
}
351+
347352
if(delegate){
348353
ui->btnCoinControl->setVisible(true);
349354
ui->containerSend->setVisible(true);
@@ -560,7 +565,6 @@ void ColdStakingWidget::handleAddressClicked(const QModelIndex &rIndex) {
560565
pos.setX(pos.x() - (DECORATION_SIZE * 2));
561566
pos.setY(pos.y() + (DECORATION_SIZE * 2));
562567

563-
bool adjustSize = false;
564568
if(!this->menu){
565569
this->menu = new TooltipMenu(window, this);
566570
this->menu->setEditBtnText(tr("Stake"));
@@ -571,7 +575,6 @@ void ColdStakingWidget::handleAddressClicked(const QModelIndex &rIndex) {
571575
this->menu->setMinimumHeight(157);
572576
this->menu->setFixedHeight(157);
573577
this->menu->setMinimumWidth(125);
574-
adjustSize = true;
575578
connect(this->menu, &TooltipMenu::message, this, &AddressesWidget::message);
576579
connect(this->menu, SIGNAL(onEditClicked()), this, SLOT(onEditClicked()));
577580
connect(this->menu, SIGNAL(onDeleteClicked()), this, SLOT(onDeleteClicked()));
@@ -588,6 +591,7 @@ void ColdStakingWidget::handleAddressClicked(const QModelIndex &rIndex) {
588591
Qt::DisplayRole).toBool();
589592
this->menu->setDeleteBtnVisible(isWhitelisted);
590593
this->menu->setEditBtnVisible(!isWhitelisted);
594+
this->menu->setCopyBtnVisible(true);
591595
this->menu->setMinimumHeight(157);
592596
} else {
593597
// owner side
@@ -596,7 +600,8 @@ void ColdStakingWidget::handleAddressClicked(const QModelIndex &rIndex) {
596600
this->menu->setCopyBtnVisible(false);
597601
this->menu->setMinimumHeight(60);
598602
}
599-
if (adjustSize) this->menu->adjustSize();
603+
604+
this->menu->adjustSize();
600605

601606
menu->move(pos);
602607
menu->show();

src/qt/pivx/coldstakingwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private slots:
6767
void onCopyOwnerClicked();
6868
void onAddressCopyClicked();
6969
void onAddressEditClicked();
70-
void onTxArrived(const QString& hash);
70+
void onTxArrived(const QString& hash, const bool& isCoinStake, const bool& isCSAnyType);
7171
void onContactsClicked(bool ownerAdd);
7272
void clearAll();
7373
void onLabelClicked();

src/qt/pivx/dashboardwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void DashboardWidget::loadWalletModel(){
239239
updateDisplayUnit();
240240
}
241241

242-
void DashboardWidget::onTxArrived(const QString& hash, const bool& isCoinStake) {
242+
void DashboardWidget::onTxArrived(const QString& hash, const bool& isCoinStake, const bool& isCSAnyType) {
243243
showList();
244244
#ifdef USE_QTCHARTS
245245
if (isCoinStake) {

src/qt/pivx/dashboardwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private slots:
122122
void onSortTypeChanged(const QString& value);
123123
void updateDisplayUnit();
124124
void showList();
125-
void onTxArrived(const QString& hash, const bool& isCoinStake);
125+
void onTxArrived(const QString& hash, const bool& isCoinStake, const bool& isCSAnyType);
126126

127127
#ifdef USE_QTCHARTS
128128
void windowResizeEvent(QResizeEvent *event);

src/qt/pivx/forms/coldstakingwidget.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,14 @@
751751
</widget>
752752
</item>
753753
<item>
754-
<widget class="QListView" name="listViewStakingAddress"/>
754+
<widget class="QListView" name="listViewStakingAddress">
755+
<property name="enabled">
756+
<bool>true</bool>
757+
</property>
758+
<property name="mouseTracking">
759+
<bool>true</bool>
760+
</property>
761+
</widget>
755762
</item>
756763
</layout>
757764
</widget>

src/qt/transactionrecord.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ bool TransactionRecord::isCoinStake() const
537537
return (type == TransactionRecord::StakeMint || type == TransactionRecord::Generated || type == TransactionRecord::StakeZPIV);
538538
}
539539

540+
bool TransactionRecord::isAnyColdStakingType() const
541+
{
542+
return (type == TransactionRecord::P2CSDelegation || type == TransactionRecord::P2CSDelegationSent
543+
|| type == TransactionRecord::StakeDelegated || type == TransactionRecord::StakeHot
544+
|| type == TransactionRecord::P2CSUnlockOwner || type == TransactionRecord::P2CSUnlockStaker);
545+
}
546+
540547
bool TransactionRecord::isNull() const
541548
{
542549
return hash.IsNull() || size == 0;

src/qt/transactionrecord.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class TransactionRecord
173173
*/
174174
bool isCoinStake() const;
175175

176+
/** Return true if the tx is a any cold staking type tx.
177+
*/
178+
bool isAnyColdStakingType() const;
179+
176180
/** Return true if the tx hash is null and/or if the size is 0
177181
*/
178182
bool isNull() const;

src/qt/transactiontablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void TransactionTableModel::updateTransaction(const QString& hash, int status, b
321321
priv->updateWallet(updated, status, showTransaction, rec);
322322

323323
if (!rec.isNull())
324-
emit txArrived(hash, rec.isCoinStake());
324+
emit txArrived(hash, rec.isCoinStake(), rec.isAnyColdStakingType());
325325
}
326326

327327
void TransactionTableModel::updateConfirmations()

0 commit comments

Comments
 (0)