From 8d3e8d7783c858dc415084a58514c77389a3d482 Mon Sep 17 00:00:00 2001 From: sehyunc <41171808+sehyunc@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:31:36 -0700 Subject: [PATCH] order table: display "Undercapitalized" text if order cannot be filled --- app/orders/columns.tsx | 86 ++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/app/orders/columns.tsx b/app/orders/columns.tsx index e2b3d8f1..354917f4 100644 --- a/app/orders/columns.tsx +++ b/app/orders/columns.tsx @@ -1,4 +1,4 @@ -import { OrderState, Token } from "@renegade-fi/react" +import { OrderState, Token, useBackOfQueueWallet } from "@renegade-fi/react" import { ColumnDef, RowData } from "@tanstack/react-table" import { ChevronDown, ChevronUp, ChevronsUpDown } from "lucide-react" import { formatUnits } from "viem/utils" @@ -105,12 +105,25 @@ export const columns: ColumnDef[] = [ id: "status", accessorKey: "state", header: () =>
Status
, - cell: ({ row }) => { - return ( -
- {formatOrderState[row.getValue("status")]} -
- ) + cell: function Cell({ row }) { + const { data: isCapitalized } = useBackOfQueueWallet({ + query: { + select: (data) => + data.balances.some( + (balance) => + balance.mint === + (row.original.data.side === "Buy" + ? row.original.data.quote_mint + : row.original.data.base_mint) && + balance.amount > BigInt(0), + ), + }, + }) + let status: string = formatOrderState[row.getValue("status")] + if (!isCapitalized && status === "Open") { + status = "Undercapitalized" + } + return
{status}
}, filterFn: (row, _, filterValue) => { if (filterValue === "open") { @@ -259,7 +272,7 @@ export const columns: ColumnDef[] = [ return row.fills.reduce((acc, fill) => acc + fill.amount, BigInt(0)) }, header: () =>
Filled
, - cell: ({ row }) => { + cell: function Cell({ row }) { const filledAmount = row.getValue("filled") const totalAmount = row.getValue("amount") const percentageFilled = @@ -272,28 +285,43 @@ export const columns: ColumnDef[] = [ Number(filledAmount), Number(totalAmount), ) - return ( - <> - {!row.original.fills.length && - row.original.state !== OrderState.Cancelled ? ( -
- Finding counterparties - -
- ) : ( -
- {percentageFilledNumber ? ( - - ) : ( - <> - )} -
- {percentageFilledLabel} -
+ const { data: isCapitalized } = useBackOfQueueWallet({ + query: { + select: (data) => + data.balances.some( + (balance) => + balance.mint === + (row.original.data.side === "Buy" + ? row.original.data.quote_mint + : row.original.data.base_mint) && + balance.amount > BigInt(0), + ), + }, + }) + if ( + row.original.fills.length || + row.original.state === OrderState.Cancelled + ) { + return ( +
+ {percentageFilledNumber ? ( + + ) : ( + <> + )} +
+ {percentageFilledLabel}
- )} - - ) +
+ ) + } else if (isCapitalized) { + return ( +
+ Finding counterparties + +
+ ) + } }, }, {