import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Switch } from '@/components/ui/switch' import managedOutboxService from '@/services/managed-outbox.service' import relayStatsService from '@/services/relay-stats.service' import storage, { dispatchSettingsChanged } from '@/services/local-storage.service' import type { TRelayEntry } from '@/types/relay-management' import type { TOutboxMode } from '@/types/relay-management' import { Check, ChevronDown, ChevronUp, Shield, ShieldAlert, ShieldOff, X } from 'lucide-react' import { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' type RelayTab = 'pending' | 'approved' | 'rejected' function failureRateColor(rate: number): string { if (rate >= 0.99) return 'text-red-900 dark:text-red-300' if (rate > 0.5) return 'text-red-600 dark:text-red-400' if (rate > 0.1) return 'text-yellow-600 dark:text-yellow-400' return 'text-green-600 dark:text-green-400' } function RelayRow({ entry, onAction }: { entry: TRelayEntry; onAction: () => void }) { const { t } = useTranslation() const [expanded, setExpanded] = useState(false) const failureRate = relayStatsService.getFailureRate(entry.url) const autoDisabled = relayStatsService.isAutoDisabled(entry.url) return (
{t('Relays discovered via outbox model (NIP-65) are tracked here with per-network failure stats. In')} {' '}{t('Automatic')} {t('mode, all discovered relays are used unless manually excluded or auto-disabled. In')} {' '}{t('Managed')} {t('mode, relays must be explicitly approved before use.')}
{t('Approve/Reject controls whether a relay is used in managed mode. Exclude is a manual override that blocks a relay in both modes, independent of approval status. Relays with 99%+ failure rate on your current network are auto-disabled.')}
{t('Failure rates are tracked per network (based on your external IP), so a relay that fails on one connection may work fine on another.')}