import { useCallback, useEffect, useState } from 'react' import { ChevronDownIcon, NoSymbolIcon } from '@heroicons/react/20/solid' import dayjs from 'dayjs' import { useTranslation } from 'next-i18next' import Image from 'next/legacy/image' import { breakpoints } from '../../utils/theme' import { useViewport } from '../../hooks/useViewport' import { LinkButton } from '../shared/Button' import { Disclosure, Transition } from '@headlessui/react' import SheenLoader from '../shared/SheenLoader' import mangoStore from '@store/mangoStore' import { countLeadingZeros, floorToDecimal } from '../../utils/numbers' import useLocalStorageState from 'hooks/useLocalStorageState' import { PAGINATION_PAGE_LENGTH, PREFERRED_EXPLORER_KEY } from 'utils/constants' import Tooltip from '@components/shared/Tooltip' import { formatTokenSymbol } from 'utils/tokens' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' import useMangoAccount from 'hooks/useMangoAccount' import ConnectEmptyState from '@components/shared/ConnectEmptyState' import { useWallet } from '@solana/wallet-adapter-react' import FormatNumericValue from '@components/shared/FormatNumericValue' import useMangoGroup from 'hooks/useMangoGroup' import TokenLogo from '@components/shared/TokenLogo' const SwapHistoryTable = () => { const { t } = useTranslation(['common', 'settings', 'swap']) const swapHistory = mangoStore((s) => s.mangoAccount.swapHistory.data) const loadSwapHistory = mangoStore((s) => s.mangoAccount.swapHistory.loading) const { group } = useMangoGroup() const [offset, setOffset] = useState(0) const actions = mangoStore.getState().actions const { mangoAccountAddress } = useMangoAccount() const { connected } = useWallet() const { width } = useViewport() const showTableView = width ? width > breakpoints.md : false const [preferredExplorer] = useLocalStorageState( PREFERRED_EXPLORER_KEY, EXPLORERS[0], ) useEffect(() => { if (mangoAccountAddress) { actions.fetchSwapHistory(mangoAccountAddress) setOffset(0) } }, [actions, mangoAccountAddress]) const handleShowMore = useCallback(() => { const set = mangoStore.getState().set set((s) => { s.mangoAccount.swapHistory.loading = true }) if (!mangoAccountAddress) return setOffset(offset + PAGINATION_PAGE_LENGTH) actions.fetchSwapHistory( mangoAccountAddress, 0, offset + PAGINATION_PAGE_LENGTH, ) }, [actions, offset, mangoAccountAddress]) return group && mangoAccountAddress && (swapHistory.length || loadSwapHistory) ? ( <> {showTableView ? (
{t('date')} | {t('swap:paid')} | {t('swap:received')} | {t('value')} | {t('borrow')} |
|
{dayjs(block_datetime).format('ddd D MMM')} {dayjs(block_datetime).format('h:mma')} |
|
|
|
{borrowAmount} {inSymbol} |
{borrowFee} {inSymbol} |
---|
{dayjs(block_datetime).format('ddd D MMM')}
{dayjs(block_datetime).format('h:mma')}
{t('value')}
{t('borrow')}
{borrowAmount}{' '} {inSymbol}
{t('borrow-fee')}
${borrowFee}
{t('transaction')}
{t('swap:no-history')}