import { useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; interface CopyConfigDialogProps { isOpen: boolean; onClose: () => void; traderAddress: string; } export function CopyConfigDialog({ isOpen, onClose, traderAddress }: CopyConfigDialogProps) { const [fixedSize, setFixedSize] = useState("10"); const [maxPosition, setMaxPosition] = useState("100"); const [stopLoss, setStopLoss] = useState("15"); const [takeProfit, setTakeProfit] = useState("30"); const [isLoading, setIsLoading] = useState(false); const handleStartCopy = async () => { setIsLoading(true); try { const response = await fetch("http://localhost:8080/api/copy/start", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ trader_address: traderAddress, enabled: true, fixed_size: parseFloat(fixedSize), max_position: parseFloat(maxPosition), stop_loss_pct: parseFloat(stopLoss) / 100, // Backend expects decimal? Assuming pct in struct comment take_profit_pct: parseFloat(takeProfit) / 100, }), }); if (!response.ok) { throw new Error("Failed to start copy"); } const data = await response.json(); console.log("Copy started:", data); onClose(); } catch (error) { console.error("Error starting copy:", error); // TODO: Show error toast } finally { setIsLoading(false); } }; return ( Copy Configuration Configure risk parameters for copying {traderAddress.slice(0, 6)}...{traderAddress.slice(-4)}
setFixedSize(e.target.value)} className="col-span-3" />
setMaxPosition(e.target.value)} className="col-span-3" />
setStopLoss(e.target.value)} className="col-span-3" />
setTakeProfit(e.target.value)} className="col-span-3" />
); }