import { Popover } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/24/solid' import Image from 'next/image' import Link from 'next/link' import { useRouter } from 'next/router' import React, { useMemo } from 'react' import BigNumber from 'bignumber.js' import ArrowRightLine from 'components/Icons/arrow-right-line.svg' import ProgressBar from 'components/ProgressBar' import SearchInput from 'components/SearchInput' import Spinner from 'components/Spinner' import Wallet from 'components/Wallet' import useCreateCreditAccount from 'hooks/mutations/useCreateCreditAccount' import useDeleteCreditAccount from 'hooks/mutations/useDeleteCreditAccount' import useAccountStats from 'hooks/useAccountStats' import useCreditAccounts from 'hooks/useCreditAccounts' import useCreditManagerStore from 'stores/useCreditManagerStore' import useWalletStore from 'stores/useWalletStore' import { formatCurrency } from 'utils/formatters' import { chain } from 'utils/chains' import Button from './Button' import SemiCircleProgress from './SemiCircleProgress' // TODO: will require some tweaks depending on how lower viewport mocks pans out const MAX_VISIBLE_CREDIT_ACCOUNTS = 5 const navItems = [ { href: '/trade', label: 'Trade' }, { href: '/earn', label: 'Earn' }, { href: '/borrow', label: 'Borrow' }, { href: '/portfolio', label: 'Portfolio' }, { href: '/council', label: 'Council' }, ] const NavLink = ({ href, children }: { href: string; children: string }) => { const router = useRouter() return ( {children} ) } const Navigation = () => { const address = useWalletStore((s) => s.address) const selectedAccount = useCreditManagerStore((s) => s.selectedAccount) const setSelectedAccount = useCreditManagerStore((s) => s.actions.setSelectedAccount) const toggleCreditManager = useCreditManagerStore((s) => s.actions.toggleCreditManager) const { data: creditAccountsList, isLoading: isLoadingCreditAccounts } = useCreditAccounts() const { mutate: createCreditAccount, isLoading: isLoadingCreate } = useCreateCreditAccount() const { mutate: deleteCreditAccount, isLoading: isLoadingDelete } = useDeleteCreditAccount( selectedAccount || '', ) const accountStats = useAccountStats() const { firstCreditAccounts, restCreditAccounts } = useMemo(() => { return { firstCreditAccounts: creditAccountsList?.slice(0, MAX_VISIBLE_CREDIT_ACCOUNTS) ?? [], restCreditAccounts: creditAccountsList?.slice(MAX_VISIBLE_CREDIT_ACCOUNTS) ?? [], } }, [creditAccountsList]) const isConnected = !!address const hasCreditAccounts = creditAccountsList && creditAccountsList.length > 0 const rightSideContent = () => { if ((!isConnected && !hasCreditAccounts) || isLoadingCreditAccounts) { return null } if (!hasCreditAccounts) { return } return (
{formatCurrency( BigNumber(accountStats.netWorth) .dividedBy(10 ** chain.stakeCurrency.coinDecimals) .toNumber(), )}
{/* TOOLTIP */}