import { useEffect, useState } from 'react'; import type { ReactNode } from 'react'; import { tradingKillSwitchClient } from '../lib/runtime'; interface AccessibilityState { status: 'loading' | 'available' | 'maintenance' | 'product_disabled'; message?: string; } const initialState: AccessibilityState = { status: 'loading', }; export function ProductAccessibilityGate({ children }: { children: ReactNode }) { const [state, setState] = useState(initialState); useEffect(() => { let active = true; async function loadAvailability() { try { const result = await tradingKillSwitchClient.check(); if (!active) { return; } if (result.disabled) { setState({ status: 'product_disabled', message: result.message ?? 'Trading access is temporarily disabled.', }); return; } setState({ status: 'available' }); } catch (error) { console.warn('[ProductAccessibilityGate] Failed to evaluate kill switch.', error); if (active) { setState({ status: 'available' }); } } } void loadAvailability(); return () => { active = false; }; }, []); if (state.status === 'loading') { return ; } if (state.status !== 'available') { return ( ); } return <>{children}; } function CenteredMessage({ title, body }: { title: string; body?: string }) { return (

{title}

{body ? (

{body}

) : null}
); }