From a652ba2e083183c1d23c9927c207562ac27d20eb Mon Sep 17 00:00:00 2001 From: sehyunc <41171808+sehyunc@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:04:12 -0700 Subject: [PATCH] block order placement if no balances --- .../desktop/new-order-stepper.tsx | 11 +-- .../order-stepper/desktop/steps/default.tsx | 87 ++++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/components/dialogs/order-stepper/desktop/new-order-stepper.tsx b/components/dialogs/order-stepper/desktop/new-order-stepper.tsx index cb0c3b61..0e1fec14 100644 --- a/components/dialogs/order-stepper/desktop/new-order-stepper.tsx +++ b/components/dialogs/order-stepper/desktop/new-order-stepper.tsx @@ -1,19 +1,10 @@ import * as React from "react" -import { VisuallyHidden } from "@radix-ui/react-visually-hidden" - import { NewOrderFormProps } from "@/app/trade/[base]/components/new-order/new-order-form" import { DefaultStep } from "@/components/dialogs/order-stepper/desktop/steps/default" import { SuccessStepWithoutSavings } from "@/components/dialogs/order-stepper/desktop/steps/success-without-savings" -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog" +import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog" export interface NewOrderConfirmationProps extends NewOrderFormProps { onSuccess?: () => void diff --git a/components/dialogs/order-stepper/desktop/steps/default.tsx b/components/dialogs/order-stepper/desktop/steps/default.tsx index f953fb14..d1b0e2ea 100644 --- a/components/dialogs/order-stepper/desktop/steps/default.tsx +++ b/components/dialogs/order-stepper/desktop/steps/default.tsx @@ -1,7 +1,12 @@ import React from "react" import { VisuallyHidden } from "@radix-ui/react-visually-hidden" -import { Token, UpdateType, useCreateOrder } from "@renegade-fi/react" +import { + Token, + UpdateType, + useBackOfQueueWallet, + useCreateOrder, +} from "@renegade-fi/react" import { Loader2 } from "lucide-react" import { toast } from "sonner" @@ -14,9 +19,11 @@ import { NewOrderConfirmationProps, useStepper, } from "@/components/dialogs/order-stepper/desktop/new-order-stepper" +import { TransferDialog } from "@/components/dialogs/transfer/transfer-dialog" import { TokenIcon } from "@/components/token-icon" import { Button } from "@/components/ui/button" import { + DialogClose, DialogDescription, DialogFooter, DialogHeader, @@ -40,7 +47,7 @@ import { formatNumber, safeParseUnits } from "@/lib/format" import { decimalCorrectPrice } from "@/lib/utils" export function DefaultStep(props: NewOrderConfirmationProps) { - const { onNext, setTaskId } = useStepper() + const { onNext, setTaskId, setOpen } = useStepper() const baseToken = Token.findByTicker(props.base) const quoteToken = Token.findByTicker("USDC") @@ -76,6 +83,82 @@ export function DefaultStep(props: NewOrderConfirmationProps) { }, }) + const { data: hasBalances } = useBackOfQueueWallet({ + query: { + select: (data) => + data.balances.some((balance) => balance.amount > BigInt(0)), + }, + }) + const parsedAmount = safeParseUnits(props.amount, baseToken.decimals) + const formattedAmount = formatNumber( + parsedAmount instanceof Error ? BigInt(0) : parsedAmount, + baseToken.decimals, + true, + ) + + if (!hasBalances) { + return ( + <> + + Funds Required + + + Deposit {props.isSell ? props.base : "USDC"} to place this order. + + + + + + + + {props.isSell ? "Sell" : "Buy"} + + + + {formattedAmount} {props.base} + + + + + + + {props.isSell ? "For" : "With"} + + + USDC + + + + + + + + + You must fund your account before placing an order. + + + + + + + + setOpen(false)} + > + Deposit {props.isSell ? props.base : "USDC"} + + + + > + ) + } + return ( <>