refactor(market): resolve exchange/pair selection through one helper

The chart fetch and the Market tab both resolved the saved exchange and
pair names into the registry, with their own near-identical scans and
slightly different fallbacks. Keeping two copies risked the chart and
the chips disagreeing about which pair was selected.

- A single resolver maps the saved names to a registry index, matching
  the exchange name (any exchange when none is saved) then the pair
  display name, and falling back to the registry's first pair, the UI
  default. The chart fetch and the Market tab both call it.
- The Market tab now derives its selection indices from the saved names
  against the current registry every frame, so the indices stay correct
  when the live exchange list replaces the fallback; a steady-state fast
  path skips the scan once the indices already name the saved selection.

Tests: the resolver returns the right index for a matched exchange/pair,
an empty-exchange match, and the first-pair fallback on misses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 16:00:10 -05:00
co-authored by Claude Opus 4.8
parent ce00621a4a
commit 3f82af99c4
4 changed files with 74 additions and 25 deletions
+5 -6
View File
@@ -3272,14 +3272,13 @@ void App::refreshExchangeChart()
? data::getExchangeRegistry() : state_.market.exchanges;
const std::string selEx = settings_->getSelectedExchange();
const std::string selPair = settings_->getSelectedPair();
// Same resolver as the Market tab chips (not found => registry's first pair, the UI default).
const data::ExchangePair* pair = nullptr;
for (const auto& ex : reg) {
if (!selEx.empty() && ex.name != selEx) continue;
for (const auto& p : ex.pairs)
if (p.displayName == selPair) { pair = &p; break; }
if (pair) break;
if (!reg.empty()) {
const auto sel = data::resolveExchangeSelection(reg, selEx, selPair);
if (sel.exchangeIdx < (int)reg.size() && sel.pairIdx < (int)reg[sel.exchangeIdx].pairs.size())
pair = &reg[sel.exchangeIdx].pairs[sel.pairIdx];
}
if (!pair && !reg.empty() && !reg[0].pairs.empty()) pair = &reg[0].pairs[0]; // default like the UI
if (!pair) { state_.market.exchange_chart_active = false; exchange_chart_key_.clear(); return; }
const std::string key = pair->identifier + ":" + pair->base + "/" + pair->quote;