From 7f3cce69b933cf293bef6500439b0c45019a1661 Mon Sep 17 00:00:00 2001 From: OpenSquared Date: Tue, 30 Jun 2026 17:03:36 +0200 Subject: [PATCH] feat: instrument analysis --- frontend/src/context/TabsContext.tsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend/src/context/TabsContext.tsx b/frontend/src/context/TabsContext.tsx index c9b5e17..de2bd6b 100644 --- a/frontend/src/context/TabsContext.tsx +++ b/frontend/src/context/TabsContext.tsx @@ -1,7 +1,19 @@ -import { createContext, useContext, useCallback, useState, useEffect, ReactNode } from 'react' +import { createContext, useContext, useCallback, useState, ReactNode } from 'react' -// Instruments that exist in instruments.json — used to validate localStorage -const VALID_INSTRUMENT_SUFFIX = /^[A-Z0-9]+=?[A-Z0-9-]*$/ +// Forex tickers on Yahoo Finance require the =X suffix; migrate stale plain versions +const FOREX_MIGRATIONS: Record = { 'EURUSD': 'EURUSD=X', 'GBPUSD': 'GBPUSD=X', 'USDJPY': 'USDJPY=X', 'USDCHF': 'USDCHF=X' } + +function migrateInstrumentId(id: string): string { + return FOREX_MIGRATIONS[id] ?? id +} + +// Apply once at module load so every localStorage read is already corrected +;(function migrateLastInstrument() { + const stored = localStorage.getItem('last_instrument') + if (stored && FOREX_MIGRATIONS[stored]) { + localStorage.setItem('last_instrument', FOREX_MIGRATIONS[stored]) + } +})() interface TabsCtx { kept: ReadonlySet @@ -32,8 +44,9 @@ export function TabsProvider({ children }: { children: ReactNode }) { setKept(p => { const n = new Set(p); n.delete(r); return n }), []) const openInstrument = useCallback((id: string) => { - localStorage.setItem('last_instrument', id) - setInstrumentIds(p => p.includes(id) ? p : [...p, id]) + const safe = migrateInstrumentId(id.toUpperCase()) + localStorage.setItem('last_instrument', safe) + setInstrumentIds(p => p.includes(safe) ? p : [...p, safe]) }, []) const closeInstrument = useCallback((id: string) =>