import React from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faCheckCircle, faWifi, faClock, faPlane } from '@fortawesome/free-solid-svg-icons' import { RelayStatus } from '../../services/relayStatusService' import { formatDistanceToNow } from 'date-fns' import { isLocalRelay } from '../../utils/helpers' interface RelaySettingsProps { relayStatuses: RelayStatus[] onClose?: () => void } const RelaySettings: React.FC = ({ relayStatuses }) => { const formatRelayUrl = (url: string) => { return url.replace(/^wss?:\/\//, '').replace(/\/$/, '') } const formatLastSeen = (timestamp: number) => { try { return formatDistanceToNow(timestamp, { addSuffix: true }) } catch { return 'just now' } } // Sort relays: local relays first, then by connection status, then by URL const sortedRelays = [...relayStatuses].sort((a, b) => { const aIsLocal = isLocalRelay(a.url) const bIsLocal = isLocalRelay(b.url) // Local relays always first if (aIsLocal && !bIsLocal) return -1 if (!aIsLocal && bIsLocal) return 1 // Within local or remote groups, connected before disconnected if (a.isInPool !== b.isInPool) return a.isInPool ? -1 : 1 // Finally sort by URL return a.url.localeCompare(b.url) }) const getRelayIcon = (relay: RelayStatus) => { const isLocal = isLocalRelay(relay.url) const isConnected = relay.isInPool if (isLocal) { return { icon: faPlane, color: isConnected ? '#22c55e' : '#ef4444', size: '1rem' } } else { if (isConnected) { return { icon: faCheckCircle, color: '#22c55e', size: '1rem' } } else { return { icon: faWifi, color: '#ef4444', size: '1rem' } } } } return (

Relays

{sortedRelays.length > 0 && (
{sortedRelays.map((relay) => { const iconConfig = getRelayIcon(relay) const isDisconnected = !relay.isInPool return (
{formatRelayUrl(relay.url)}
{isDisconnected && (
{formatLastSeen(relay.lastSeen)}
)}
) })}
)} {relayStatuses.length === 0 && (

No relay connections found

)}
) } export default RelaySettings