refactor: tab-aware prioritized refresh system

Split monolithic refreshData() into independent sub-functions
(refreshCoreData, refreshAddressData, refreshTransactionData,
refreshEncryptionState) each with its own timer and atomic guard.

Per-category timers replace the single 5s refresh_timer_:
- core_timer_: balance + blockchain info (5s default)
- transaction_timer_: tx list + enrichment (10s default)
- address_timer_: z/t address lists (15s default)
- peer_timer_: encryption state (10s default)

Tab-switching via setCurrentPage() adjusts active intervals so
the current tab's data refreshes faster (e.g. 3s core on Overview,
5s transactions on History) while background categories slow down.

Use fast_worker_ for core data on Overview tab to avoid blocking
behind the main refresh batch.

Bump version to 1.1.2.
This commit is contained in:
2026-04-04 13:05:00 -05:00
parent 1f9e43d7b2
commit bbf53a130c
5 changed files with 508 additions and 610 deletions

View File

@@ -15,7 +15,7 @@ if(APPLE)
endif()
project(ObsidianDragon
VERSION 1.1.1
VERSION 1.1.2
LANGUAGES C CXX
DESCRIPTION "DragonX Cryptocurrency Wallet"
)

View File

@@ -343,7 +343,10 @@ void App::update()
}
// Update timers
refresh_timer_ += io.DeltaTime;
core_timer_ += io.DeltaTime;
address_timer_ += io.DeltaTime;
transaction_timer_ += io.DeltaTime;
peer_timer_ += io.DeltaTime;
price_timer_ += io.DeltaTime;
fast_refresh_timer_ += io.DeltaTime;
tx_age_timer_ += io.DeltaTime;
@@ -591,20 +594,37 @@ void App::update()
transactions_dirty_ = true;
addresses_dirty_ = true;
last_tx_block_height_ = -1;
refresh_timer_ = REFRESH_INTERVAL;
core_timer_ = active_core_interval_;
transaction_timer_ = active_tx_interval_;
address_timer_ = active_addr_interval_;
}
};
});
}
// Regular refresh every 5 seconds
// Per-category refresh with tab-aware intervals
// Skip when wallet is locked — same reason as above.
if (refresh_timer_ >= REFRESH_INTERVAL) {
refresh_timer_ = 0.0f;
if (state_.connected && !state_.isLocked()) {
refreshData();
} else if (!connection_in_progress_ &&
wizard_phase_ == WizardPhase::None) {
if (state_.connected && !state_.isLocked()) {
if (core_timer_ >= active_core_interval_) {
core_timer_ = 0.0f;
refreshCoreData();
}
if (transaction_timer_ >= active_tx_interval_) {
transaction_timer_ = 0.0f;
refreshTransactionData();
}
if (address_timer_ >= active_addr_interval_) {
address_timer_ = 0.0f;
refreshAddressData();
}
if (peer_timer_ >= active_peer_interval_) {
peer_timer_ = 0.0f;
refreshEncryptionState();
}
} else if (core_timer_ >= active_core_interval_) {
core_timer_ = 0.0f;
if (!connection_in_progress_ &&
wizard_phase_ == WizardPhase::None) {
tryConnect();
}
}
@@ -619,7 +639,7 @@ void App::update()
// Keyboard shortcut: Ctrl+, to open Settings page
if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_Comma)) {
current_page_ = ui::NavPage::Settings;
setCurrentPage(ui::NavPage::Settings);
}
// Keyboard shortcut: Ctrl+Left/Right to cycle themes
@@ -1886,7 +1906,11 @@ void App::renderAntivirusHelpDialog()
void App::refreshNow()
{
refresh_timer_ = REFRESH_INTERVAL; // Trigger immediate refresh
// Trigger immediate refresh on all categories
core_timer_ = active_core_interval_;
transaction_timer_ = active_tx_interval_;
address_timer_ = active_addr_interval_;
peer_timer_ = active_peer_interval_;
transactions_dirty_ = true; // Force transaction list update
addresses_dirty_ = true; // Force address/balance update
last_tx_block_height_ = -1; // Reset tx cache
@@ -1909,7 +1933,7 @@ void App::handlePaymentURI(const std::string& uri)
pending_label_ = payment.label;
// Switch to Send page
current_page_ = ui::NavPage::Send;
setCurrentPage(ui::NavPage::Send);
// Notify user
std::string msg = "Payment request loaded";
@@ -1936,7 +1960,7 @@ void App::setCurrentTab(int tab) {
ui::NavPage::Settings, // 9 = Settings
};
if (tab >= 0 && tab < static_cast<int>(sizeof(kTabMap)/sizeof(kTabMap[0])))
current_page_ = kTabMap[tab];
setCurrentPage(kTabMap[tab]);
}
bool App::startEmbeddedDaemon()

