import { useEffect, useState } from 'react' import useMangoStore from '../stores/useMangoStore' import dayjs from 'dayjs' import { BadgeCheckIcon, BellIcon, InformationCircleIcon, LinkIcon, PlusCircleIcon, TrashIcon, } from '@heroicons/react/outline' import { RadioGroup } from '@headlessui/react' import useAlertsStore from '../stores/useAlertsStore' import useLocalStorageState from '../hooks/useLocalStorageState' import TopBar from '../components/TopBar' import Button, { LinkButton } from '../components/Button' import AlertsModal from '../components/AlertsModal' import AlertItem from '../components/AlertItem' import PageBodyContainer from '../components/PageBodyContainer' import EmptyState from '../components/EmptyState' import Select from '../components/Select' import { abbreviateAddress } from '../utils' const relativeTime = require('dayjs/plugin/relativeTime') dayjs.extend(relativeTime) const TABS = ['Active', 'Triggered'] export default function Alerts() { const connected = useMangoStore((s) => s.wallet.connected) const marginAccounts = useMangoStore((s) => s.marginAccounts) const [activeTab, setActiveTab] = useState(TABS[0]) const [openAlertModal, setOpenAlertModal] = useState(false) const [reactivateAlertData, setReactivateAlertData] = useState(null) const [acc, setAcc] = useState('All') const [filteredActiveAlerts, setFilteredActiveAlerts] = useState([]) const [filteredTriggeredAlerts, setFilteredTriggeredAlerts] = useState([]) const activeAlerts = useAlertsStore((s) => s.activeAlerts) const triggeredAlerts = useAlertsStore((s) => s.triggeredAlerts) const loading = useAlertsStore((s) => s.loading) const [clearedAlerts, setClearedAlerts] = useState([]) const [clearAlertsTimestamp, setClearAlertsTimestamp] = useLocalStorageState( 'clearAlertsTimestamp' ) useEffect(() => { if (!connected || loading) { setAcc('All') } }, [connected, loading]) useEffect(() => { if (clearAlertsTimestamp && !loading) { const filterByTimestamp = triggeredAlerts.filter( (alert) => alert.triggeredTimestamp > clearAlertsTimestamp && Object.keys(alert).includes('triggeredTimestamp') ) setClearedAlerts(filterByTimestamp) } }, [clearAlertsTimestamp, loading]) const handleTabChange = (tabName) => { setActiveTab(tabName) } const handleAccountChange = (val) => { if (val !== 'All') { setAcc(val) const showActive = activeAlerts.filter( (alert) => alert.acc.toString() === val ) const showTriggered = clearAlertsTimestamp ? clearedAlerts.filter((alert) => alert.acc.toString() === val) : triggeredAlerts.filter((alert) => alert.acc.toString() === val) setFilteredActiveAlerts(showActive) setFilteredTriggeredAlerts(showTriggered) } else { setAcc(val) } } return (
Get notified when your account is in danger of liquidation.
Active alerts will only trigger once.
None of your active liquidation alerts have been triggered.
Re-activate alerts you want to receive again.