Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(qt): Governance Tab should respect selected units and settings #6403

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/qt/governancelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <netbase.h>
#include <qt/clientmodel.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>

#include <univalue.h>

Expand Down Expand Up @@ -135,8 +136,10 @@ QVariant ProposalModel::data(const QModelIndex& index, int role) const
return proposal->startDate().date();
case Column::END_DATE:
return proposal->endDate().date();
case Column::PAYMENT_AMOUNT:
return proposal->paymentAmount();
case Column::PAYMENT_AMOUNT: {
return BitcoinUnits::floorWithUnit(m_display_unit, proposal->paymentAmount() * COIN, false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I just noticed that proposal->paymentAmount() returns float here.

str_amounts is assigned as string ValueFromAmount(payment.nAmount)) which doesn't lose precision, but conversion back through float and multiplying to COIN can potentionallly add a strange 0.00000002 at the end, I think.

Is it possible to avoid conversion to float here?

        if (UniValue amountValue = find_value(prop_data, "payment_amount"); amountValue.isNum()) {
            m_paymentAmount = amountValue.get_real(); // <----- here
        }

Copy link
Author

@UdjinM6 UdjinM6 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! We should be using double here. Will fix in a follow-up PR.

EDIT: #6404

BitcoinUnits::SeparatorStyle::ALWAYS);
}
case Column::IS_ACTIVE:
return proposal->isActive() ? tr("Yes") : tr("No");
case Column::VOTING_STATUS:
Expand Down Expand Up @@ -283,6 +286,8 @@ const Proposal* ProposalModel::getProposalAt(const QModelIndex& index) const
return m_data[index.row()];
}

void ProposalModel::setDisplayUnit(int display_unit) { this->m_display_unit = display_unit; }

//
// Governance Tab main widget.
//
Expand Down Expand Up @@ -340,6 +345,17 @@ void GovernanceList::setClientModel(ClientModel* model)
{
this->clientModel = model;
updateProposalList();
if (model != nullptr) {
connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &GovernanceList::updateDisplayUnit);
}
}

void GovernanceList::updateDisplayUnit()
{
if (this->clientModel) {
proposalModel->setDisplayUnit(this->clientModel->getOptionsModel()->getDisplayUnit());
ui->govTableView->update();
}
}

void GovernanceList::updateProposalList()
Expand Down
5 changes: 5 additions & 0 deletions src/qt/governancelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <governance/object.h>
#include <primitives/transaction.h>
#include <qt/bitcoinunits.h>
#include <sync.h>
#include <util/system.h>

Expand Down Expand Up @@ -48,6 +49,7 @@ class GovernanceList : public QWidget
QTimer* timer;

private Q_SLOTS:
void updateDisplayUnit();
void updateProposalList();
void updateProposalCount() const;
void showProposalContextMenu(const QPoint& pos);
Expand Down Expand Up @@ -92,6 +94,7 @@ class ProposalModel : public QAbstractTableModel
private:
QList<const Proposal*> m_data;
int nAbsVoteReq = 0;
int m_display_unit{BitcoinUnits::DASH};

public:
explicit ProposalModel(QObject* parent = nullptr) :
Expand Down Expand Up @@ -119,6 +122,8 @@ class ProposalModel : public QAbstractTableModel
void setVotingParams(int nAbsVoteReq);

const Proposal* getProposalAt(const QModelIndex& index) const;

void setDisplayUnit(int display_unit);
};

#endif // BITCOIN_QT_GOVERNANCELIST_H
Loading