import React from 'react'; import { Save, AlertCircle, CheckCircle, Globe2 } from 'lucide-react'; import { fetchDynamicConfigItems, upsertDynamicConfigItems } from '../lib/dynamicConfigApi'; import { Button } from './ui/button'; import { Card } from './ui/card'; import { Input } from './ui/input'; interface ConfigItem { key: string; value: string; description: string; } export const GlobalConfigManager = () => { const [configs, setConfigs] = React.useState([]); const [loading, setLoading] = React.useState(true); const [saving, setSaving] = React.useState(false); const [message, setMessage] = React.useState<{ type: 'success' | 'error', text: string } | null>(null); const fetchConfigs = async () => { setLoading(true); try { const data = await fetchDynamicConfigItems(); setConfigs(data || []); } catch (error: any) { console.error('Error fetching global config:', error); setMessage({ type: 'error', text: error?.message || 'Dynamic config service unavailable.' }); } setLoading(false); }; React.useEffect(() => { fetchConfigs(); }, []); const handleChange = (key: string, value: string) => { setConfigs(prev => prev.map(item => item.key === key ? { ...item, value } : item)); }; const handleSave = async (item: ConfigItem) => { setSaving(true); try { await upsertDynamicConfigItems([item]); setMessage({ type: 'success', text: `${item.key} updated successfully.` }); setTimeout(() => setMessage(null), 3000); } catch (error: any) { setMessage({ type: 'error', text: `Failed to save ${item.key}: ${error.message}` }); } setSaving(false); }; if (loading) return
Loading system configuration...
; return (

Global Bot Configuration

{message && (
{message.type === 'success' ? : } {message.text}
)}
{configs.map((config) => (
handleChange(config.key, e.target.value)} className="h-10 rounded px-3 py-2 text-sm" />

{config.description || 'System setting used by the trading core.'}

))} {configs.length === 0 && (

No dynamic configuration entries found.

The bot is currently using .env defaults.

)}

Note: Changes to global variables usually require a bot restart to take full effect (e.g. changing intervals or providers). Symbols may update dynamically depending on strategy implementation.

); };