import { Fragment, useCallback, useEffect, useMemo, useState } from 'react' import { CheckCircleIcon, ArrowTopRightOnSquareIcon, InformationCircleIcon, XCircleIcon, XMarkIcon, } from '@heroicons/react/20/solid' import mangoStore, { CLUSTER } from '@store/mangoStore' import { Notification, notify } from '../../utils/notifications' import Loading from './Loading' import { Transition } from '@headlessui/react' import { CLIENT_TX_TIMEOUT, NOTIFICATION_POSITION_KEY, PREFERRED_EXPLORER_KEY, } from '../../utils/constants' import useLocalStorageState from 'hooks/useLocalStorageState' import { EXPLORERS } from 'pages/settings' import { useTranslation } from 'next-i18next' import useSolBalance from 'hooks/useSolBalance' const setMangoStore = mangoStore.getState().set const NotificationList = () => { const { t } = useTranslation() const notifications = mangoStore((s) => s.notifications) const walletTokens = mangoStore((s) => s.wallet.tokens) const notEnoughSoLMessage = t('deposit-more-sol') const [notificationPosition] = useLocalStorageState( NOTIFICATION_POSITION_KEY, 'bottom-left' ) const [mounted, setMounted] = useState(false) const { maxSolDeposit } = useSolBalance() // if a notification is shown with {"InstructionError":[0,{"Custom":1}]} then // add a notification letting the user know they may not have enough SOL useEffect(() => { if (notifications.length) { const customErrorNotification = notifications.find( (n) => n.description && n.description.includes('"Custom":1') ) const notEnoughSolNotification = notifications.find( (n) => n.title && n.title.includes(notEnoughSoLMessage) ) if ( !notEnoughSolNotification && customErrorNotification && maxSolDeposit <= 0 ) { notify({ title: notEnoughSoLMessage, type: 'info', }) } } }, [notifications, walletTokens, maxSolDeposit]) const clearAll = useCallback(() => { setMangoStore((s) => { const newNotifications = s.notifications.map((n) => ({ ...n, show: false, })) s.notifications = newNotifications }) }, [notifications]) const reversedNotifications = [...notifications].reverse() const position: string = useMemo(() => { switch (notificationPosition) { case 'bottom-left': return 'bottom-0 left-0' case 'bottom-right': return 'bottom-0 right-0' case 'top-left': return 'top-0 left-0' case 'top-right': return 'top-0 right-0' default: return 'bottom-0 left-0' } }, [notificationPosition]) useEffect(() => setMounted(true), []) if (!mounted) return null return (
{parsedTitle || title}
{description ? ({description}
) : null} {txid ? (