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:
106
src/ui/windows/balance_address_list.cpp
Normal file
106
src/ui/windows/balance_address_list.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "balance_address_list.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
|
||||
namespace dragonx {
|
||||
namespace ui {
|
||||
namespace {
|
||||
|
||||
bool containsIgnoreCase(const std::string& haystack, const std::string& needle)
|
||||
{
|
||||
if (needle.empty()) return true;
|
||||
auto it = std::search(haystack.begin(), haystack.end(),
|
||||
needle.begin(), needle.end(),
|
||||
[](char a, char b) {
|
||||
return std::tolower(static_cast<unsigned char>(a)) ==
|
||||
std::tolower(static_cast<unsigned char>(b));
|
||||
});
|
||||
return it != haystack.end();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool AddressListMatchesFilter(const AddressListInput& input, const std::string& filter)
|
||||
{
|
||||
if (!input.info) return false;
|
||||
return containsIgnoreCase(input.info->address, filter) ||
|
||||
containsIgnoreCase(input.info->label, filter) ||
|
||||
containsIgnoreCase(input.label, filter);
|
||||
}
|
||||
|
||||
std::vector<AddressListRow> BuildAddressListRows(const std::vector<AddressListInput>& inputs,
|
||||
const std::string& filter,
|
||||
bool hideZeroBalances,
|
||||
bool showHidden)
|
||||
{
|
||||
std::vector<AddressListRow> rows;
|
||||
rows.reserve(inputs.size());
|
||||
for (const auto& input : inputs) {
|
||||
if (!input.info) continue;
|
||||
if (!AddressListMatchesFilter(input, filter)) continue;
|
||||
if (input.hidden && !showHidden) continue;
|
||||
if (hideZeroBalances && input.info->balance < 1e-9 && !input.hidden && !input.favorite) continue;
|
||||
rows.push_back({input.info, input.isZ, input.hidden, input.favorite,
|
||||
input.label, input.icon, input.sortOrder});
|
||||
}
|
||||
|
||||
std::sort(rows.begin(), rows.end(),
|
||||
[](const AddressListRow& a, const AddressListRow& b) {
|
||||
bool aHasOrder = a.sortOrder >= 0;
|
||||
bool bHasOrder = b.sortOrder >= 0;
|
||||
if (aHasOrder && bHasOrder) return a.sortOrder < b.sortOrder;
|
||||
if (aHasOrder != bHasOrder) return aHasOrder > bHasOrder;
|
||||
if (a.favorite != b.favorite) return a.favorite > b.favorite;
|
||||
if (a.isZ != b.isZ) return a.isZ > b.isZ;
|
||||
return a.info->balance > b.info->balance;
|
||||
});
|
||||
return rows;
|
||||
}
|
||||
|
||||
AddressRowLayout ComputeAddressRowLayout(float rowX,
|
||||
float rowY,
|
||||
float rowWidth,
|
||||
float rowHeight,
|
||||
float rowPadLeft,
|
||||
float rowIconSize,
|
||||
float spacingMd,
|
||||
float spacingSm,
|
||||
float spacingXs)
|
||||
{
|
||||
AddressRowLayout layout;
|
||||
layout.contentStartX = rowX + rowPadLeft;
|
||||
layout.contentStartY = rowY + spacingMd;
|
||||
layout.buttonSize = rowHeight - spacingMd * 2.0f;
|
||||
|
||||
const float buttonY = rowY + (rowHeight - layout.buttonSize) * 0.5f;
|
||||
const float rightEdge = rowX + rowWidth;
|
||||
const float favoriteX = rightEdge - layout.buttonSize - spacingXs;
|
||||
const float visibilityX = favoriteX - spacingSm - layout.buttonSize;
|
||||
|
||||
layout.favoriteButton = {favoriteX, buttonY, layout.buttonSize, layout.buttonSize};
|
||||
layout.visibilityButton = {visibilityX, buttonY, layout.buttonSize, layout.buttonSize};
|
||||
layout.contentRight = visibilityX - spacingSm;
|
||||
layout.labelX = layout.contentStartX + rowIconSize * 2.0f + spacingMd;
|
||||
return layout;
|
||||
}
|
||||
|
||||
std::string FormatAddressUsdValue(double balance, double priceUsd)
|
||||
{
|
||||
if (priceUsd <= 0.0 || balance <= 0.0) return {};
|
||||
|
||||
char buffer[32];
|
||||
const double usdValue = balance * priceUsd;
|
||||
if (usdValue >= 1.0) {
|
||||
std::snprintf(buffer, sizeof(buffer), "$%.2f", usdValue);
|
||||
} else if (usdValue >= 0.01) {
|
||||
std::snprintf(buffer, sizeof(buffer), "$%.4f", usdValue);
|
||||
} else {
|
||||
std::snprintf(buffer, sizeof(buffer), "$%.6f", usdValue);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace dragonx
|
||||
Reference in New Issue
Block a user