From 5915f254c487d16deb22bc99968be39859268f7e Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sun, 27 Oct 2019 12:29:24 -0700 Subject: [PATCH 1/2] Refresh logic --- src/controller.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index f43fe4d..7eb4282 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -137,15 +137,13 @@ void Controller::refresh(bool force) { getInfoThenRefresh(force); } -void Controller::getInfoThenRefresh(bool force) { +void Controller::getInfoThenRefresh(bool doUpdate) { if (!zrpc->haveConnection()) return noConnection(); static bool prevCallSucceeded = false; zrpc->fetchInfo([=] (const json& reply) { - qDebug() << "Info updated"; - prevCallSucceeded = true; // Testnet? @@ -159,10 +157,12 @@ void Controller::getInfoThenRefresh(bool force) { if (!Settings::getInstance()->isTestnet()) main->disableRecurring(); - static int lastBlock = 0; int curBlock = reply["latest_block_height"].get(); + bool doUpdate = doUpdate || (model->getLatestBlock() != curBlock); model->setLatestBlock(curBlock); + qDebug() << "Refreshing. Full update: " << doUpdate; + // Connected, so display checkmark. auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump()); QIcon i(":/icons/res/connected.gif"); @@ -178,10 +178,8 @@ void Controller::getInfoThenRefresh(bool force) { // See if recurring payments needs anything Recurring::getInstance()->processPending(main); - if ( force || (curBlock != lastBlock) ) { + if ( doUpdate ) { // Something changed, so refresh everything. - lastBlock = curBlock; - refreshBalances(); refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans() refreshTransactions(); @@ -340,6 +338,10 @@ void Controller::refreshTransactions() { CAmount total_amount; QList items; + auto confirmations = model->getLatestBlock() - it["block_height"].get() + 1; + auto txid = QString::fromStdString(it["txid"]); + auto datetime = it["datetime"].get(); + // First, check if there's outgoing metadata if (!it["outgoing_metadata"].is_null()) { @@ -365,12 +367,7 @@ void Controller::refreshTransactions() { } txdata.push_back(TransactionItem{ - "Sent", - it["datetime"].get(), - address, - QString::fromStdString(it["txid"]), - model->getLatestBlock() - it["block_height"].get(), - items + "Sent", datetime, address, txid,confirmations, items }); } else { // Incoming Transaction @@ -389,12 +386,7 @@ void Controller::refreshTransactions() { }); TransactionItem tx{ - "Receive", - it["datetime"].get(), - address, - QString::fromStdString(it["txid"]), - model->getLatestBlock() - it["block_height"].get() + 1, - items + "Receive", datetime, address, txid,confirmations, items }; txdata.push_back(tx); From 73c6773e4990ad54de2d5b2308d6d723a865fad1 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sun, 27 Oct 2019 12:33:12 -0700 Subject: [PATCH 2/2] Fix update force logic --- src/controller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 7eb4282..aab6eec 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -137,7 +137,7 @@ void Controller::refresh(bool force) { getInfoThenRefresh(force); } -void Controller::getInfoThenRefresh(bool doUpdate) { +void Controller::getInfoThenRefresh(bool force) { if (!zrpc->haveConnection()) return noConnection(); @@ -158,7 +158,7 @@ void Controller::getInfoThenRefresh(bool doUpdate) { main->disableRecurring(); int curBlock = reply["latest_block_height"].get(); - bool doUpdate = doUpdate || (model->getLatestBlock() != curBlock); + bool doUpdate = force || (model->getLatestBlock() != curBlock); model->setLatestBlock(curBlock); qDebug() << "Refreshing. Full update: " << doUpdate;