diff --git a/app/orders/columns.tsx b/app/orders/columns.tsx index fc1f3869..2a8a9223 100644 --- a/app/orders/columns.tsx +++ b/app/orders/columns.tsx @@ -14,11 +14,11 @@ import { TooltipTrigger, } from "@/components/ui/tooltip" -import { useCheckInsufficientBalancesForOrder } from "@/hooks/use-check-insufficient-balances-for-order" +import { useIsOrderUndercapitalized } from "@/hooks/use-is-order-undercapitalized" import { ExtendedOrderMetadata } from "@/hooks/use-order-table-data" import { useSavingsAcrossFillsQuery } from "@/hooks/use-savings-across-fills-query" import { Side } from "@/lib/constants/protocol" -import { INSUFFICIENT_BALANCE_TOOLTIP } from "@/lib/constants/tooltips" +import { UNDERCAPITALIZED_ORDER_TOOLTIP } from "@/lib/constants/tooltips" import { formatCurrency, formatNumber, @@ -63,7 +63,7 @@ export const columns: ColumnDef[] = [ const remainingAmount = row.original.data.amount - row.original.fills.reduce((acc, fill) => acc + fill.amount, BigInt(0)) - const { isInsufficient } = useCheckInsufficientBalancesForOrder({ + const { isUndercapitalized } = useIsOrderUndercapitalized({ amount: remainingAmount, baseMint: row.original.data.base_mint, quoteMint: row.original.data.quote_mint, @@ -81,7 +81,7 @@ export const columns: ColumnDef[] = [ OrderState.Matching, OrderState.SettlingMatch, ].includes(row.original.state) && - isInsufficient + isUndercapitalized ) { return (
@@ -91,7 +91,7 @@ export const columns: ColumnDef[] = [

- {INSUFFICIENT_BALANCE_TOOLTIP({ ticker: token.ticker })} + {UNDERCAPITALIZED_ORDER_TOOLTIP({ ticker: token.ticker })}

@@ -106,21 +106,17 @@ export const columns: ColumnDef[] = [ accessorKey: "state", header: () =>
Status
, cell: function Cell({ row }) { - const { data: isUndercapitalized } = 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 > row.original.data.amount, - ), - }, + const remainingAmount = + row.original.data.amount - + row.original.fills.reduce((acc, fill) => acc + fill.amount, BigInt(0)) + const { isUndercapitalized } = useIsOrderUndercapitalized({ + amount: remainingAmount, + baseMint: row.original.data.base_mint, + quoteMint: row.original.data.quote_mint, + side: row.original.data.side === "Buy" ? Side.BUY : Side.SELL, }) let status: string = formatOrderState[row.getValue("status")] - if (!isUndercapitalized && status === "Open") { + if (isUndercapitalized && status === "Open") { status = "Undercapitalized" } return
{status}
@@ -285,7 +281,8 @@ export const columns: ColumnDef[] = [ Number(filledAmount), Number(totalAmount), ) - const { data: isCapitalized } = useBackOfQueueWallet({ + // TODO: Check if amount > MIN_FILL_SIZE + const { data: isMatchable } = useBackOfQueueWallet({ query: { select: (data) => data.balances.some( @@ -314,7 +311,7 @@ export const columns: ColumnDef[] = [
) - } else if (isCapitalized) { + } else if (isMatchable) { return (
Finding counterparties diff --git a/app/trade/[base]/components/order-details/insufficient-warning.tsx b/app/trade/[base]/components/order-details/insufficient-warning.tsx index 896e088a..671055e0 100644 --- a/app/trade/[base]/components/order-details/insufficient-warning.tsx +++ b/app/trade/[base]/components/order-details/insufficient-warning.tsx @@ -8,9 +8,9 @@ import { ResponsiveTooltipTrigger, } from "@/components/ui/responsive-tooltip" -import { useCheckInsufficientBalancesForOrder } from "@/hooks/use-check-insufficient-balances-for-order" +import { useIsOrderUndercapitalized } from "@/hooks/use-is-order-undercapitalized" import { Side } from "@/lib/constants/protocol" -import { INSUFFICIENT_BALANCE_TOOLTIP } from "@/lib/constants/tooltips" +import { UNDERCAPITALIZED_ORDER_TOOLTIP } from "@/lib/constants/tooltips" import { cn } from "@/lib/utils" export function InsufficientWarning({ @@ -30,14 +30,14 @@ export function InsufficientWarning({ side: Side withDialog?: boolean }) { - const { isInsufficient, token } = useCheckInsufficientBalancesForOrder({ + const { isUndercapitalized, token } = useIsOrderUndercapitalized({ amount, baseMint, quoteMint, side, }) - if (!isInsufficient) return null + if (!isUndercapitalized) return null const warningContent = (
@@ -66,7 +66,7 @@ export function InsufficientWarning({

- {INSUFFICIENT_BALANCE_TOOLTIP({ + {UNDERCAPITALIZED_ORDER_TOOLTIP({ ticker: token.ticker, })}

diff --git a/hooks/use-check-insufficient-balances-for-order.tsx b/hooks/use-is-order-undercapitalized.tsx similarity index 85% rename from hooks/use-check-insufficient-balances-for-order.tsx rename to hooks/use-is-order-undercapitalized.tsx index d67e9907..a941abef 100644 --- a/hooks/use-check-insufficient-balances-for-order.tsx +++ b/hooks/use-is-order-undercapitalized.tsx @@ -4,19 +4,17 @@ import { formatUnits } from "viem/utils" import { useUSDPrice } from "@/hooks/use-usd-price" import { Side } from "@/lib/constants/protocol" -interface CheckInsufficientBalancesProps { - amount: bigint - baseMint: `0x${string}` - quoteMint: `0x${string}` - side: Side -} - -export function useCheckInsufficientBalancesForOrder({ +export function useIsOrderUndercapitalized({ amount, baseMint, quoteMint, side, -}: CheckInsufficientBalancesProps) { +}: { + amount: bigint + baseMint: `0x${string}` + quoteMint: `0x${string}` + side: Side +}) { const baseToken = Token.findByAddress(baseMint) const quoteToken = Token.findByAddress(quoteMint) const token = side === Side.BUY ? quoteToken : baseToken @@ -30,7 +28,7 @@ export function useCheckInsufficientBalancesForOrder({ const usdPrice = useUSDPrice(Token.findByAddress(baseMint), amount) - const isInsufficient = (() => { + const isUndercapitalized = (() => { if (side === Side.BUY) { const formattedUsdPrice = formatUnits( usdPrice, @@ -46,7 +44,7 @@ export function useCheckInsufficientBalancesForOrder({ })() return { - isInsufficient, + isUndercapitalized, token, } } diff --git a/lib/constants/tooltips.ts b/lib/constants/tooltips.ts index 93509f4e..3598047a 100644 --- a/lib/constants/tooltips.ts +++ b/lib/constants/tooltips.ts @@ -6,7 +6,11 @@ export const FEES_SECTION_BINANCE_FEES = "The estimated fees you would pay if you were to execute this order on Binance." export const FEES_SECTION_TOTAL_SAVINGS = "The amount you save by executing this order on Renegade." -export const INSUFFICIENT_BALANCE_TOOLTIP = ({ ticker }: { ticker: string }) => +export const UNDERCAPITALIZED_ORDER_TOOLTIP = ({ + ticker, +}: { + ticker: string +}) => `You do not have enough ${ticker} in your wallet to fully execute this order. Only part of the order will be filled.` export const MAX_BALANCES_TOOLTIP = `Renegade wallets can hold a maximum of ${MAX_BALANCES} assets at a time.` export const MAX_ORDERS_TOOLTIP = `Renegade wallets can hold a maximum of ${MAX_ORDERS} orders at a time.`