import { ArrowSmDownIcon } from '@heroicons/react/solid' import BN from 'bn.js' import Link from 'next/link' import { useRouter } from 'next/router' import SideBadge from './SideBadge' import { LinkButton } from './Button' import { useSortableData } from '../hooks/useSortableData' import { useViewport } from '../hooks/useViewport' import { breakpoints } from './TradePageGrid' import { Table, TableDateDisplay, Td, Th, TrBody, TrHead, } from './TableElements' import { ExpandableRow } from './TableElements' import { formatUsdValue } from '../utils' import { useTranslation } from 'next-i18next' import Pagination from './Pagination' import usePagination from '../hooks/usePagination' import { useEffect } from 'react' import useMangoStore from '../stores/useMangoStore' const formatTradeDateTime = (timestamp: BN | string) => { // don't compare to BN because of npm maddness // prototypes can be different due to multiple versions being imported if (typeof timestamp === 'string') { return timestamp } else { return timestamp.toNumber() * 1000 } } const TradeHistoryTable = ({ numTrades }: { numTrades?: number }) => { const { t } = useTranslation('common') const { asPath } = useRouter() const { width } = useViewport() const tradeHistoryAndLiquidations = useMangoStore( (state) => state.tradeHistory.parsed ) const tradeHistory = tradeHistoryAndLiquidations.filter( (t) => !('liqor' in t) ) const isMobile = width ? width < breakpoints.md : false const { paginatedData, totalPages, nextPage, previousPage, page, firstPage, lastPage, setData, data, } = usePagination(tradeHistory || [], { perPage: 100 }) const { items, requestSort, sortConfig } = useSortableData(paginatedData) useEffect(() => { if (tradeHistory?.length && data?.length !== tradeHistory?.length) { setData(tradeHistory) } }, [tradeHistory]) const renderMarketName = (trade: any) => { if ( trade.marketName.includes('PERP') || trade.marketName.includes('USDC') ) { const location = `/?name=${trade.marketName}` if (asPath.includes(location)) { return {trade.marketName} } else { return ( {trade.marketName} ) } } else { return {trade.marketName} } } return (
|
|
|
|
|
|
|
|
{renderMarketName(trade)}
|
|
{trade.size} | $ {new Intl.NumberFormat('en-US').format(trade.price)} | {formatUsdValue(trade.value)} | {t(trade.liquidity.toLowerCase())} | {formatUsdValue(trade.feeCost)} |
{trade.loadTimestamp || trade.timestamp ? (
|
{trade.marketName.includes('PERP') ? ( {t('view-counterparty')} ) : null} |
---|