// Hooks import { useEffect, useState } from 'react' import { useTranslation } from 'next-i18next' // Components import { Spinner } from 'shared/components/spinner.mjs' import { WarningIcon } from 'shared/components/icons.mjs' // Update this when more translations are added const messages = 11 // Gets a random id for a loading message const msg = () => Math.floor(Math.random() * messages) export const Hodl = ({ delay = 1.25, step = 2, noTitle = false }) => { const { t } = useTranslation(['hodl']) const [fade, setFade] = useState('opacity-100') const [tick, setTick] = useState(0) const [loadingStatus, setLoadingStatus] = useState([true, t('hodl:oneMoment')]) const [shown, setShown] = useState({}) useEffect(() => { if (tick > 0 && tick < 10) { let newMsg do { newMsg = msg() } while (typeof shown[newMsg] !== 'undefined') setLoadingStatus([true, t(`hodl:${newMsg}`)]) const newShown = { ...shown } shown[newMsg] = true setShown(newShown) } else if (tick > 0) setLoadingStatus([true, t(`hodl:giveUp`), true]) }, [tick]) useEffect(() => { if (loadingStatus[1]) { if (loadingStatus[2]) { window.setTimeout(() => { setFade('opacity-0') }, 2000 * delay) } else { window.setTimeout(() => { setTick(tick + step) }, 1000 * delay) } } }, [loadingStatus[1]]) if (!loadingStatus[1]) return null return ( <> {!noTitle &&