Files
ObsidianDragon/src/data/portfolio.h
DanS 973bc0d338 feat(market): trend sparkline in all portfolio styles + inline chart/style pickers
Render the portfolio trend sparkline in every row style, each with a layout that features it:
- Table: a dedicated header-labelled TREND column (48dp rows), aligned across rows.
- Cards: a left-aligned info stack (icon + label / value+delta chip / DRGX) with a full-height sparkline filling the rest of the width (content-driven, so short groups give the chart more room).
- Spotlight: a big-value-over-a-full-width-chart-band hero tile (92dp).
Default sparkline interval is now MONTH (a real curve from the daily series, not the young minute buffer). Removed the per-row container accent line (redundant with the icon/sparkline colour) and the per-group shielded/transparent bar (private-by-default makes it near-always 100%, and dropped its now-dead SumPortfolioSplit helper). DPI-scale the sparkline stroke. Adds the "Trend" column string across 9 languages.

Relocated the Market controls out of a removed settings modal + gear: the chart line/candle picker now sits top-right of the chart (left of the trade button, candle-capable ranges only), and the Table/Cards/Spotlight picker sits left of Manage. Dropped the market fetch-prices toggle (still in the general Settings page).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 13:39:42 -05:00

62 lines
2.2 KiB
C++

// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3
//
// Portfolio helpers — pure balance math for the Market tab's configurable portfolio.
// A portfolio entry is a user label tied to a group of wallet addresses (persisted in
// Settings as PortfolioEntry); these helpers sum/query that group against the live
// per-address balance list. No I/O, no ImGui — unit-testable.
#pragma once
#include "wallet_state.h" // AddressInfo
#include <string>
#include <unordered_set>
#include <vector>
namespace dragonx {
namespace data {
// Sum the DRGX balance of `entryAddresses` by looking them up in the wallet's per-address
// list. Addresses not present in the wallet contribute 0 (e.g. removed/rescanned). Pure.
inline double SumPortfolioBalance(const std::vector<std::string>& entryAddresses,
const std::vector<AddressInfo>& walletAddresses)
{
if (entryAddresses.empty()) return 0.0;
std::unordered_set<std::string> want(entryAddresses.begin(), entryAddresses.end());
double sum = 0.0;
for (const auto& a : walletAddresses)
if (want.count(a.address)) sum += a.balance;
return sum;
}
// Whether `address` is part of the entry's address group.
inline bool PortfolioEntryContains(const std::vector<std::string>& entryAddresses,
const std::string& address)
{
for (const auto& a : entryAddresses)
if (a == address) return true;
return false;
}
// Add `address` to the group if absent (returns true if it was added).
inline bool PortfolioEntryAdd(std::vector<std::string>& entryAddresses, const std::string& address)
{
if (address.empty() || PortfolioEntryContains(entryAddresses, address)) return false;
entryAddresses.push_back(address);
return true;
}
// Remove `address` from the group if present (returns true if it was removed).
inline bool PortfolioEntryRemove(std::vector<std::string>& entryAddresses, const std::string& address)
{
for (auto it = entryAddresses.begin(); it != entryAddresses.end(); ++it) {
if (*it == address) { entryAddresses.erase(it); return true; }
}
return false;
}
} // namespace data
} // namespace dragonx