Refresh logic
This commit is contained in:
@@ -137,15 +137,13 @@ void Controller::refresh(bool force) {
|
|||||||
getInfoThenRefresh(force);
|
getInfoThenRefresh(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::getInfoThenRefresh(bool force) {
|
void Controller::getInfoThenRefresh(bool doUpdate) {
|
||||||
if (!zrpc->haveConnection())
|
if (!zrpc->haveConnection())
|
||||||
return noConnection();
|
return noConnection();
|
||||||
|
|
||||||
static bool prevCallSucceeded = false;
|
static bool prevCallSucceeded = false;
|
||||||
|
|
||||||
zrpc->fetchInfo([=] (const json& reply) {
|
zrpc->fetchInfo([=] (const json& reply) {
|
||||||
qDebug() << "Info updated";
|
|
||||||
|
|
||||||
prevCallSucceeded = true;
|
prevCallSucceeded = true;
|
||||||
|
|
||||||
// Testnet?
|
// Testnet?
|
||||||
@@ -159,10 +157,12 @@ void Controller::getInfoThenRefresh(bool force) {
|
|||||||
if (!Settings::getInstance()->isTestnet())
|
if (!Settings::getInstance()->isTestnet())
|
||||||
main->disableRecurring();
|
main->disableRecurring();
|
||||||
|
|
||||||
static int lastBlock = 0;
|
|
||||||
int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
|
int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
|
||||||
|
bool doUpdate = doUpdate || (model->getLatestBlock() != curBlock);
|
||||||
model->setLatestBlock(curBlock);
|
model->setLatestBlock(curBlock);
|
||||||
|
|
||||||
|
qDebug() << "Refreshing. Full update: " << doUpdate;
|
||||||
|
|
||||||
// Connected, so display checkmark.
|
// Connected, so display checkmark.
|
||||||
auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump());
|
auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump());
|
||||||
QIcon i(":/icons/res/connected.gif");
|
QIcon i(":/icons/res/connected.gif");
|
||||||
@@ -178,10 +178,8 @@ void Controller::getInfoThenRefresh(bool force) {
|
|||||||
// See if recurring payments needs anything
|
// See if recurring payments needs anything
|
||||||
Recurring::getInstance()->processPending(main);
|
Recurring::getInstance()->processPending(main);
|
||||||
|
|
||||||
if ( force || (curBlock != lastBlock) ) {
|
if ( doUpdate ) {
|
||||||
// Something changed, so refresh everything.
|
// Something changed, so refresh everything.
|
||||||
lastBlock = curBlock;
|
|
||||||
|
|
||||||
refreshBalances();
|
refreshBalances();
|
||||||
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
|
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
|
||||||
refreshTransactions();
|
refreshTransactions();
|
||||||
@@ -340,6 +338,10 @@ void Controller::refreshTransactions() {
|
|||||||
CAmount total_amount;
|
CAmount total_amount;
|
||||||
QList<TransactionItemDetail> items;
|
QList<TransactionItemDetail> items;
|
||||||
|
|
||||||
|
auto confirmations = model->getLatestBlock() - it["block_height"].get<json::number_integer_t>() + 1;
|
||||||
|
auto txid = QString::fromStdString(it["txid"]);
|
||||||
|
auto datetime = it["datetime"].get<json::number_integer_t>();
|
||||||
|
|
||||||
// First, check if there's outgoing metadata
|
// First, check if there's outgoing metadata
|
||||||
if (!it["outgoing_metadata"].is_null()) {
|
if (!it["outgoing_metadata"].is_null()) {
|
||||||
|
|
||||||
@@ -365,12 +367,7 @@ void Controller::refreshTransactions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
txdata.push_back(TransactionItem{
|
txdata.push_back(TransactionItem{
|
||||||
"Sent",
|
"Sent", datetime, address, txid,confirmations, items
|
||||||
it["datetime"].get<json::number_integer_t>(),
|
|
||||||
address,
|
|
||||||
QString::fromStdString(it["txid"]),
|
|
||||||
model->getLatestBlock() - it["block_height"].get<json::number_integer_t>(),
|
|
||||||
items
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Incoming Transaction
|
// Incoming Transaction
|
||||||
@@ -389,12 +386,7 @@ void Controller::refreshTransactions() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
TransactionItem tx{
|
TransactionItem tx{
|
||||||
"Receive",
|
"Receive", datetime, address, txid,confirmations, items
|
||||||
it["datetime"].get<json::number_integer_t>(),
|
|
||||||
address,
|
|
||||||
QString::fromStdString(it["txid"]),
|
|
||||||
model->getLatestBlock() - it["block_height"].get<json::number_integer_t>() + 1,
|
|
||||||
items
|
|
||||||
};
|
};
|
||||||
|
|
||||||
txdata.push_back(tx);
|
txdata.push_back(tx);
|
||||||
|
|||||||
Reference in New Issue
Block a user