import { useRouter } from 'next/router' import LogMessage from './log-message' import { useWalletLogger, useWalletLogs } from './logger' import { useEffect, useRef, useState } from 'react' import { Checkbox, Form } from './form' import { useField } from 'formik' import styles from '@/styles/log.module.css' import { Button } from 'react-bootstrap' import { useToast } from './toast' import { useShowModal } from './modal' const FollowCheckbox = ({ value, ...props }) => { const [,, helpers] = useField(props.name) useEffect(() => { helpers.setValue(value) }, [value]) return ( ) } export default function WalletLogs ({ wallet, embedded }) { const logs = useWalletLogs(wallet) const router = useRouter() const { follow: defaultFollow } = router.query const [follow, setFollow] = useState(defaultFollow ?? true) const tableRef = useRef() const scrollY = useRef() const showModal = useShowModal() useEffect(() => { if (follow) { tableRef.current?.scroll({ top: tableRef.current.scrollHeight, behavior: 'smooth' }) } }, [logs, follow]) useEffect(() => { function onScroll (e) { const y = e.target.scrollTop const down = y - scrollY.current >= -1 if (!!scrollY.current && !down) { setFollow(false) } const maxY = e.target.scrollHeight - e.target.clientHeight const dY = maxY - y const isBottom = dY >= -1 && dY <= 1 if (isBottom) { setFollow(true) } scrollY.current = y } tableRef.current?.addEventListener('scroll', onScroll) return () => tableRef.current?.removeEventListener('scroll', onScroll) }, []) return ( <>
{ showModal(onClose => ) }} >clear
------ start of logs ------
{logs.length === 0 &&
empty
} {logs.map((log, i) => )}
) } function DeleteWalletLogsObstacle ({ wallet, onClose }) { const toaster = useToast() const { deleteLogs } = useWalletLogger(wallet) const prompt = `Do you really want to delete all ${wallet ? '' : 'wallet'} logs ${wallet ? 'of this wallet' : ''}?` return (
{prompt}
cancel
) }