/* FinPulse — Indices: India (default) + Global US (Finnhub, on tab switch) */
function IndicesScreen({ onOpenStock, initialRegion, initialSel }) {
const L = useLive();
const MD = useMarketData();
const [region, setRegion] = useState(initialRegion || 'IN');
const india = MD.indices || [];
const global = MD.globalIndices || [];
const indices = region === 'US' ? global : india;
const [sel, setSel] = useState(initialSel || (indices[0] && indices[0].label));
useEffect(() => {
if (initialRegion) setRegion(initialRegion);
}, [initialRegion]);
useEffect(() => {
if (initialSel) setSel(initialSel);
}, [initialSel]);
useEffect(() => {
if (region === 'US' && L.hasKey && !global.length && !MD.globalLoading) {
MD.loadGlobal();
}
}, [region, L.hasKey]);
useEffect(() => {
if (indices.length && !indices.find((i) => i.label === sel)) setSel(indices[0].label);
}, [indices.length, region]);
if ((MD.loading && !india.length && region === 'IN') || (region === 'US' && MD.globalLoading && !global.length)) {
return ;
}
if (region === 'US' && !L.hasKey) {
return (
Indices
India benchmarks · switch to Global for US markets
Connect API} />
);
}
if (!indices.length) {
return Retry} />;
}
const ix = indices.find((i) => i.label === sel) || indices[0];
const meta = region === 'US'
? (MD.globalIndexMeta[sel] || { desc: ix.desc })
: (MD.indexMeta[sel] || { desc: ix.desc });
const members = MD.indexMembers(sel, region);
const cur = ix.cur === 'INR' ? '₹' : '$';
return (
Indices
{region === 'IN' ? 'NSE & BSE benchmarks' : 'US benchmark ETFs · Finnhub live'}
{indices.map((i) => {
const up = i.chg >= 0;
const sym = i.cur === 'INR' ? '₹' : '$';
return (
);
})}
{ix.label} · {ix.symbol}
{cur}{fmt.price(ix.value)}
= 0 ? 'var(--up)' : 'var(--down)'} height={240}
labels={['Open', '', 'Mid', '', 'Now']} />
{meta.desc}
{members.length ? 'Top Constituents' : 'About'}
{members.length ? (
{members.map((s, i) => (
onOpenStock(s)} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '9px 0', cursor: 'pointer', borderBottom: i < members.length - 1 ? '1px solid var(--border)' : 'none' }}>
{s.name}
{fmt.stockPrice(s)}
))}
) : (
{meta.desc}
)}
);
}
Object.assign(window, { IndicesScreen });