import { ArrowSmDownIcon } from '@heroicons/react/solid' import BN from 'bn.js' import useTradeHistory from '../hooks/useTradeHistory' 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, Td, Th, TrBody, TrHead } from './TableElements' import { ExpandableRow } from './TableElements' import { formatUsdValue } from '../utils' const TradeHistoryTable = ({ numTrades }: { numTrades?: number }) => { const { asPath } = useRouter() const tradeHistory = useTradeHistory({ excludePerpLiquidations: true }) const { items, requestSort, sortConfig } = useSortableData(tradeHistory) const { width } = useViewport() const isMobile = width ? width < breakpoints.md : false const renderTradeDateTime = (timestamp: BN | string) => { let date // don't compare to BN because of npm maddness // prototypes can be different due to multiple versions being imported if (typeof timestamp === 'string') { date = new Date(timestamp) } else { date = new Date(timestamp.toNumber() * 1000) } return ( <>
{date.toLocaleDateString()}
{date.toLocaleTimeString()}
) } const filteredTrades = numTrades ? items.slice(0, numTrades) : items return (
{tradeHistory && tradeHistory.length ? ( !isMobile ? ( {filteredTrades.map((trade: any, index) => ( ))}
requestSort('market')} > Market requestSort('side')} > Side requestSort('size')} > Size requestSort('price')} > Price requestSort('value')} > Value requestSort('liquidity')} > Liquidity requestSort('feeCost')} > Fee requestSort('loadTimestamp')} > Approx Time
{trade.marketName}
{trade.size} {formatUsdValue(trade.price)} {formatUsdValue(trade.value)} {trade.liquidity} {formatUsdValue(trade.feeCost)} {trade.loadTimestamp || trade.timestamp ? renderTradeDateTime( trade.loadTimestamp || trade.timestamp ) : 'Recent'}
) : ( items.map((trade: any, index) => (
{trade.marketName}
{trade.side.toUpperCase()} {`${trade.size} at ${formatUsdValue( trade.price )}`}
} key={`${index}`} index={index} panelTemplate={ <>
Value
{formatUsdValue(trade.value)}
Liquidity
{trade.liquidity}
Fee
{formatUsdValue(trade.feeCost)}
Approx Time
{trade.loadTimestamp || trade.timestamp ? renderTradeDateTime( trade.loadTimestamp || trade.timestamp ) : 'Recent'}
} /> )) ) ) : (
No trade history {asPath === '/account' ? ( Make a trade ) : null}
)}
{numTrades && items.length > numTrades ? (
View all trades in the Account page
) : null}
) } export default TradeHistoryTable