import { PerpMarket } from '@blockworks-foundation/mango-v4' import { IconButton, LinkButton } from '@components/shared/Button' import ConnectEmptyState from '@components/shared/ConnectEmptyState' import FormatNumericValue from '@components/shared/FormatNumericValue' import SheenLoader from '@components/shared/SheenLoader' import SideBadge from '@components/shared/SideBadge' import { Table, TableDateDisplay, Td, Th, TrBody, TrHead, } from '@components/shared/TableElements' import Tooltip from '@components/shared/Tooltip' import { NoSymbolIcon, UsersIcon } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import { PublicKey } from '@solana/web3.js' import mangoStore from '@store/mangoStore' import dayjs from 'dayjs' import useMangoAccount from 'hooks/useMangoAccount' import useSelectedMarket from 'hooks/useSelectedMarket' import useTradeHistory from 'hooks/useTradeHistory' import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import { PAGINATION_PAGE_LENGTH } from 'utils/constants' import { abbreviateAddress } from 'utils/formatting' import { breakpoints } from 'utils/theme' import MarketLogos from './MarketLogos' import PerpSideBadge from './PerpSideBadge' import TableMarketName from './TableMarketName' const TradeHistory = () => { const { t } = useTranslation(['common', 'trade']) const group = mangoStore.getState().group const { selectedMarket } = useSelectedMarket() const { mangoAccountAddress } = useMangoAccount() const { data: combinedTradeHistory, isLoading: loadingTradeHistory, fetchNextPage, } = useTradeHistory() const { width } = useViewport() const { connected } = useWallet() const showTableView = width ? width > breakpoints.md : false if (!selectedMarket || !group) return null return mangoAccountAddress && (combinedTradeHistory.length || loadingTradeHistory) ? ( <> {showTableView ? (
{combinedTradeHistory.map((trade, index: number) => { const { side, price, market, size, feeCost, liquidity } = trade return ( ) })}
{t('market')} {t('trade:size')} {t('price')} {t('value')} {t('fee')} {t('date')}
{size}

{liquidity}

{trade?.time ? ( ) : ( 'Recent' )} {'taker' in trade ? ( ) : null}
) : (
{combinedTradeHistory.map((trade, index: number) => { const { side, price, market, size, liquidity } = trade return (

{dayjs(trade?.time ? trade.time : Date.now()).format( 'ddd D MMM' )}

{trade?.time ? dayjs(trade.time).format('h:mma') : 'Recent'}

{market.name} {market instanceof PerpMarket ? ( ) : ( )}

{size} {' at '}

{'taker' in trade ? ( ) : null}
) })}
)} {loadingTradeHistory ? (
{[...Array(4)].map((x, i) => (
))}
) : null} {combinedTradeHistory.length && combinedTradeHistory.length % PAGINATION_PAGE_LENGTH === 0 ? (
fetchNextPage()}>Show More
) : null} ) : mangoAccountAddress || connected ? (

No trade history

) : (
) } export default TradeHistory