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
Binary file added public/hyperodd_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 47 additions & 17 deletions src/components/trade/positions/send-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { t } from "@lingui/core/macro";
import { PaperPlaneTiltIcon, SpinnerGapIcon, WarningCircleIcon } from "@phosphor-icons/react";
import { useCallback, useMemo, useState } from "react";
import { isAddress } from "viem";
import { type Address, isAddress } from "viem";
import { useConnection } from "wagmi";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
Expand All @@ -15,6 +16,7 @@ import { cn } from "@/lib/cn";
import { formatToken } from "@/lib/format";
import { useExchangeSendAsset } from "@/lib/hyperliquid/hooks/exchange";
import { useExchangeSpotSend } from "@/lib/hyperliquid/hooks/exchange/useExchangeSpotSend";
import { useInfoUserAbstraction } from "@/lib/hyperliquid/hooks/info/useInfoUserAbstraction";
import { useSpotTokens } from "@/lib/hyperliquid/markets/use-spot-tokens";
import { floorToString, limitDecimalInput } from "@/lib/trade/numbers";
import { AssetDisplay } from "../components/asset-display";
Expand All @@ -40,11 +42,18 @@ export function SendDialog({
const [amount, setAmount] = useState("");
const [error, setError] = useState<string | null>(null);

const { address } = useConnection();
const { getToken } = useSpotTokens();
const { mutateAsync: sendAsset, isPending: isSendAssetPending } = useExchangeSendAsset();
const { mutateAsync: spotSend, isPending: isSpotSendPending } = useExchangeSpotSend();
const { data: abstractionMode, isLoading: isAbstractionLoading } = useInfoUserAbstraction(
address as Address | undefined,
);
const { perpSummary, spotBalances } = useAccountBalances();

const isUnifiedAccount = abstractionMode !== "default" && abstractionMode !== undefined;
const effectiveAccountType = isUnifiedAccount ? "spot" : accountType;

const isPending = isSendAssetPending || isSpotSendPending;

const availableSpotTokens = useMemo((): BalanceRow[] => {
Expand All @@ -66,11 +75,11 @@ export function SendDialog({
}, [spotBalances]);

const tokenOptions = useMemo(() => {
if (accountType === "perp") {
if (effectiveAccountType === "perp") {
return [DEFAULT_QUOTE_TOKEN];
}
return availableSpotTokens.map((b) => b.asset);
}, [accountType, availableSpotTokens]);
}, [effectiveAccountType, availableSpotTokens]);

const tokenInfo = useMemo(() => getToken(selectedToken), [getToken, selectedToken]);
const tokenId = useMemo(() => {
Expand All @@ -81,18 +90,18 @@ export function SendDialog({
const decimals = useMemo(() => getToken(selectedToken)?.transferDecimals ?? 2, [getToken, selectedToken]);

const availableBalance = useMemo(() => {
if (accountType === "perp") {
if (effectiveAccountType === "perp") {
return getPerpAvailable(perpSummary?.accountValue, perpSummary?.totalMarginUsed);
}
const balance = spotBalances?.find((b) => b.coin === selectedToken);
return getAvailableFromTotals(balance?.total, balance?.hold);
}, [accountType, perpSummary, spotBalances, selectedToken]);
}, [effectiveAccountType, perpSummary, spotBalances, selectedToken]);

const availableBalanceStr = useMemo(() => floorToString(availableBalance, decimals), [availableBalance, decimals]);

const isValidDestination = isAddress(destination);
const isValidAmount = isAmountWithinBalance(amount, availableBalance);
const canSend = isValidDestination && isValidAmount && !!tokenId && !isPending;
const canSend = isValidDestination && isValidAmount && !!tokenId && !isPending && !isAbstractionLoading;

function handleAccountTypeChange(value: AccountType) {
setAccountType(value);
Expand Down Expand Up @@ -122,7 +131,15 @@ export function SendDialog({

setError(null);
try {
if (accountType === "perp") {
if (isUnifiedAccount) {
await sendAsset({
destination,
sourceDex: "spot",
destinationDex: selectedToken === DEFAULT_QUOTE_TOKEN ? "" : "spot",
token: tokenId,
amount,
});
} else if (effectiveAccountType === "perp") {
await sendAsset({
destination,
sourceDex: "",
Expand All @@ -144,7 +161,18 @@ export function SendDialog({
const message = err instanceof Error ? err.message : t`Send failed`;
setError(message);
}
}, [accountType, amount, canSend, destination, onOpenChange, sendAsset, spotSend, tokenId]);
}, [
effectiveAccountType,
amount,
canSend,
destination,
isUnifiedAccount,
onOpenChange,
selectedToken,
sendAsset,
spotSend,
tokenId,
]);

function handleOpenChange(newOpen: boolean) {
if (!newOpen) {
Expand Down Expand Up @@ -178,15 +206,17 @@ export function SendDialog({
</div>

<div className="flex gap-2">
<Select value={accountType} onValueChange={(v) => handleAccountTypeChange(v as AccountType)}>
<SelectTrigger className="flex-1 h-10 bg-surface-base/50 border-border-200/60">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="perp">{t`Perps Account`}</SelectItem>
<SelectItem value="spot">{t`Spot Account`}</SelectItem>
</SelectContent>
</Select>
{!isUnifiedAccount && (
<Select value={accountType} onValueChange={(v) => handleAccountTypeChange(v as AccountType)}>
<SelectTrigger className="flex-1 h-10 bg-surface-base/50 border-border-200/60">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="perp">{t`Perps Account`}</SelectItem>
<SelectItem value="spot">{t`Spot Account`}</SelectItem>
</SelectContent>
</Select>
)}

<Select value={selectedToken} onValueChange={handleTokenChange}>
<SelectTrigger className="flex-1 h-10 bg-surface-base/50 border-border-200/60">
Expand Down
5 changes: 2 additions & 3 deletions src/lib/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ export function buildPageHead(options: PageSeoOptions = {}): HeadOutput {

const links: LinkTag[] = [
{ rel: "canonical", href: canonicalUrl },
{ rel: "icon", href: "/favicon.ico", sizes: "32x32" },
{ rel: "icon", href: "/icon.svg", type: "image/svg+xml" },
{ rel: "apple-touch-icon", href: "/apple-touch-icon.png" },
{ rel: "icon", href: "/hyperodd_icon.png", type: "image/png" },
{ rel: "apple-touch-icon", href: "/hyperodd_icon.png" },
{ rel: "manifest", href: "/manifest.json" },
{ rel: "preconnect", href: "https://app.hyperliquid.xyz" },
{ rel: "dns-prefetch", href: "https://app.hyperliquid.xyz" },
Expand Down
Loading