Browse Source

call supply every 15 min

pull/2/head
DenioD 4 years ago
parent
commit
3e79044f25
  1. 69
      src/controller.cpp
  2. 2
      src/controller.h
  3. 4
      src/datamodel.h
  4. 39
      src/mainwindow.ui

69
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<json::boolean_t>();
model->setEncryptionStatus(isEncrypted, isLocked);
});
// Get the total supply and render it with thousand decimal
zrpc->fetchSupply([=] (const json& reply) {
int supply = reply["supply"].get<json::number_integer_t>();
int zfunds = reply["zfunds"].get<json::number_integer_t>();
int total = reply["total"].get<json::number_integer_t>();;
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<json::number_integer_t>();
int zfunds = reply["zfunds"].get<json::number_integer_t>();
int total = reply["total"].get<json::number_integer_t>();;
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<QString, CAmount>* balancesMap, QList<UnspentOutput>* 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<json::number_unsigned_t>());
CAmount balZ = CAmount::fromqint64(reply["zbalance"].get<json::number_unsigned_t>());
CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get<json::number_unsigned_t>());
CAmount balSpendable = CAmount::fromqint64(reply["spendable_zbalance"].get<json::number_unsigned_t>());
model->setBalT(balT);
model->setBalZ(balZ);
model->setBalVerified(balVerified);
model->setBalSpendable(balSpendable);
// This is for the websockets
AppDataModel::getInstance()->setBalances(balT, balZ);

2
src/controller.h

@ -108,6 +108,8 @@ public:
void saveWallet(const std::function<void(json)>& cb) { zrpc->saveWallet(cb); }
void supplyUpdate();
void clearWallet(const std::function<void(json)>& cb) { zrpc->clearWallet(cb); }
void shield(const std::function<void(json)>& cb) { zrpc->shield(cb); }

4
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;
};

39
src/mainwindow.ui

@ -59,7 +59,7 @@
<item row="0" column="0" colspan="2">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_6">
<attribute name="title">
@ -666,13 +666,40 @@
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QLabel" name="label_40">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Spendable</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="balSpendable">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
@ -711,7 +738,7 @@
</item>
</layout>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="lblSyncWarning">
<property name="styleSheet">
<string notr="true">color:red;</string>
@ -724,7 +751,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="unconfirmedWarning">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
@ -743,14 +770,14 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QPushButton" name="depositHushButton">
<property name="text">
<string>Deposit Hush</string>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="9" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>

Loading…
Cancel
Save