mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Use WalletBalances struct in Qt
Suggested by John Newbery <john@johnnewbery.com> https://github.com/bitcoin/bitcoin/pull/10244#discussion_r177504284
This commit is contained in:
parent
56f33ca349
commit
9a61eed1fc
@ -21,6 +21,8 @@
|
||||
#define DECORATION_SIZE 54
|
||||
#define NUM_ITEMS 5
|
||||
|
||||
Q_DECLARE_METATYPE(interface::WalletBalances)
|
||||
|
||||
class TxViewDelegate : public QAbstractItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -113,16 +115,12 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
|
||||
ui(new Ui::OverviewPage),
|
||||
clientModel(0),
|
||||
walletModel(0),
|
||||
currentBalance(-1),
|
||||
currentUnconfirmedBalance(-1),
|
||||
currentImmatureBalance(-1),
|
||||
currentWatchOnlyBalance(-1),
|
||||
currentWatchUnconfBalance(-1),
|
||||
currentWatchImmatureBalance(-1),
|
||||
txdelegate(new TxViewDelegate(platformStyle, this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_balances.balance = -1;
|
||||
|
||||
// use a SingleColorIcon for the "out of sync warning" icon
|
||||
QIcon icon = platformStyle->SingleColorIcon(":/icons/warning");
|
||||
icon.addPixmap(icon.pixmap(QSize(64,64), QIcon::Normal), QIcon::Disabled); // also set the disabled icon because we are using a disabled QPushButton to work around missing HiDPI support of QLabel (https://bugreports.qt.io/browse/QTBUG-42503)
|
||||
@ -159,28 +157,23 @@ OverviewPage::~OverviewPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance)
|
||||
void OverviewPage::setBalance(const interface::WalletBalances& balances)
|
||||
{
|
||||
int unit = walletModel->getOptionsModel()->getDisplayUnit();
|
||||
currentBalance = balance;
|
||||
currentUnconfirmedBalance = unconfirmedBalance;
|
||||
currentImmatureBalance = immatureBalance;
|
||||
currentWatchOnlyBalance = watchOnlyBalance;
|
||||
currentWatchUnconfBalance = watchUnconfBalance;
|
||||
currentWatchImmatureBalance = watchImmatureBalance;
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balance + unconfirmedBalance + immatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, watchOnlyBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, watchUnconfBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, watchImmatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, false, BitcoinUnits::separatorAlways));
|
||||
m_balances = balances;
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
|
||||
|
||||
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
|
||||
// for the non-mining users
|
||||
bool showImmature = immatureBalance != 0;
|
||||
bool showWatchOnlyImmature = watchImmatureBalance != 0;
|
||||
bool showImmature = balances.immature_balance != 0;
|
||||
bool showWatchOnlyImmature = balances.immature_watch_only_balance != 0;
|
||||
|
||||
// for symmetry reasons also show immature label when the watch-only one is shown
|
||||
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
|
||||
@ -233,9 +226,8 @@ void OverviewPage::setWalletModel(WalletModel *model)
|
||||
// Keep up to date with wallet
|
||||
interface::Wallet& wallet = model->wallet();
|
||||
interface::WalletBalances balances = wallet.getBalances();
|
||||
setBalance(balances.balance, balances.unconfirmed_balance, balances.immature_balance,
|
||||
balances.watch_only_balance, balances.unconfirmed_watch_only_balance, balances.immature_watch_only_balance);
|
||||
connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)));
|
||||
setBalance(balances);
|
||||
connect(model, SIGNAL(balanceChanged(interface::WalletBalances)), this, SLOT(setBalance(interface::WalletBalances)));
|
||||
|
||||
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||
|
||||
@ -251,9 +243,9 @@ void OverviewPage::updateDisplayUnit()
|
||||
{
|
||||
if(walletModel && walletModel->getOptionsModel())
|
||||
{
|
||||
if(currentBalance != -1)
|
||||
setBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance,
|
||||
currentWatchOnlyBalance, currentWatchUnconfBalance, currentWatchImmatureBalance);
|
||||
if (m_balances.balance != -1) {
|
||||
setBalance(m_balances);
|
||||
}
|
||||
|
||||
// Update txdelegate->unit with the current unit
|
||||
txdelegate->unit = walletModel->getOptionsModel()->getDisplayUnit();
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef BITCOIN_QT_OVERVIEWPAGE_H
|
||||
#define BITCOIN_QT_OVERVIEWPAGE_H
|
||||
|
||||
#include <amount.h>
|
||||
#include <interface/wallet.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
@ -38,8 +38,7 @@ public:
|
||||
void showOutOfSyncWarning(bool fShow);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
|
||||
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
|
||||
void setBalance(const interface::WalletBalances& balances);
|
||||
|
||||
Q_SIGNALS:
|
||||
void transactionClicked(const QModelIndex &index);
|
||||
@ -49,12 +48,7 @@ private:
|
||||
Ui::OverviewPage *ui;
|
||||
ClientModel *clientModel;
|
||||
WalletModel *walletModel;
|
||||
CAmount currentBalance;
|
||||
CAmount currentUnconfirmedBalance;
|
||||
CAmount currentImmatureBalance;
|
||||
CAmount currentWatchOnlyBalance;
|
||||
CAmount currentWatchUnconfBalance;
|
||||
CAmount currentWatchImmatureBalance;
|
||||
interface::WalletBalances m_balances;
|
||||
|
||||
TxViewDelegate *txdelegate;
|
||||
std::unique_ptr<TransactionFilterProxy> filter;
|
||||
|
@ -150,9 +150,8 @@ void SendCoinsDialog::setModel(WalletModel *_model)
|
||||
}
|
||||
|
||||
interface::WalletBalances balances = _model->wallet().getBalances();
|
||||
setBalance(balances.balance, balances.unconfirmed_balance, balances.immature_balance,
|
||||
balances.watch_only_balance, balances.unconfirmed_watch_only_balance, balances.immature_watch_only_balance);
|
||||
connect(_model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)));
|
||||
setBalance(balances);
|
||||
connect(_model, SIGNAL(balanceChanged(interface::WalletBalances)), this, SLOT(setBalance(interface::WalletBalances)));
|
||||
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
|
||||
updateDisplayUnit();
|
||||
|
||||
@ -516,24 +515,17 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SendCoinsDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
|
||||
const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance)
|
||||
void SendCoinsDialog::setBalance(const interface::WalletBalances& balances)
|
||||
{
|
||||
Q_UNUSED(unconfirmedBalance);
|
||||
Q_UNUSED(immatureBalance);
|
||||
Q_UNUSED(watchBalance);
|
||||
Q_UNUSED(watchUnconfirmedBalance);
|
||||
Q_UNUSED(watchImmatureBalance);
|
||||
|
||||
if(model && model->getOptionsModel())
|
||||
{
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance));
|
||||
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balances.balance));
|
||||
}
|
||||
}
|
||||
|
||||
void SendCoinsDialog::updateDisplayUnit()
|
||||
{
|
||||
setBalance(model->wallet().getBalance(), 0, 0, 0, 0, 0);
|
||||
setBalance(model->wallet().getBalances());
|
||||
ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
||||
updateMinFeeLabel();
|
||||
updateSmartFeeLabel();
|
||||
|
@ -51,8 +51,7 @@ public Q_SLOTS:
|
||||
void accept();
|
||||
SendCoinsEntry *addEntry();
|
||||
void updateTabsAndLabels();
|
||||
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
|
||||
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
|
||||
void setBalance(const interface::WalletBalances& balances);
|
||||
|
||||
Q_SIGNALS:
|
||||
void coinsSent(const uint256& txid);
|
||||
|
@ -93,7 +93,7 @@ void WalletModel::checkBalanceChanged(const interface::WalletBalances& new_balan
|
||||
{
|
||||
if(new_balances.balanceChanged(m_cached_balances)) {
|
||||
m_cached_balances = new_balances;
|
||||
Q_EMIT balanceChanged(new_balances.balance, new_balances.unconfirmed_balance, new_balances.immature_balance, new_balances.watch_only_balance, new_balances.unconfirmed_watch_only_balance, new_balances.immature_watch_only_balance);
|
||||
Q_EMIT balanceChanged(new_balances);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,8 +237,7 @@ private:
|
||||
|
||||
Q_SIGNALS:
|
||||
// Signal that balance in wallet changed
|
||||
void balanceChanged(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
|
||||
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
|
||||
void balanceChanged(const interface::WalletBalances& balances);
|
||||
|
||||
// Encryption status of wallet changed
|
||||
void encryptionStatusChanged();
|
||||
|
Loading…
Reference in New Issue
Block a user