import { X, FileJson, CheckCircle, AlertCircle } from 'lucide-react' import { useState } from 'react' export default function JsonUploadModal({ isOpen, onClose, onUpload }) { const [jsonText, setJsonText] = useState('') const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const validateJson = (text) => { try { const parsed = JSON.parse(text) if (!Array.isArray(parsed)) { return { valid: false, error: 'JSON must be an array of rules' } } for (let i = 0; i < parsed.length; i++) { const rule = parsed[i] if (!rule.rule || !rule.condition || !rule.action) { return { valid: false, error: `Rule ${i + 1} missing required fields (rule, condition, action)` } } if (!['LONG', 'SHORT', 'FOLLOW_TREND'].includes(rule.action)) { return { valid: false, error: `Rule ${i + 1}: action must be LONG, SHORT, or FOLLOW_TREND` } } } return { valid: true, data: parsed } } catch (e) { return { valid: false, error: 'Invalid JSON format' } } } const handleSubmit = () => { setError(null) setSuccess(false) const validation = validateJson(jsonText) if (!validation.valid) { setError(validation.error) return } onUpload(validation.data) setSuccess(true) setTimeout(() => { onClose() setJsonText('') setSuccess(false) }, 1500) } const loadExample = () => { const example = [ { "rule": "MACD Bullish Crossover", "condition": "MACD > Signal", "action": "LONG", "confidence": "Medium", "description": "When MACD line crosses above the signal line, indicating bullish momentum." }, { "rule": "Bollinger Breakout", "condition": "Price > Upper_Band", "action": "SHORT", "confidence": "Low", "description": "Price breaking above upper Bollinger Band may indicate overextension." } ] setJsonText(JSON.stringify(example, null, 2)) } if (!isOpen) return null return (

Add Custom Rules

JSON Format

Paste your JSON array of trading rules. Each rule must include: rule, condition, action, confidence, and description.