Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/trade/header/user-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ export function UserMenu() {
}, []);

async function handleLogout() {
if (authenticated) {
await logout();
try {
if (authenticated) {
await logout();
}
} finally {
disconnect();
}
disconnect();
}
Comment on lines +66 to 74

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is safer to wrap the logout() call in a try...finally block to ensure that disconnect() is called even if the Privy logout process fails. This ensures the wallet connection is always cleared regardless of the session state.

	async function handleLogout() {
		try {
			if (authenticated) {
				await logout();
			}
		} finally {
			disconnect();
		}
	}


if (!mounted || !ready || isConnecting) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/trade/mobile/mobile-positions-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useConnection } from "wagmi";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { POSITIONS_TABS, UI_TEXT } from "@/config/constants";
import { HL_ALL_DEXS, POSITIONS_TABS, UI_TEXT } from "@/config/constants";
import { useAccountBalances } from "@/hooks/trade/use-account-balances";
import { cn } from "@/lib/cn";
import { useSubOpenOrders } from "@/lib/hyperliquid/hooks/subscription";
Expand Down Expand Up @@ -32,7 +32,7 @@ export function MobilePositionsView({ className }: MobilePositionsViewProps) {
const { perpPositions, isLoading: isLoadingState } = useAccountBalances();

const { data: ordersEvent, status: ordersStatus } = useSubOpenOrders(
{ user: address ?? "0x0" },
{ user: address ?? "0x0", dex: HL_ALL_DEXS },
{ enabled: isConnected && !!address },
);
const openOrders = ordersEvent?.orders;
Expand Down
6 changes: 5 additions & 1 deletion src/components/trade/mobile/mobile-terminal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo, useState } from "react";
import { useConnection } from "wagmi";
import { HL_ALL_DEXS } from "@/config/constants";
import { useAccountBalances } from "@/hooks/trade/use-account-balances";
import { cn } from "@/lib/cn";
import { useSubOpenOrders } from "@/lib/hyperliquid/hooks/subscription";
Expand All @@ -22,7 +23,10 @@ export function MobileTerminal({ className }: Props) {

const { address, isConnected } = useConnection();
const { perpPositions } = useAccountBalances();
const { data: ordersEvent } = useSubOpenOrders({ user: address ?? "0x0" }, { enabled: isConnected && !!address });
const { data: ordersEvent } = useSubOpenOrders(
{ user: address ?? "0x0", dex: HL_ALL_DEXS },
{ enabled: isConnected && !!address },
);
const openOrders = ordersEvent?.orders;

const positionsCount = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/trade/positions/orders-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { FALLBACK_VALUE_PLACEHOLDER } from "@/config/constants";
import { FALLBACK_VALUE_PLACEHOLDER, HL_ALL_DEXS } from "@/config/constants";
import { cn } from "@/lib/cn";
import { formatDateTime, formatToken, formatUSD } from "@/lib/format";
import { useMarkets } from "@/lib/hyperliquid";
Expand Down Expand Up @@ -44,7 +44,7 @@ export function OrdersTab() {
data: openOrdersEvent,
status,
error,
} = useSubOpenOrders({ user: address ?? "0x0" }, { enabled: isConnected && !!address });
} = useSubOpenOrders({ user: address ?? "0x0", dex: HL_ALL_DEXS }, { enabled: isConnected && !!address });
const markets = useMarkets();
const [selectedOrderIds, setSelectedOrderIds] = useState<Set<number>>(() => new Set());

