mango-ui-v2/components/TradeHistoryTable.tsx

139 lines
4.8 KiB
TypeScript
Raw Normal View History

2021-04-12 21:40:26 -07:00
import useTradeHistory from '../hooks/useTradeHistory'
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table'
import SideBadge from './SideBadge'
// import useMangoStore from '../stores/useMangoStore'
// import Loading from './Loading'
const TradeHistoryTable = () => {
2021-04-14 23:16:36 -07:00
const tradeHistory = useTradeHistory()
// const connected = useMangoStore((s) => s.wallet.connected)
const renderTradeDateTime = (timestamp) => {
const date = new Date(timestamp)
return (
<>
<div>{date.toLocaleDateString()}</div>
<div className="text-xs text-th-fgd-3">{date.toLocaleTimeString()}</div>
</>
)
}
return (
<div className={`flex flex-col py-6`}>
<div className={`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}>
<div className={`align-middle inline-block min-w-full sm:px-6 lg:px-8`}>
2021-04-13 09:57:58 -07:00
{tradeHistory && tradeHistory.length ? (
<div
2021-04-12 21:40:26 -07:00
className={`shadow overflow-hidden border-b border-th-bkg-2 sm:rounded-md`}
>
<Table className={`min-w-full divide-y divide-th-bkg-2`}>
<Thead>
<Tr>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Market
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Side
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Size
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Price
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Liquidity
</Th>
<Th
scope="col"
className={`px-6 py-3 text-left font-normal`}
>
2021-04-12 21:40:26 -07:00
Fees
</Th>
<Th
2021-04-13 16:41:04 -07:00
scope="col"
className={`px-6 py-3 text-left font-normal`}
2021-04-13 16:41:04 -07:00
>
2021-04-22 08:43:20 -07:00
Approx Date/Time
</Th>
</Tr>
</Thead>
<Tbody>
2021-04-12 21:40:26 -07:00
{tradeHistory.map((trade, index) => (
<Tr
2021-04-14 23:16:36 -07:00
key={`${trade.orderId}${trade.side}${trade.uuid}`}
className={`border-b border-th-bkg-3
2021-04-13 16:41:04 -07:00
${index % 2 === 0 ? `bg-th-bkg-3` : `bg-th-bkg-2`}
`}
>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
2021-04-12 21:40:26 -07:00
{trade.marketName}
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
<SideBadge side={trade.side} />
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
2021-04-12 21:40:26 -07:00
{trade.size}
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
2021-04-12 21:40:26 -07:00
{trade.price}
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
2021-04-12 21:40:26 -07:00
{trade.liquidity}
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
>
2021-04-12 21:40:26 -07:00
{trade.feeCost}
</Td>
<Td
className={`px-6 py-4 whitespace-nowrap text-sm text-th-fgd-1`}
2021-04-13 16:41:04 -07:00
>
{trade.loadTimestamp
? renderTradeDateTime(trade.loadTimestamp)
2021-04-13 16:41:04 -07:00
: 'Recent'}
</Td>
</Tr>
))}
</Tbody>
</Table>
</div>
) : (
<div
2021-04-19 06:45:59 -07:00
className={`w-full text-center py-6 bg-th-bkg-1 text-th-fgd-3 rounded-md`}
>
No trade history
</div>
)}
</div>
</div>
</div>
)
}
export default TradeHistoryTable