Refactor app services and stabilize refresh/UI flows
- Add refresh scheduler and network refresh service boundaries for typed refresh results, ordered RPC collectors, applicators, and price parsing. - Add daemon lifecycle and wallet security workflow helpers while preserving App-owned command RPC, decrypt, cancellation, and UI handoff behavior. - Split balance, console, mining, amount formatting, and async task logic into focused modules with expanded Phase 4 test coverage. - Fix market price loading by triggering price refresh immediately, avoiding queue-pressure drops, tracking loading/error state, and adding translations. - Polish send, explorer, peers, settings, theme/schema, and related tab UI. - Replace checked-in generated language headers with build-generated resources. - Document the cleanup audit, UI static-state guidance, and architecture updates.
This commit is contained in:
72
src/ui/windows/mining_tab_helpers.cpp
Normal file
72
src/ui/windows/mining_tab_helpers.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "mining_tab_helpers.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
namespace dragonx {
|
||||
namespace ui {
|
||||
|
||||
int GetMaxMiningThreads()
|
||||
{
|
||||
int hardwareThreads = static_cast<int>(std::thread::hardware_concurrency());
|
||||
return std::max(1, hardwareThreads);
|
||||
}
|
||||
|
||||
int ClampMiningThreads(int requestedThreads, int maxThreads)
|
||||
{
|
||||
int boundedMax = std::max(1, maxThreads);
|
||||
return std::clamp(requestedThreads, 1, boundedMax);
|
||||
}
|
||||
|
||||
bool IsPoolMiningActive(bool poolMode, bool xmrigRunning, bool soloMiningRunning)
|
||||
{
|
||||
return poolMode ? xmrigRunning : (soloMiningRunning || xmrigRunning);
|
||||
}
|
||||
|
||||
std::string FormatHashrate(double hashrate)
|
||||
{
|
||||
char buffer[64];
|
||||
if (hashrate >= 1e12) {
|
||||
snprintf(buffer, sizeof(buffer), "%.2f TH/s", hashrate / 1e12);
|
||||
} else if (hashrate >= 1e9) {
|
||||
snprintf(buffer, sizeof(buffer), "%.2f GH/s", hashrate / 1e9);
|
||||
} else if (hashrate >= 1e6) {
|
||||
snprintf(buffer, sizeof(buffer), "%.2f MH/s", hashrate / 1e6);
|
||||
} else if (hashrate >= 1e3) {
|
||||
snprintf(buffer, sizeof(buffer), "%.2f KH/s", hashrate / 1e3);
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "%.2f H/s", hashrate);
|
||||
}
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
double EstimateHoursToBlock(double localHashrate, double networkHashrate, double difficulty)
|
||||
{
|
||||
(void)difficulty;
|
||||
if (localHashrate <= 0.0 || networkHashrate <= 0.0) return 0.0;
|
||||
double blocksPerHour = 3600.0 / 75.0;
|
||||
double share = localHashrate / networkHashrate;
|
||||
if (share <= 0.0) return 0.0;
|
||||
return 1.0 / (blocksPerHour * share);
|
||||
}
|
||||
|
||||
std::string FormatEstTime(double estimatedHours)
|
||||
{
|
||||
char buffer[64];
|
||||
if (estimatedHours <= 0.0) {
|
||||
return "N/A";
|
||||
} else if (estimatedHours < 1.0) {
|
||||
snprintf(buffer, sizeof(buffer), "~%.0f min", estimatedHours * 60.0);
|
||||
} else if (estimatedHours < 24.0) {
|
||||
snprintf(buffer, sizeof(buffer), "~%.1f hrs", estimatedHours);
|
||||
} else if (estimatedHours < 168.0) {
|
||||
snprintf(buffer, sizeof(buffer), "~%.1f days", estimatedHours / 24.0);
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "~%.1f weeks", estimatedHours / 168.0);
|
||||
}
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace dragonx
|
||||
Reference in New Issue
Block a user