({ accountId }: { accountId: string })
| 2 | import { api } from '../api' |
| 3 | |
| 4 | export function ReconnectButton({ accountId }: { accountId: string }) { |
| 5 | const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle') |
| 6 | const [message, setMessage] = useState('') |
| 7 | const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null) |
| 8 | |
| 9 | useEffect(() => () => { if (timerRef.current) clearTimeout(timerRef.current) }, []) |
| 10 | |
| 11 | const handleReconnect = async () => { |
| 12 | setStatus('loading') |
| 13 | setMessage('') |
| 14 | try { |
| 15 | const result = await api.trading.reconnectUTA(accountId) |
| 16 | if (result.success) { |
| 17 | setStatus('success') |
| 18 | setMessage(result.message || 'Connected') |
| 19 | timerRef.current = setTimeout(() => setStatus('idle'), 3000) |
| 20 | } else { |
| 21 | setStatus('error') |
| 22 | setMessage(result.error || 'Connection failed') |
| 23 | } |
| 24 | } catch (err) { |
| 25 | setStatus('error') |
| 26 | setMessage(err instanceof Error ? err.message : 'Connection failed') |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // No outer margin here — spacing belongs to the call site (this rides in |
| 31 | // the page-header action row AND in the edit dialog; a baked-in mt-3 was |
| 32 | // what knocked the header buttons out of alignment). |
| 33 | return ( |
| 34 | <div className="flex items-center gap-2"> |
| 35 | <button |
| 36 | onClick={handleReconnect} |
| 37 | disabled={status === 'loading'} |
| 38 | className="btn-secondary-sm" |
| 39 | > |
| 40 | {status === 'loading' ? 'Connecting...' : 'Reconnect'} |
| 41 | </button> |
| 42 | {status === 'success' && <span className="text-[12px] text-green">{message}</span>} |
| 43 | {status === 'error' && <span className="text-[12px] text-red">{message}</span>} |
| 44 | </div> |
| 45 | ) |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected