import { useState } from "react"; import Input from "./Input"; import Button from "./Button"; import "./AlertForm.css"; const ALERT_TYPES = [ { value: "incoming_tx", label: "Incoming transaction" }, { value: "outgoing_tx", label: "Outgoing transaction" }, { value: "large_transfer", label: "Large transfer" }, { value: "balance_below", label: "Balance below threshold" }, ]; export default function AlertForm({ onSubmit }) { const [type, setType] = useState("incoming_tx"); const [threshold, setThreshold] = useState(""); const needsThreshold = type === "large_transfer" || type === "balance_below"; const canSubmit = needsThreshold ? threshold.trim() !== "" && !isNaN(Number(threshold)) && Number(threshold) > 0 : true; function handleSubmit(e) { e.preventDefault(); if (!canSubmit) return; onSubmit({ type, threshold: needsThreshold ? Number(threshold) : undefined, }); setThreshold(""); } return (
{ALERT_TYPES.map((opt) => ( ))}
{needsThreshold && ( )}
); }