import useSWR from "swr"; import toast from "react-hot-toast"; import { useMemo, useEffect, useState } from "react"; import "./Sidebar.scss"; import { Box, Grid, Link, Paper, SvgIcon, Typography, Divider, Accordion, AccordionSummary, AccordionDetails, } from "@mui/material"; import { styled } from "@mui/material/styles"; import { NavLink, useLocation } from "react-router-dom"; import { useSwitchChain } from "wagmi"; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import GitHubIcon from '@mui/icons-material/GitHub'; import XIcon from '@mui/icons-material/X'; import TelegramIcon from '@mui/icons-material/Telegram'; import HowToVoteIcon from '@mui/icons-material/HowToVote'; import HubIcon from '@mui/icons-material/Hub'; import PublicIcon from '@mui/icons-material/Public'; import ForkRightIcon from '@mui/icons-material/ForkRight'; import GavelIcon from '@mui/icons-material/Gavel'; import HistoryIcon from '@mui/icons-material/History'; import CasinoIcon from '@mui/icons-material/Casino'; import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; import BookIcon from '@mui/icons-material/Book'; import CurrencyExchangeIcon from '@mui/icons-material/CurrencyExchange'; import MergeIcon from '@mui/icons-material/Merge'; import RampLeftIcon from '@mui/icons-material/RampLeft'; import RouteIcon from '@mui/icons-material/Route'; import GhostIcon from "../../assets/icons/ghost-nav-header.svg?react"; import NavItem from "../NavItem/NavItem"; import GhostStyledIcon from "../Icon/GhostIcon"; import DiscordIcon from "../Icon/DiscordIcon"; import BondIcon from "../Icon/BondIcon"; import StakeIcon from "../Icon/StakeIcon"; import WrapIcon from "../Icon/WrapIcon"; import { isNetworkAvailable, negativeBridgeNumbers, bridgeNumbers } from "../../constants"; import { AVAILABLE_DEXES } from "../../constants/dexes"; import { ECOSYSTEM } from "../../constants/ecosystem"; import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; import { sortBondsByDiscount, formatCurrency } from "../../helpers"; import BondDiscount from "../../containers/Bond/components/BondDiscount"; import Chip from "../Chip/Chip"; import DashboardIcon from '@mui/icons-material/Dashboard'; import ShowerIcon from '@mui/icons-material/Shower'; import WifiProtectedSetupIcon from '@mui/icons-material/WifiProtectedSetup'; import { useTokenSymbol } from "../../hooks/tokens"; import { useLiveBonds } from "../../hooks/bonds/index"; import { useLocalStorage } from "../../hooks/localstorage"; import { useUnstableProvider } from "../../hooks/ghost"; import pckg from "../../../package.json" const PREFIX = "NavContent"; const classes = { gray: `${PREFIX}-gray`, }; const StyledBox = styled(Box)(({ theme }) => ({ [`& .${classes.gray}`]: { color: theme.colors.gray[90], }, })); const NavContent = ({ chainId, addressChainId, address }) => { const location = useLocation(); const { chains } = useSwitchChain(); const chainName = useMemo(() => { return chains.find(chain => chain.id === chainId).name.toLowerCase(); }, [chains, chainId, addressChainId]); const [pendingExoduses, setPendingExoduses] = useState(0); const [signedExoduses, setSignedExoduses] = useState(0); const { useStorageValue, CONSTANTS } = useLocalStorage(); const { casperApi } = useUnstableProvider(); const { liveBonds: ghostBonds } = useLiveBonds(chainId); const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO"); const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST"); const { data: pendingHistory } = useStorageValue(chainId, address, CONSTANTS.pendingHistoryPrefix, {}) const pendingTransactions = useMemo(() => { if (!pendingHistory) return null; const count = Object.values(pendingHistory).reduce((sum, count) => sum + count, 0); return count > 0 ? count: null; }, [pendingHistory]); const sortedGhostBonds = useMemo(() => sortBondsByDiscount(ghostBonds), [ghostBonds]); const { data: counterForExodusRequest } = useSWR( casperApi ? ["counterForExodusRequest", casperApi] : null, ([_, api]) => api.query.GhostExodus.CounterForExodusRequests.getValue(), { fallbackData: 0, refetchInterval: 12000 }, ); useEffect(() => { if (pendingExoduses === counterForExodusRequest) return else if (pendingExoduses > counterForExodusRequest) { const newlySigned = pendingExoduses - counterForExodusRequest; setSignedExoduses((prev) => prev + newlySigned); setPendingExoduses(counterForExodusRequest); } else { const newlyQueued = counterForExodusRequest - pendingExoduses; const message = newlyQueued === 1 ? "GHOST Exodus request is signing now. Get ready to verify it and earn rewards!" : `${newlyQueued} GHOST Exodus requests are signing now. Get ready to verify them and earn rewards!`; toast.success(message, { autoClose: 5000 }); setPendingExoduses(counterForExodusRequest); } }, [counterForExodusRequest, pendingExoduses]); useEffect(() => { if (!location.pathname.endsWith("exodus")) return setSignedExoduses(0); }, [location]); return (
Version {pckg.version}
); }; export default NavContent;