From e82514f46a9ebbc94a432457e108a6985d9f5970 Mon Sep 17 00:00:00 2001 From: DanS Date: Sun, 12 Jul 2026 12:05:36 -0500 Subject: [PATCH] feat(market): persist chart range + style across sessions The chart interval (Live/1H/1D/1W/1M) and the line/candle style were session-only statics. Persist both like the selected exchange/pair: new chart_interval / chart_style settings (defaults 1M / candlestick), loaded into the market view on first show and saved on each interval click / style toggle. Verified: writing chart_interval=2, chart_style=0 to settings.json and launching restores them (not reset to defaults) and re-saves them intact. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/config/settings.cpp | 4 ++++ src/config/settings.h | 6 ++++++ src/ui/windows/market_tab.cpp | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/config/settings.cpp b/src/config/settings.cpp index 0f1fc4f..70d2873 100644 --- a/src/config/settings.cpp +++ b/src/config/settings.cpp @@ -285,6 +285,8 @@ bool Settings::load(const std::string& path) loadScalar(j, "reduce_motion", reduce_motion_); loadScalar(j, "selected_exchange", selected_exchange_); loadScalar(j, "selected_pair", selected_pair_); + loadScalar(j, "chart_interval", chart_interval_); + loadScalar(j, "chart_style", chart_style_); loadScalar(j, "pool_url", pool_url_); // Migrate old default pool URL that was missing the stratum port if (pool_url_ == "pool.dragonx.is") pool_url_ = "pool.dragonx.is:3433"; @@ -486,6 +488,8 @@ bool Settings::save(const std::string& path) j["reduce_motion"] = reduce_motion_; j["selected_exchange"] = selected_exchange_; j["selected_pair"] = selected_pair_; + j["chart_interval"] = chart_interval_; + j["chart_style"] = chart_style_; j["pool_url"] = pool_url_; j["pool_algo"] = pool_algo_; j["pool_worker"] = pool_worker_; diff --git a/src/config/settings.h b/src/config/settings.h index 96ba965..07e6455 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -370,6 +370,10 @@ public: void setSelectedExchange(const std::string& v) { selected_exchange_ = v; } std::string getSelectedPair() const { return selected_pair_; } void setSelectedPair(const std::string& v) { selected_pair_ = v; } + int getChartInterval() const { return chart_interval_; } // Market chart range 0=Live..4=1M + void setChartInterval(int v) { chart_interval_ = v; } + int getChartStyle() const { return chart_style_; } // 0 = line, 1 = candlestick + void setChartStyle(int v) { chart_style_ = v; } // Pool mining std::string getPoolUrl() const { return pool_url_; } @@ -524,6 +528,8 @@ private: bool reduce_motion_ = false; std::string selected_exchange_ = "Nonkyc.io"; std::string selected_pair_ = "DRGX/USDT"; + int chart_interval_ = 4; // Market chart range (0=Live 1=1H 2=1D 3=1W 4=1M) + int chart_style_ = 1; // Market chart style (0=line, 1=candlestick) // Pool mining std::string pool_url_ = "pool.dragonx.is:3433"; diff --git a/src/ui/windows/market_tab.cpp b/src/ui/windows/market_tab.cpp index 5daf6cd..f3c3365 100644 --- a/src/ui/windows/market_tab.cpp +++ b/src/ui/windows/market_tab.cpp @@ -76,6 +76,12 @@ static void LoadMarketState(config::Settings* settings, const std::vectorgetChartInterval(); + if (iv >= 0 && iv <= 4) s_mkt.chartInterval = iv; + int st = settings->getChartStyle(); + if (st == 0 || st == 1) s_mkt.chartStyle = st; } // Helper: format compact currency @@ -1407,6 +1413,7 @@ static void mktDrawPriceChart(const MktCtx& cx) ImGui::PushID(9100 + b); if (ImGui::InvisibleButton("##civ", ImVec2(bw, pillH))) { s_mkt.chartInterval = kIvs[b].iv; + if (app->settings()) { app->settings()->setChartInterval(kIvs[b].iv); app->settings()->save(); } } if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); ImGui::PopID(); @@ -1429,8 +1436,10 @@ static void mktDrawPriceChart(const MktCtx& cx) ImVec2(tmn.x + (pillH - tiSz.x) * 0.5f, tmn.y + (pillH - tiSz.y) * 0.5f), thov ? OnSurface() : OnSurfaceMedium(), styleIcon); ImGui::SetCursorScreenPos(tmn); - if (ImGui::InvisibleButton("##ChartStyle", ImVec2(pillH, pillH))) + if (ImGui::InvisibleButton("##ChartStyle", ImVec2(pillH, pillH))) { s_mkt.chartStyle = isCandle ? 0 : 1; + if (app->settings()) { app->settings()->setChartStyle(s_mkt.chartStyle); app->settings()->save(); } + } if (ImGui::IsItemHovered()) material::Tooltip("%s", TR(isCandle ? "market_style_line" : "market_style_candle")); bx += pillH;