View File

@@ -221,13 +221,19 @@ public:
void refreshPeerInfo();
void refreshMarketData();
/// @brief Per-category refresh intervals, adjusted by active tab
struct RefreshIntervals {
float core; // balance + sync status
float transactions; // tx list + enrichment
float addresses; // address lists + balances
float peers; // peer info (0 = disabled)
};
/// @brief Get recommended refresh intervals for a given page
static RefreshIntervals getIntervalsForPage(ui::NavPage page);
// UI navigation
void setCurrentPage(ui::NavPage page) {
if (page != current_page_) {
current_page_ = page;
if (page == ui::NavPage::Peers) refreshPeerInfo();
}
}
void setCurrentPage(ui::NavPage page);
ui::NavPage getCurrentPage() const { return current_page_; }
// Dialog triggers (used by settings page to open modal dialogs)
@@ -362,7 +368,6 @@ private:
// Shutdown state
std::atomic<bool> shutting_down_{false};
std::atomic<bool> shutdown_complete_{false};
std::atomic<bool> refresh_in_progress_{false};
bool address_list_dirty_ = false; // P8: dedup rebuildAddressList
std::string shutdown_status_;
std::thread shutdown_thread_;
@@ -438,16 +443,33 @@ private:
std::string pending_memo_;
std::string pending_label_;
// Timers (in seconds since last update)
float refresh_timer_ = 0.0f;
// Per-category timers (in seconds since last refresh)
float core_timer_ = 0.0f; // balance + sync status
float address_timer_ = 0.0f; // address lists
float transaction_timer_ = 0.0f; // transaction list
float peer_timer_ = 0.0f; // peer info
float price_timer_ = 0.0f;
float fast_refresh_timer_ = 0.0f; // For mining stats
// Refresh intervals (seconds)
static constexpr float REFRESH_INTERVAL = 5.0f;
// Default refresh intervals (seconds)
static constexpr float CORE_INTERVAL_DEFAULT = 5.0f;
static constexpr float ADDRESS_INTERVAL_DEFAULT = 15.0f;
static constexpr float TX_INTERVAL_DEFAULT = 10.0f;
static constexpr float PEER_INTERVAL_DEFAULT = 10.0f;
static constexpr float PRICE_INTERVAL = 60.0f;
static constexpr float FAST_REFRESH_INTERVAL = 1.0f;
// Active intervals — adjusted by tab priority via applyRefreshPolicy()
float active_core_interval_ = CORE_INTERVAL_DEFAULT;
float active_tx_interval_ = TX_INTERVAL_DEFAULT;
float active_addr_interval_ = ADDRESS_INTERVAL_DEFAULT;
float active_peer_interval_ = PEER_INTERVAL_DEFAULT;
// Per-category refresh guards (prevent worker queue pileup)
std::atomic<bool> core_refresh_in_progress_{false};
std::atomic<bool> address_refresh_in_progress_{false};
std::atomic<bool> tx_refresh_in_progress_{false};
// Mining refresh guard (prevents worker queue pileup)
std::atomic<bool> mining_refresh_in_progress_{false};
int mining_slow_counter_ = 0; // counts fast ticks; fires slow refresh every N
@@ -604,11 +626,17 @@ private:
void applyDefaultBanlist();
// Private methods - data refresh
void refreshData();
void refreshBalance();
void refreshAddresses();
void refreshData(); // Orchestrator: dispatches per-category refreshes
void refreshCoreData(); // Balance + blockchain info (can use fast_worker_)
void refreshAddressData(); // Address lists + balances
void refreshTransactionData(); // Transaction list + z_viewtransaction enrichment
void refreshEncryptionState(); // Wallet encryption/lock state
void refreshBalance(); // Legacy: balance-only refresh (used by specific callers)
void refreshAddresses(); // Legacy: standalone address refresh
void refreshPrice();
void refreshWalletEncryptionState();
void applyRefreshPolicy(ui::NavPage page);
bool shouldRefreshTransactions() const;
void checkAutoLock();
void checkIdleMining();
};

File diff suppressed because it is too large Load Diff

View File

@@ -7,10 +7,10 @@
// !! DO NOT EDIT version.h — it is generated from version.h.in by CMake.
// !! Change the version in CMakeLists.txt: project(... VERSION x.y.z ...)
#define DRAGONX_VERSION "1.1.1"
#define DRAGONX_VERSION "1.1.2"
#define DRAGONX_VERSION_MAJOR 1
#define DRAGONX_VERSION_MINOR 1
#define DRAGONX_VERSION_PATCH 1
#define DRAGONX_VERSION_PATCH 2
#define DRAGONX_APP_NAME "ObsidianDragon"
#define DRAGONX_ORG_NAME "Hush"