From 3e79044f2572e379d02ccb13cfca2dc2c239a3ec Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:04:16 +0200 Subject: [PATCH] call supply every 15 min --- src/controller.cpp | 69 ++++++++++++++++++++++++++++++---------------- src/controller.h | 2 ++ src/datamodel.h | 4 +++ src/mainwindow.ui | 39 ++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 29 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 9500e81..c2e2c23 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -32,6 +32,9 @@ Controller::Controller(MainWindow* main) balancesTableModel = new BalancesTableModel(main->ui->balancesTable); main->ui->balancesTable->setModel(balancesTableModel); + // Call the supply once + // supplyUpdate(); + // Setup transactions table model transactionsTableModel = new TxTableModel(ui->transactionsTable); main->ui->transactionsTable->setModel(transactionsTableModel); @@ -52,6 +55,13 @@ Controller::Controller(MainWindow* main) }); timer->start(Settings::updateSpeed); + // Set up to fetch supply + timer = new QTimer(main); + QObject::connect(timer, &QTimer::timeout, [=]() { + supplyUpdate(); + }); + timer->start(Settings::priceRefreshSpeed); + // Create the data model model = new DataModel(); @@ -81,6 +91,7 @@ void Controller::setConnection(Connection* c) // If we're allowed to get the Hush Price, get the prices if (Settings::getInstance()->getAllowFetchPrices()) refreshZECPrice(); + supplyUpdate(); // If we're allowed to check for updates, check for a new release if (Settings::getInstance()->getCheckForUpdates()) @@ -577,29 +588,7 @@ void Controller::getInfoThenRefresh(bool force) bool isLocked = reply["locked"].get(); model->setEncryptionStatus(isEncrypted, isLocked); }); - // Get the total supply and render it with thousand decimal - zrpc->fetchSupply([=] (const json& reply) { - int supply = reply["supply"].get(); - int zfunds = reply["zfunds"].get(); - int total = reply["total"].get();; - if ( - Settings::getInstance()->get_currency_name() == "EUR" || - Settings::getInstance()->get_currency_name() == "CHF" || - Settings::getInstance()->get_currency_name() == "RUB" - ) - { - ui->supply_taddr->setText((QLocale(QLocale::German).toString(supply)+ " Hush")); - ui->supply_zaddr->setText((QLocale(QLocale::German).toString(zfunds)+ " Hush")); - ui->supply_total->setText((QLocale(QLocale::German).toString(total)+ " Hush")); - } - else - { - ui->supply_taddr->setText("Hush " + (QLocale(QLocale::English).toString(supply))); - ui->supply_zaddr->setText("Hush " +(QLocale(QLocale::English).toString(zfunds))); - ui->supply_total->setText("Hush " +(QLocale(QLocale::English).toString(total))); - } - - }); + if ( doUpdate ) { @@ -692,6 +681,36 @@ void Controller::updateUI(bool anyUnconfirmed) ); }; +void Controller::supplyUpdate() { + + qDebug()<<"Supply"; + + // Get the total supply and render it with thousand decimal + zrpc->fetchSupply([=] (const json& reply) { + int supply = reply["supply"].get(); + int zfunds = reply["zfunds"].get(); + int total = reply["total"].get();; + if ( + Settings::getInstance()->get_currency_name() == "EUR" || + Settings::getInstance()->get_currency_name() == "CHF" || + Settings::getInstance()->get_currency_name() == "RUB" + ) + { + ui->supply_taddr->setText((QLocale(QLocale::German).toString(supply)+ " Hush")); + ui->supply_zaddr->setText((QLocale(QLocale::German).toString(zfunds)+ " Hush")); + ui->supply_total->setText((QLocale(QLocale::German).toString(total)+ " Hush")); + } + else + { + ui->supply_taddr->setText("Hush " + (QLocale(QLocale::English).toString(supply))); + ui->supply_zaddr->setText("Hush " +(QLocale(QLocale::English).toString(zfunds))); + ui->supply_total->setText("Hush " +(QLocale(QLocale::English).toString(total))); + } + + }); + +} + // Function to process reply of the listunspent and z_listunspent API calls, used below. void Controller::processUnspent(const json& reply, QMap* balancesMap, QList* unspentOutputs) { auto processFn = [=](const json& array) { @@ -727,6 +746,7 @@ void Controller::updateUIBalances() CAmount balT = getModel()->getBalT(); CAmount balZ = getModel()->getBalZ(); CAmount balVerified = getModel()->getBalVerified(); + CAmount balSpendable = getModel()->getBalSpendable(); // Reduce the BalanceZ by the pending outgoing amount. We're adding // here because totalPending is already negative for outgoing txns. @@ -743,6 +763,7 @@ void Controller::updateUIBalances() ui->balSheilded->setText(balZ.toDecimalhushString()); ui->balVerified->setText(balVerified.toDecimalhushString()); ui->balTransparent->setText(balT.toDecimalhushString()); + ui->balSpendable->setText(balSpendable.toDecimalhushString()); ui->balTotal->setText(balTotal.toDecimalhushString()); if (Settings::getInstance()->get_currency_name() == "USD") @@ -879,10 +900,12 @@ void Controller::refreshBalances() CAmount balT = CAmount::fromqint64(reply["tbalance"].get()); CAmount balZ = CAmount::fromqint64(reply["zbalance"].get()); CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get()); + CAmount balSpendable = CAmount::fromqint64(reply["spendable_zbalance"].get()); model->setBalT(balT); model->setBalZ(balZ); model->setBalVerified(balVerified); + model->setBalSpendable(balSpendable); // This is for the websockets AppDataModel::getInstance()->setBalances(balT, balZ); diff --git a/src/controller.h b/src/controller.h index a1d0ac4..88c0579 100644 --- a/src/controller.h +++ b/src/controller.h @@ -108,6 +108,8 @@ public: void saveWallet(const std::function& cb) { zrpc->saveWallet(cb); } + void supplyUpdate(); + void clearWallet(const std::function& cb) { zrpc->clearWallet(cb); } void shield(const std::function& cb) { zrpc->shield(cb); } diff --git a/src/datamodel.h b/src/datamodel.h index 4d2ac06..afcaf59 100644 --- a/src/datamodel.h +++ b/src/datamodel.h @@ -49,6 +49,9 @@ public: CAmount getBalVerified() { QReadLocker locker(lock); return balVerified; } void setBalVerified(CAmount a) { QReadLocker locker(lock); this->balVerified = a; } + CAmount getBalSpendable() { QReadLocker locker(lock); return balSpendable; } + void setBalSpendable(CAmount a) { QReadLocker locker(lock); this->balSpendable = a; } + CAmount getTotalPending() { QReadLocker locker(lock); return totalPending; } void setTotalPending(CAmount a) { QReadLocker locker(lock); this->totalPending = a; } @@ -72,6 +75,7 @@ private: CAmount balT; CAmount balZ; CAmount balVerified; + CAmount balSpendable; QReadWriteLock* lock; }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 74543b6..52520c0 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -59,7 +59,7 @@ - 0 + 1 @@ -666,13 +666,40 @@ + + + + + + 0 + 0 + + + + Spendable + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + Qt::Horizontal - + @@ -711,7 +738,7 @@ - + color:red; @@ -724,7 +751,7 @@ - + @@ -743,14 +770,14 @@ - + Deposit Hush - + Qt::Vertical