Expand Down
5 changes: 4 additions & 1 deletion src/components/trade/positions/positions-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function PositionsPanel() {
const { address, isConnected } = useConnection();
const { perpSummary, spotBalances } = useAccountBalances();
const { positions } = useUserPositions();
const { data: ordersEvent } = useSubOpenOrders({ user: address ?? "0x0" }, { enabled: isConnected && !!address });
const { data: ordersEvent } = useSubOpenOrders(
{ user: address ?? "0x0", dex: HL_ALL_DEXS },
{ enabled: isConnected && !!address },
);
const { data: twapStatesEvent } = useSubTwapStates(
{ user: address ?? "0x0", dex: HL_ALL_DEXS },
{ enabled: isConnected && !!address },
Expand Down
12 changes: 11 additions & 1 deletion src/components/trade/tradebox/trade-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import {
import type { ActiveDialog } from "@/lib/trade/types";
import { useButtonContent } from "@/lib/trade/use-button-content";
import { perpInput, spotInput, useOrderValidation } from "@/lib/trade/use-order-validation";
import { useDepositModalActions, useSettingsDialogActions, useSwapModalActions } from "@/stores/use-global-modal-store";
import {
useDepositModalActions,
useFaucetModalActions,
useSettingsDialogActions,
useSwapModalActions,
} from "@/stores/use-global-modal-store";
import { useMarketOrderSlippageBps, useMarketOrderSlippagePercent } from "@/stores/use-global-settings-store";
import {
useLimitPrice,
Expand Down Expand Up @@ -137,9 +142,12 @@ export function TradePanel() {
const [activeDialog, setActiveDialog] = useState<Exclude<ActiveDialog, "wallet">>(null);

const { open: openDepositModal } = useDepositModalActions();
const { open: openFaucetModal } = useFaucetModalActions();
const { open: openSettingsDialog } = useSettingsDialogActions();
const { open: openSwapModal } = useSwapModalActions();

const isTestnet = import.meta.env.VITE_HYPERLIQUID_TESTNET === "true";

const swapTargetToken = useMemo(() => {
if (!market || market.kind !== "builderPerp") return null;

Expand Down Expand Up @@ -424,8 +432,10 @@ export function TradePanel() {
canApprove,
side,
isSubmitting,
isTestnet,
onConnectWallet: () => !authenticated && login(),
onDeposit: () => openDepositModal("deposit"),
onFaucet: openFaucetModal,
onRegister: handleRegister,
onSubmit: handleSubmit,
});
Expand Down
8 changes: 6 additions & 2 deletions src/lib/trade/use-button-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ interface ButtonContentInput {
canApprove: boolean;
side: Side;
isSubmitting: boolean;
isTestnet: boolean;
onConnectWallet: () => void;
onDeposit: () => void;
onFaucet: () => void;
onRegister: () => void;
onSubmit: () => void;
}
Expand Down Expand Up @@ -58,8 +60,8 @@ export function useButtonContent(input: ButtonContentInput): ButtonContent {
}
if (input.availableBalance <= 0) {
return {
text: t`Deposit`,
action: input.onDeposit,
text: input.isTestnet ? t`Deposit USDH or use Faucet` : t`Deposit`,
action: input.isTestnet ? input.onFaucet : input.onDeposit,
disabled: false,
variant: "cyan",
};
Expand All @@ -79,8 +81,10 @@ export function useButtonContent(input: ButtonContentInput): ButtonContent {
isRegistering,
input.canApprove,
input.isAgentLoading,
input.isTestnet,
input.onConnectWallet,
input.onDeposit,
input.onFaucet,
input.onRegister,
input.onSubmit,
input.side,
Expand Down
4 changes: 4 additions & 0 deletions src/locales/ar/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ msgstr ""
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "إيداع في Hyperliquid"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr ""

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ msgstr "Deposit failed"
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "Deposit on Hyperliquid"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr "Deposit USDH or use Faucet"

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr "Destination"
Expand Down
4 changes: 4 additions & 0 deletions src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ msgstr ""
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "Depositar en Hyperliquid"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr ""

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ msgstr ""
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "Déposer sur Hyperliquid"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr ""

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions src/locales/hi/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ msgstr ""
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "Hyperliquid पर जमा करें"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr ""

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions src/locales/zh/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ msgstr ""
#~ msgid "Deposit on Hyperliquid"
#~ msgstr "在 Hyperliquid 存款"

#: src/lib/trade/use-button-content.ts
msgid "Deposit USDH or use Faucet"
msgstr ""

#: src/components/trade/positions/send-dialog.tsx
msgid "Destination"
msgstr ""
Expand Down
Loading