mango-ui-v3/components/OpenOrdersTable.tsx

112 lines
4.2 KiB
TypeScript
Raw Normal View History

2021-04-05 14:38:59 -07:00
import xw from 'xwind'
import { TrashIcon } from '@heroicons/react/solid'
import { useOpenOrders } from '../hooks/useOpenOrders'
2021-04-05 14:38:59 -07:00
const OpenOrdersTable = () => {
const openOrders = useOpenOrders()
2021-04-05 14:38:59 -07:00
return (
<div css={xw`flex flex-col py-6`}>
<div css={xw`-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8`}>
<div css={xw`align-middle inline-block min-w-full sm:px-6 lg:px-8`}>
2021-04-11 21:17:23 -07:00
{openOrders && openOrders.length > 0 ? (
<div
css={xw`shadow overflow-hidden border-b border-mango-dark-light sm:rounded-md`}
>
<table css={xw`min-w-full divide-y divide-mango-dark-light`}>
<thead>
<tr>
<th
scope="col"
css={xw`px-6 py-3 text-left text-base font-medium text-gray-300 tracking-wider`}
2021-04-05 14:38:59 -07:00
>
Market
</th>
<th
scope="col"
css={xw`px-6 py-3 text-left text-base font-medium text-gray-300 tracking-wider`}
2021-04-05 14:38:59 -07:00
>
Side
</th>
<th
scope="col"
css={xw`px-6 py-3 text-left text-base font-medium text-gray-300 tracking-wider`}
2021-04-05 14:38:59 -07:00
>
Size
</th>
<th
scope="col"
css={xw`px-6 py-3 text-left text-base font-medium text-gray-300 tracking-wider`}
2021-04-05 14:38:59 -07:00
>
Price
</th>
<th scope="col" css={xw`relative px-6 py-3`}>
<span css={xw`sr-only`}>Edit</span>
</th>
</tr>
</thead>
<tbody>
{openOrders.map((order, index) => (
<tr
key={`${order.orderId}${order.side}`}
css={
index % 2 === 0
? xw`bg-mango-dark-light`
: xw`bg-mango-dark-lighter`
}
2021-04-05 14:38:59 -07:00
>
<td
css={xw`px-6 py-4 whitespace-nowrap text-sm text-gray-300 font-light`}
2021-04-05 14:38:59 -07:00
>
{order.marketName}
</td>
<td
css={xw`px-6 py-4 whitespace-nowrap text-sm text-gray-300 font-light`}
>
<div
css={xw`rounded inline-block bg-mango-green px-2 py-1 text-mango-dark font-bold`}
>
{order.side.toUpperCase()}
</div>
</td>
<td
css={xw`px-6 py-4 whitespace-nowrap text-sm text-gray-300 font-light`}
>
{order.size}
</td>
<td
css={xw`px-6 py-4 whitespace-nowrap text-sm text-gray-300 font-light`}
>
{order.price}
</td>
<td
css={xw`px-6 py-4 opacity-75 whitespace-nowrap text-right text-sm font-medium`}
>
<button
onClick={() => alert('cancel order')}
css={xw`flex items-center ml-auto text-mango-red border border-mango-red hover:text-red-700 hover:border-red-700 py-1 px-4`}
>
<TrashIcon css={xw`h-5 w-5 mr-1`} />
<span>Cancel Order</span>
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
) : (
<div
2021-04-12 06:32:01 -07:00
css={xw`w-full text-center py-6 text-base bg-th-bkg-1 font-light text-th-fgd-4 rounded-md`}
>
No open orders
</div>
)}
2021-04-05 14:38:59 -07:00
</div>
</div>
</div>
)
}
export default OpenOrdersTable