refactor(market): drop dead statics, fix BTC preview/card precision mismatch
Audit cleanup of market_tab.cpp: - Remove the write-only statics s_history_initialized and s_last_refresh_time (assigned in several places, never read) and their now-dead assignments. - Align the portfolio grid card's BTC value to %.8f to match the editor preview (pfBuildDisplay) and the summary rows; it was the lone %.6f, so the same balance rendered with different precision in the preview vs the card. - Fix the stale s_pf_sel comment (no "-2 = unsaved draft" state exists). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,8 +36,6 @@ using namespace material;
|
||||
|
||||
// ---- Market tab persistent state ----
|
||||
static std::vector<double> s_price_history; // mirror of WalletState market.price_history
|
||||
static bool s_history_initialized = false;
|
||||
static double s_last_refresh_time = 0.0;
|
||||
|
||||
// Exchange / pair selection
|
||||
static int s_exchange_idx = 0;
|
||||
@@ -97,7 +95,7 @@ static std::string FormatPrice(double price)
|
||||
|
||||
// ---- Portfolio editor (modal) state ----
|
||||
static bool s_portfolio_editor_open = false;
|
||||
static int s_pf_sel = -1; // selected group index in the master list; -1 = none, -2 = unsaved draft
|
||||
static int s_pf_sel = -1; // selected group index in the master list; -1 = none
|
||||
static int s_pf_section = 0; // right-pane segmented control: 0=Appearance 1=Price 2=Addresses
|
||||
// Backdrop live-capture: capture once on open + on viewport resize (not every frame). The blur is a
|
||||
// frozen snapshot while the modal is open — efficient and flicker-free.
|
||||
@@ -1464,8 +1462,6 @@ void RenderMarketTab(App* app)
|
||||
// The chart series (s_price_history) + timestamps (chartTimes) were computed in the
|
||||
// precompute above. Historical intervals come from CoinGecko market_chart; "Live" is the
|
||||
// in-session buffer. Until two points exist, the empty-state below is shown.
|
||||
s_history_initialized = true;
|
||||
|
||||
// The chart shares the combined hero+chart glass panel drawn in PRICE SUMMARY above.
|
||||
ImVec2 chartMin = ImGui::GetCursorScreenPos();
|
||||
ImVec2 chartMax(chartMin.x + availWidth, chartMin.y + chartH);
|
||||
@@ -1500,7 +1496,6 @@ void RenderMarketTab(App* app)
|
||||
ImGui::PushID(9100 + b);
|
||||
if (ImGui::InvisibleButton("##civ", ImVec2(bw, pillH))) {
|
||||
s_chart_interval = kIvs[b].iv;
|
||||
s_history_initialized = false;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
||||
ImGui::PopID();
|
||||
@@ -1521,8 +1516,6 @@ void RenderMarketTab(App* app)
|
||||
ImGui::SetCursorScreenPos(rbMin);
|
||||
if (ImGui::InvisibleButton("##RefreshMarket", ImVec2(pillH, pillH))) {
|
||||
app->refreshMarketData();
|
||||
s_history_initialized = false;
|
||||
s_last_refresh_time = ImGui::GetTime();
|
||||
}
|
||||
if (ImGui::IsItemHovered()) material::Tooltip("%s", TR("market_refresh_price"));
|
||||
|
||||
@@ -1774,7 +1767,6 @@ void RenderMarketTab(App* app)
|
||||
if (ex != s_exchange_idx || pr != s_pair_idx) {
|
||||
s_exchange_idx = ex;
|
||||
s_pair_idx = pr;
|
||||
s_history_initialized = false;
|
||||
app->settings()->setSelectedExchange(exName);
|
||||
app->settings()->setSelectedPair(pairName);
|
||||
app->settings()->save();
|
||||
@@ -1942,7 +1934,7 @@ void RenderMarketTab(App* app)
|
||||
// Value + DRGX strings per basis.
|
||||
char vb[80]; std::string valueStr; bool hasValue = false;
|
||||
if (e.priceBasis == 0 && market.price_usd > 0) { snprintf(vb, sizeof(vb), "$%.2f", bal * market.price_usd); valueStr = vb; hasValue = true; }
|
||||
else if (e.priceBasis == 1 && market.price_btc > 0) { snprintf(vb, sizeof(vb), "%.6f BTC", bal * market.price_btc); valueStr = vb; hasValue = true; }
|
||||
else if (e.priceBasis == 1 && market.price_btc > 0) { snprintf(vb, sizeof(vb), "%.8f BTC", bal * market.price_btc); valueStr = vb; hasValue = true; }
|
||||
else if (e.priceBasis == 3 && e.manualPrice > 0.0) { snprintf(vb, sizeof(vb), "%.2f %s", bal * e.manualPrice, e.manualCurrency.c_str()); valueStr = vb; hasValue = true; }
|
||||
char db[48]; snprintf(db, sizeof(db), "%.4f %s", bal, DRAGONX_TICKER);
|
||||
bool heroIsValue = e.showValue && hasValue;
|
||||
|
||||
Reference in New Issue
Block a user