@liberfi.io/ui-perpetuals 0.1.95 → 0.1.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@ declare global {
12
12
  };
13
13
  }
14
14
  }
15
- declare const _default: "0.1.95";
15
+ declare const _default: "0.1.97";
16
16
 
17
17
  /**
18
18
  * Trading pair symbol format
@@ -1021,22 +1021,26 @@ declare function useTradesScript({ symbol, limit, }: UseTradesScriptParams): Use
1021
1021
  type PlaceOrderFormWidgetProps = {
1022
1022
  symbol: string;
1023
1023
  userAddress?: string;
1024
+ maxLeverage?: number;
1024
1025
  onSuccess?: () => void;
1025
1026
  onError?: (error: Error) => void;
1026
1027
  className?: string;
1027
1028
  };
1028
- declare function PlaceOrderFormWidget({ symbol, userAddress, onSuccess, onError, className, }: PlaceOrderFormWidgetProps): react_jsx_runtime.JSX.Element;
1029
+ declare function PlaceOrderFormWidget({ symbol, userAddress, maxLeverage, onSuccess, onError, className, }: PlaceOrderFormWidgetProps): react_jsx_runtime.JSX.Element;
1029
1030
 
1030
1031
  type PlaceOrderFormData = {
1031
1032
  price?: number;
1032
1033
  amount: number;
1033
1034
  leverage: number;
1035
+ takeProfitPrice?: number;
1034
1036
  takeProfitPercent?: number;
1037
+ stopLossPrice?: number;
1035
1038
  stopLossPercent?: number;
1036
1039
  };
1037
1040
  type UsePlaceOrderFormScriptParams = {
1038
1041
  symbol: string;
1039
1042
  userAddress?: string;
1043
+ maxLeverage?: number;
1040
1044
  onSuccess?: () => void;
1041
1045
  onError?: (error: Error) => void;
1042
1046
  };
@@ -1055,8 +1059,9 @@ type UsePlaceOrderFormScriptResult = {
1055
1059
  availableMargin: number;
1056
1060
  accountValue: number;
1057
1061
  currentPosition?: number;
1062
+ maxLeverage: number;
1058
1063
  };
1059
- declare function usePlaceOrderFormScript({ symbol, userAddress, onSuccess, onError, }: UsePlaceOrderFormScriptParams): UsePlaceOrderFormScriptResult;
1064
+ declare function usePlaceOrderFormScript({ symbol, userAddress, maxLeverage: maxLeverageProp, onSuccess, onError, }: UsePlaceOrderFormScriptParams): UsePlaceOrderFormScriptResult;
1060
1065
 
1061
1066
  type PlaceOrderFormUIProps = {
1062
1067
  methods: UseFormReturn<PlaceOrderFormData>;
@@ -1074,8 +1079,9 @@ type PlaceOrderFormUIProps = {
1074
1079
  availableMargin: number;
1075
1080
  accountValue: number;
1076
1081
  currentPosition?: number;
1082
+ maxLeverage: number;
1077
1083
  };
1078
- declare function PlaceOrderFormUI({ methods, side, orderType, onSideChange, onOrderTypeChange, onSubmit, isSubmitting, symbol, currentPrice, estimatedFee, liquidationPrice, availableMargin, accountValue, currentPosition, }: PlaceOrderFormUIProps): react_jsx_runtime.JSX.Element;
1084
+ declare function PlaceOrderFormUI({ methods, side, orderType, onSideChange, onOrderTypeChange, onSubmit, isSubmitting, symbol, currentPrice, estimatedFee, liquidationPrice, availableMargin, accountValue, currentPosition, maxLeverage, }: PlaceOrderFormUIProps): react_jsx_runtime.JSX.Element;
1079
1085
 
1080
1086
  type PositionsWidgetProps = {
1081
1087
  userAddress?: string;
@@ -1092,7 +1098,9 @@ type PositionsUIProps = {
1092
1098
  isClosing: boolean;
1093
1099
  };
1094
1100
  declare function PositionsUI({ positions, onClosePosition, isClosing, }: PositionsUIProps): react_jsx_runtime.JSX.Element;
1101
+ /** Loading skeleton for positions panel */
1095
1102
  declare function PositionsSkeleton(): react_jsx_runtime.JSX.Element;
1103
+ /** Empty state when there are no open positions */
1096
1104
  declare function PositionsEmpty(): react_jsx_runtime.JSX.Element;
1097
1105
 
1098
1106
  type UsePositionsScriptParams = {
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ declare global {
12
12
  };
13
13
  }
14
14
  }
15
- declare const _default: "0.1.95";
15
+ declare const _default: "0.1.97";
16
16
 
17
17
  /**
18
18
  * Trading pair symbol format
@@ -1021,22 +1021,26 @@ declare function useTradesScript({ symbol, limit, }: UseTradesScriptParams): Use
1021
1021
  type PlaceOrderFormWidgetProps = {
1022
1022
  symbol: string;
1023
1023
  userAddress?: string;
1024
+ maxLeverage?: number;
1024
1025
  onSuccess?: () => void;
1025
1026
  onError?: (error: Error) => void;
1026
1027
  className?: string;
1027
1028
  };
1028
- declare function PlaceOrderFormWidget({ symbol, userAddress, onSuccess, onError, className, }: PlaceOrderFormWidgetProps): react_jsx_runtime.JSX.Element;
1029
+ declare function PlaceOrderFormWidget({ symbol, userAddress, maxLeverage, onSuccess, onError, className, }: PlaceOrderFormWidgetProps): react_jsx_runtime.JSX.Element;
1029
1030
 
1030
1031
  type PlaceOrderFormData = {
1031
1032
  price?: number;
1032
1033
  amount: number;
1033
1034
  leverage: number;
1035
+ takeProfitPrice?: number;
1034
1036
  takeProfitPercent?: number;
1037
+ stopLossPrice?: number;
1035
1038
  stopLossPercent?: number;
1036
1039
  };
1037
1040
  type UsePlaceOrderFormScriptParams = {
1038
1041
  symbol: string;
1039
1042
  userAddress?: string;
1043
+ maxLeverage?: number;
1040
1044
  onSuccess?: () => void;
1041
1045
  onError?: (error: Error) => void;
1042
1046
  };
@@ -1055,8 +1059,9 @@ type UsePlaceOrderFormScriptResult = {
1055
1059
  availableMargin: number;
1056
1060
  accountValue: number;
1057
1061
  currentPosition?: number;
1062
+ maxLeverage: number;
1058
1063
  };
1059
- declare function usePlaceOrderFormScript({ symbol, userAddress, onSuccess, onError, }: UsePlaceOrderFormScriptParams): UsePlaceOrderFormScriptResult;
1064
+ declare function usePlaceOrderFormScript({ symbol, userAddress, maxLeverage: maxLeverageProp, onSuccess, onError, }: UsePlaceOrderFormScriptParams): UsePlaceOrderFormScriptResult;
1060
1065
 
1061
1066
  type PlaceOrderFormUIProps = {
1062
1067
  methods: UseFormReturn<PlaceOrderFormData>;
@@ -1074,8 +1079,9 @@ type PlaceOrderFormUIProps = {
1074
1079
  availableMargin: number;
1075
1080
  accountValue: number;
1076
1081
  currentPosition?: number;
1082
+ maxLeverage: number;
1077
1083
  };
1078
- declare function PlaceOrderFormUI({ methods, side, orderType, onSideChange, onOrderTypeChange, onSubmit, isSubmitting, symbol, currentPrice, estimatedFee, liquidationPrice, availableMargin, accountValue, currentPosition, }: PlaceOrderFormUIProps): react_jsx_runtime.JSX.Element;
1084
+ declare function PlaceOrderFormUI({ methods, side, orderType, onSideChange, onOrderTypeChange, onSubmit, isSubmitting, symbol, currentPrice, estimatedFee, liquidationPrice, availableMargin, accountValue, currentPosition, maxLeverage, }: PlaceOrderFormUIProps): react_jsx_runtime.JSX.Element;
1079
1085
 
1080
1086
  type PositionsWidgetProps = {
1081
1087
  userAddress?: string;
@@ -1092,7 +1098,9 @@ type PositionsUIProps = {
1092
1098
  isClosing: boolean;
1093
1099
  };
1094
1100
  declare function PositionsUI({ positions, onClosePosition, isClosing, }: PositionsUIProps): react_jsx_runtime.JSX.Element;
1101
+ /** Loading skeleton for positions panel */
1095
1102
  declare function PositionsSkeleton(): react_jsx_runtime.JSX.Element;
1103
+ /** Empty state when there are no open positions */
1096
1104
  declare function PositionsEmpty(): react_jsx_runtime.JSX.Element;
1097
1105
 
1098
1106
  type UsePositionsScriptParams = {
package/dist/index.js CHANGED
@@ -1,3 +1,10 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactQuery=require('@tanstack/react-query'),ui=require('@liberfi.io/ui'),reactHookForm=require('react-hook-form');typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-perpetuals"]="0.1.95");var rr="0.1.95";var de=class{ws=null;wsEndpoint;subscriptions=new Map;reconnectAttempts=0;maxReconnectAttempts=10;reconnectDelay=1e3;heartbeatInterval=null;messageQueue=[];isConnected=false;pingInterval=3e4;reconnectTimeout=null;isReconnecting=false;constructor(e){this.wsEndpoint=e;}async connect(){return new Promise((e,r)=>{try{this.ws&&this.ws.close(),this.ws=new WebSocket(this.wsEndpoint),this.ws.onopen=()=>{console.log("[WebSocket] Connected to Hyperliquid"),this.isConnected=!0,this.reconnectAttempts=0,this.isReconnecting=!1,this.startHeartbeat(),this.flushMessageQueue(),e();},this.ws.onmessage=s=>{this.handleMessage(s.data);},this.ws.onerror=s=>{console.error("[WebSocket] Error:",s),this.isConnected=!1,this.isReconnecting||r(new Error("WebSocket connection failed"));},this.ws.onclose=s=>{console.log(`[WebSocket] Closed: ${s.code} - ${s.reason||"No reason provided"}`),this.isConnected=!1,this.stopHeartbeat(),s.code!==1e3&&this.attemptReconnect();};}catch(s){r(s);}})}disconnect(){this.stopHeartbeat(),this.subscriptions.clear(),this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(1e3,"Normal closure"),this.ws=null),this.isConnected=false,this.isReconnecting=false,this.reconnectAttempts=0;}attemptReconnect(){if(this.isReconnecting)return;if(this.reconnectAttempts>=this.maxReconnectAttempts){console.error("[WebSocket] Max reconnection attempts reached");return}this.isReconnecting=true,this.reconnectAttempts++;let e=Math.min(this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1),3e4);console.log(`[WebSocket] Reconnecting in ${e}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`),this.reconnectTimeout=window.setTimeout(()=>{this.connect().then(()=>{this.resubscribeAll();}).catch(r=>{console.error("[WebSocket] Reconnection failed:",r),this.isReconnecting=false;});},e);}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.isConnected&&this.ws&&this.ws.readyState===WebSocket.OPEN&&this.send({method:"ping"});},this.pingInterval);}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null);}send(e){this.isConnected&&this.ws&&this.ws.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(e)):this.messageQueue.push(e);}flushMessageQueue(){for(;this.messageQueue.length>0;){let e=this.messageQueue.shift();e&&this.send(e);}}resubscribeAll(){this.subscriptions.forEach(e=>{this.sendSubscription(e.type,e.param);});}handleMessage(e){try{let r=JSON.parse(e);r.channel?this.handleChannelMessage(r):r.method;}catch(r){console.error("[WebSocket] Failed to parse message:",r,e);}}handleChannelMessage(e){let r=e.channel;this.subscriptions.forEach((s,n)=>{if(this.isChannelMatch(r,s.type,s.param))try{let a=this.transformData(s.type,e.data,s.param);s.callback(a);}catch(a){console.error(`[WebSocket] Error in subscription callback (${n}):`,a);}});}isChannelMatch(e,r,s){return r==="ticker"?e==="allMids":r==="trades"?e==="trades":r==="orderBook"?e==="l2Book":r==="candle"?e==="candle":r==="userFills"?e==="userFills":r==="userEvents"?e==="userEvents":false}transformData(e,r,s){return e==="ticker"?this.transformTickerData(r):e==="trades"?this.transformTradesData(r,s):e==="orderBook"?this.transformOrderBookData(r,s):e==="candle"?this.transformCandleData(r,s):e==="userFills"?this.transformUserFillsData(r):e==="userEvents"?this.transformUserEventsData(r):r}transformTickerData(e){let r=e.mids||{};return Object.entries(r).map(([s,n])=>({symbol:`${s}-USDC`,price:parseFloat(n),timestamp:Date.now()}))}transformTradesData(e,r){return Array.isArray(e)?e.map(s=>({symbol:r,side:s.side==="B"?"buy":"sell",price:parseFloat(s.px),quantity:parseFloat(s.sz),timestamp:s.time,tradeId:s.tid})):[]}transformOrderBookData(e,r){let[s,n]=e.levels||[[],[]];return {symbol:r,bids:s.map(a=>({price:parseFloat(a.px),quantity:parseFloat(a.sz),count:a.n})),asks:n.map(a=>({price:parseFloat(a.px),quantity:parseFloat(a.sz),count:a.n})),timestamp:e.time||Date.now()}}transformCandleData(e,r){let[s]=r.split(":");return {symbol:s,open:parseFloat(e.o),high:parseFloat(e.h),low:parseFloat(e.l),close:parseFloat(e.c),volume:parseFloat(e.v),timestamp:e.t,closeTimestamp:e.T}}transformUserFillsData(e){return Array.isArray(e)?e.map(r=>({tradeId:r.tid?.toString(),orderId:r.oid?.toString(),symbol:`${r.coin}-USDC`,side:r.dir?.includes("Long")?"long":"short",price:parseFloat(r.px),quantity:parseFloat(r.sz),fee:parseFloat(r.fee||"0"),feeCurrency:r.feeToken||"USDC",isMaker:r.side==="M",timestamp:r.time})):[]}transformUserEventsData(e){return e}sendSubscription(e,r){let s;if(e==="ticker")s={method:"subscribe",subscription:{type:"allMids"}};else if(e==="trades")s={method:"subscribe",subscription:{type:"trades",coin:r.split("-")[0]}};else if(e==="orderBook")s={method:"subscribe",subscription:{type:"l2Book",coin:r.split("-")[0]}};else if(e==="candle"){let[n,a]=r.split(":");s={method:"subscribe",subscription:{type:"candle",coin:n.split("-")[0],interval:a}};}else e==="userFills"?s={method:"subscribe",subscription:{type:"userFills",user:r}}:e==="userEvents"&&(s={method:"subscribe",subscription:{type:"userEvents",user:r}});s&&this.send(s);}sendUnsubscription(e,r){let s;if(e==="ticker")s={method:"unsubscribe",subscription:{type:"allMids"}};else if(e==="trades")s={method:"unsubscribe",subscription:{type:"trades",coin:r.split("-")[0]}};else if(e==="orderBook")s={method:"unsubscribe",subscription:{type:"l2Book",coin:r.split("-")[0]}};else if(e==="candle"){let[n,a]=r.split(":");s={method:"unsubscribe",subscription:{type:"candle",coin:n.split("-")[0],interval:a}};}else e==="userFills"?s={method:"unsubscribe",subscription:{type:"userFills",user:r}}:e==="userEvents"&&(s={method:"unsubscribe",subscription:{type:"userEvents",user:r}});s&&this.send(s);}subscribe(e,r,s){let n=`${e}:${r}`;return this.subscriptions.set(n,{type:e,param:r,callback:s}),this.sendSubscription(e,r),n}unsubscribe(e){let r=this.subscriptions.get(e);r&&(this.sendUnsubscription(r.type,r.param),this.subscriptions.delete(e));}isConnectedNow(){return this.isConnected}};var ut={testnet:{api:"https://api.hyperliquid-testnet.xyz",ws:"wss://api.hyperliquid-testnet.xyz/ws"},mainnet:{api:"https://api.hyperliquid.xyz",ws:"wss://api.hyperliquid.xyz/ws"}},ge=class{apiEndpoint;_wsEndpoint;timeout;environment;wsManager=null;constructor(e={}){this.environment=e.environment||"testnet",this.apiEndpoint=e.apiEndpoint||ut[this.environment].api,this._wsEndpoint=e.wsEndpoint||ut[this.environment].ws,this.timeout=e.timeout||3e4;}async request(e,r){let s=`${this.apiEndpoint}${e}`;try{let n=new AbortController,a=setTimeout(()=>n.abort(),this.timeout),i=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r),signal:n.signal});if(clearTimeout(a),!i.ok)throw new $(`HTTP ${i.status}: ${i.statusText}`,i.status,await i.text());return await i.json()}catch(n){throw n.name==="AbortError"?new $(`Request timeout after ${this.timeout}ms`,408,""):n instanceof $?n:new $(`Network error: ${n.message}`,0,"")}}symbolToCoin(e){return e.split("-")[0]}parseInterval(e){return {"1m":6e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"4h":144e5,"1d":864e5,"1w":6048e5}[e]}async getSupportedCoins(){let[e]=await this.request("/info",{type:"metaAndAssetCtxs"});return e.universe.map(r=>`${r.name}-USDC`)}async getMarket(e){let r=await this.getMarkets([e]);return r.length>0?r[0]:null}async getMarkets(e){let[r,s]=await this.request("/info",{type:"metaAndAssetCtxs"}),n=r.universe.map((a,i)=>{let o=s[i],l=`${a.name}-USDC`,u=parseFloat(o.midPx||o.markPx||"0"),d=o.prevDayPx?parseFloat(o.prevDayPx):u,m=d>0?(u-d)/d*100:0;return {symbol:l,price:u,change24h:m,volume24h:parseFloat(o.dayNtlVlm||"0"),fundingRate:parseFloat(o.funding||"0"),openInterest:parseFloat(o.openInterest||"0"),markPrice:parseFloat(o.markPx||"0"),indexPrice:parseFloat(o.oraclePx||o.midPx||"0")}});if(e&&e.length>0){let a=new Set(e);return n.filter(i=>a.has(i.symbol))}return n}async getKlines(e,r,s=100){let n=this.symbolToCoin(e),a=this.parseInterval(r),i=Date.now(),o=i-a*s;return (await this.request("/info",{type:"candleSnapshot",req:{coin:n,interval:r,startTime:o,endTime:i}})).map(u=>({symbol:e,open:parseFloat(u.o),high:parseFloat(u.h),low:parseFloat(u.l),close:parseFloat(u.c),volume:parseFloat(u.v),timestamp:u.t,closeTimestamp:u.T}))}async getOrderBook(e,r=10){let s=this.symbolToCoin(e),n=await this.request("/info",{type:"l2Book",coin:s}),[a,i]=n.levels;return {symbol:e,bids:a.slice(0,r).map(o=>({price:parseFloat(o.px),quantity:parseFloat(o.sz),count:o.n})),asks:i.slice(0,r).map(o=>({price:parseFloat(o.px),quantity:parseFloat(o.sz),count:o.n})),timestamp:n.time}}async getRecentTrades(e,r=50){let s=this.symbolToCoin(e);return (await this.request("/info",{type:"recentTrades",coin:s})).slice(0,r).map(a=>({symbol:e,side:a.side==="B"?"buy":"sell",price:parseFloat(a.px),quantity:parseFloat(a.sz),timestamp:a.time,tradeId:a.tid}))}async placeOrder(e){throw new Error("placeOrder() requires wallet private key configuration for EIP-712 signature. Please configure authentication before calling this method. See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint")}async cancelOrder(e){throw new Error("cancelOrder() requires wallet private key configuration for EIP-712 signature. Please configure authentication before calling this method. See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint")}async getPositions(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"clearinghouseState",user:e.userAddress}),s=r.assetPositions.map(a=>{let i=a.position,o=`${i.coin}-USDC`,l=parseFloat(i.szi);if(l===0)return null;let u=parseFloat(i.entryPx),d=parseFloat(i.unrealizedPnl),m=parseFloat(i.positionValue);return {symbol:o,side:l>0?"long":"short",quantity:Math.abs(l),entryPrice:u,markPrice:u,unrealizedPnl:d,unrealizedPnlPercent:parseFloat(i.returnOnEquity)*100,leverage:i.leverage.value,liquidationPrice:i.liquidationPx?parseFloat(i.liquidationPx):void 0,margin:parseFloat(i.marginUsed),notionalValue:Math.abs(m)}}).filter(Boolean),n=e.symbol?s.filter(a=>a.symbol===e.symbol):s;return {positions:n,totalEquity:parseFloat(r.marginSummary.accountValue),availableBalance:parseFloat(r.marginSummary.accountValue)-parseFloat(r.marginSummary.totalMarginUsed),totalUnrealizedPnl:n.reduce((a,i)=>a+i.unrealizedPnl,0),raw:r}}async getOpenOrders(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"openOrders",user:e.userAddress}),s=r.map(a=>{let i=`${a.coin}-USDC`,o=parseFloat(a.origSz),l=parseFloat(a.sz),u=o-l;return {orderId:a.oid.toString(),clientOrderId:a.cloid,symbol:i,side:a.side?"long":"short",orderType:"limit",price:parseFloat(a.limitPx),quantity:o,filledQuantity:u,remainingQuantity:l,status:u>0&&l>0?"partially_filled":"pending",timestamp:a.timestamp,updateTimestamp:a.timestamp}}),n=e.symbol?s.filter(a=>a.symbol===e.symbol):s;return {orders:n,totalCount:n.length,raw:r}}async getTrades(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"userFills",user:e.userAddress}),s=r.map(n=>{let a=`${n.coin}-USDC`,i=n.dir.includes("Long");return {tradeId:n.tid.toString(),orderId:n.oid.toString(),symbol:a,side:i?"long":"short",price:parseFloat(n.px),quantity:parseFloat(n.sz),fee:parseFloat(n.fee||"0"),feeCurrency:n.feeToken||"USDC",isMaker:n.side==="M",timestamp:n.time}});return e.symbol&&(s=s.filter(n=>n.symbol===e.symbol)),e.startTime&&(s=s.filter(n=>n.timestamp>=e.startTime)),e.endTime&&(s=s.filter(n=>n.timestamp<=e.endTime)),e.limit&&(s=s.slice(0,e.limit)),{trades:s,totalCount:s.length,raw:r}}async connectWebSocket(){if(this.wsManager||(this.wsManager=new de(this._wsEndpoint)),this.wsManager.isConnectedNow()){console.log("[WebSocket] Already connected");return}await this.wsManager.connect();}disconnectWebSocket(){this.wsManager&&(this.wsManager.disconnect(),this.wsManager=null);}subscribeMarketData(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");return this.wsManager.subscribe(e,r,s)}subscribeCandles(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");let n=`${e}:${r}`;return this.wsManager.subscribe("candle",n,s)}subscribeUserData(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");let n=e==="fills"?"userFills":"userEvents";return this.wsManager.subscribe(n,r,s)}unsubscribe(e){this.wsManager&&this.wsManager.unsubscribe(e);}},$=class extends Error{constructor(r,s,n){super(r);this.statusCode=s;this.responseBody=n;this.name="HyperliquidApiError";}};var ne=react.createContext({});function nr({client:t,children:e}){return jsxRuntime.jsx(ne.Provider,{value:{client:t},children:e})}function h(){let t=react.useContext(ne);if(!t||!t.client)throw new Error("usePerpetualsClient must be used within a PerpetualsProvider");return t}function ct(){return ["perps","coins"]}async function dt(t){return await t.getSupportedCoins()}function xe(t={}){let{client:e}=h();return reactQuery.useQuery({queryKey:ct(),queryFn:async()=>dt(e),staleTime:300*1e3,...t})}function pt(t){return ["perps","market",t.symbol]}async function mt(t,{symbol:e}){return await t.getMarket(e)}function ae(t,e={}){let{client:r}=h();return reactQuery.useQuery({queryKey:pt(t),queryFn:async()=>mt(r,t),staleTime:10*1e3,...e})}function ft(t={}){return ["perps","markets",JSON.stringify((t.symbols??[]).sort())]}async function yt(t,{symbols:e}={}){return await t.getMarkets(e)}function be(t={},e={}){let{client:r}=h();return reactQuery.useQuery({queryKey:ft(t),queryFn:async()=>yt(r,t),staleTime:10*1e3,...e})}function gt(t){return ["perps","klines",t.symbol,t.interval,String(t.limit??100)]}async function xt(t,{symbol:e,interval:r,limit:s}){return await t.getKlines(e,r,s)}function dr(t,e={}){let{client:r}=h();return reactQuery.useQuery({queryKey:gt(t),queryFn:async()=>xt(r,t),staleTime:30*1e3,...e})}function bt(t){return ["perps","orderBook",t.symbol,String(t.maxLevel??20)]}async function ht(t,{symbol:e,maxLevel:r}){return await t.getOrderBook(e,r)}function he(t,e={}){let{client:r}=h();return reactQuery.useQuery({queryKey:bt(t),queryFn:async()=>ht(r,t),staleTime:5*1e3,...e})}function Pt(t){return ["perps","recentTrades",t.symbol,String(t.limit??50)]}async function vt(t,{symbol:e,limit:r}){return await t.getRecentTrades(e,r)}function Pe(t,e={}){let{client:r}=h();return reactQuery.useQuery({queryKey:Pt(t),queryFn:async()=>vt(r,t),staleTime:5*1e3,...e})}function Nt(t){return ["perps","positions",t.userAddress??"",t.symbol??""]}async function wt(t,e){return await t.getPositions(e)}function ve(t,e={}){let{client:r}=h(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:Nt(n),queryFn:async()=>wt(r,n),enabled:s&&!!n.userAddress,staleTime:10*1e3,...e})}function kt(t){return ["perps","orders",t.userAddress??"",t.symbol??""]}async function Ct(t,e){return await t.getOpenOrders(e)}function Ne(t,e={}){let{client:r}=h(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:kt(n),queryFn:async()=>Ct(r,n),enabled:s&&!!n.userAddress,staleTime:5*1e3,...e})}function St(t){return ["perps","trades",t.userAddress??"",t.symbol??"",String(t.limit??50),String(t.startTime??""),String(t.endTime??"")]}async function Ot(t,e){return await t.getTrades(e)}function we(t,e={}){let{client:r}=h(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:St(n),queryFn:async()=>Ot(r,n),enabled:s&&!!n.userAddress,staleTime:30*1e3,...e})}async function Tt(t,e){return await t.placeOrder(e)}function ie(t={}){let{client:e}=h();return reactQuery.useMutation({mutationFn:async r=>Tt(e,r),...t})}async function Ut(t,e){return await t.cancelOrder(e)}function ke(t={}){let{client:e}=h();return reactQuery.useMutation({mutationFn:async r=>Ut(e,r),...t})}function K(t){let{type:e,symbol:r,enabled:s=true}=t,{client:n}=h(),[a,i]=react.useState(null),[o,l]=react.useState(false),[u,d]=react.useState(null),m=react.useCallback(p=>{i(p);},[]);return react.useEffect(()=>{if(!s)return;let p=null,c=true;return (async()=>{try{if(await n.connectWebSocket(),!c)return;l(!0),d(null),p=n.subscribeMarketData(e,r,m);}catch(f){c&&(d(f instanceof Error?f:new Error("Connection failed")),l(false));}})(),()=>{if(c=false,p)try{n.unsubscribe(p);}catch(f){console.error("Failed to unsubscribe:",f);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,m]),{data:a,isConnected:o,error:u}}function wr(t){let{symbol:e,interval:r,enabled:s=true}=t,{client:n}=h(),[a,i]=react.useState(null),[o,l]=react.useState(false),[u,d]=react.useState(null),m=react.useCallback(p=>{i(p);},[]);return react.useEffect(()=>{if(!s)return;let p=null,c=true;return (async()=>{try{if(await n.connectWebSocket(),!c)return;l(!0),d(null),p=n.subscribeCandles(e,r,m);}catch(f){c&&(d(f instanceof Error?f:new Error("Connection failed")),l(false));}})(),()=>{if(c=false,p)try{n.unsubscribe(p);}catch(f){console.error("Failed to unsubscribe:",f);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,m]),{data:a,isConnected:o,error:u}}function oe(t){let{type:e,userAddress:r,enabled:s=true}=t,{client:n}=h(),[a,i]=react.useState(null),[o,l]=react.useState(false),[u,d]=react.useState(null),m=react.useCallback(p=>{i(p);},[]);return react.useEffect(()=>{if(!s||!r)return;let p=null,c=true;return (async()=>{try{if(await n.connectWebSocket(),!c)return;l(!0),d(null),p=n.subscribeUserData(e,r,m);}catch(f){c&&(d(f instanceof Error?f:new Error("Connection failed")),l(false));}})(),()=>{if(c=false,p)try{n.unsubscribe(p);}catch(f){console.error("Failed to unsubscribe:",f);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,m]),{data:a,isConnected:o,error:u}}function Te(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center px-4 py-3 bg-neutral-900 border-b border-neutral-800",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"Market data not available"})})}function Ue(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-6 px-4 py-3 bg-neutral-900 border-b border-neutral-800",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-28 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]}),jsxRuntime.jsx("div",{className:"h-8 w-px bg-neutral-800"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"})]})]})]})]})}function Ie(t){let[e,r]=react.useState(),[s,n]=react.useState(0),{data:a,isPending:i}=ae({symbol:t}),{data:o,isConnected:l}=K({type:"ticker",symbol:t,enabled:!!a});return react.useEffect(()=>{a&&r(a);},[a]),react.useEffect(()=>{if(!o)return;let u=Sr(o,t);u&&r(d=>Or(d??a??void 0,u,t));},[o,a,t]),react.useEffect(()=>{let u=()=>{let m=Date.now(),p=480*60*1e3,c=m%p,y=p-c;return Math.floor(y/1e3)};n(u());let d=setInterval(()=>{n(u());},1e3);return ()=>clearInterval(d)},[]),{marketData:e,isLoading:i,fundingCountdown:s}}function Sr(t,e){if(Array.isArray(t)){let r=t.find(s=>!s||typeof s!="object"?false:s.symbol===e);return r&&typeof r=="object"?r:null}return t&&typeof t=="object"?t:null}function _(t,e){return typeof t=="number"&&Number.isFinite(t)?t:e}function Or(t,e,r){return {symbol:e.symbol??t?.symbol??r,price:_(e.price,t?.price??0),change24h:_(e.change24h,t?.change24h??0),volume24h:_(e.volume24h,t?.volume24h??0),fundingRate:_(e.fundingRate,t?.fundingRate??0),openInterest:_(e.openInterest,t?.openInterest??0),markPrice:_(e.markPrice,t?.markPrice??0),indexPrice:typeof e.indexPrice=="number"&&Number.isFinite(e.indexPrice)?e.indexPrice:t?.indexPrice,high24h:typeof e.high24h=="number"&&Number.isFinite(e.high24h)?e.high24h:t?.high24h,low24h:typeof e.low24h=="number"&&Number.isFinite(e.low24h)?e.low24h:t?.low24h}}function Tr(t){let e=Math.floor(t/3600),r=Math.floor(t%3600/60),s=t%60;return `${String(e).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function Rt(t,e=2){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e9?`$${(t/1e9).toFixed(e)}B`:t>=1e6?`$${(t/1e6).toFixed(e)}M`:t>=1e3?`$${(t/1e3).toFixed(e)}K`:`$${t.toFixed(e)}`}function Dt(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function Me({marketData:t,fundingCountdown:e}){let{symbol:r,price:s,change24h:n,indexPrice:a,volume24h:i,openInterest:o,fundingRate:l}=t,u=typeof n=="number"&&Number.isFinite(n)?n:0,d=typeof l=="number"&&Number.isFinite(l)?l:0,m=u>=0,p=(u*100).toFixed(2);return jsxRuntime.jsxs("div",{className:"flex items-center gap-6 px-4 py-3 bg-neutral-900 border-b border-neutral-800",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-white",children:r}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-2xl font-bold text-white",children:Dt(s)}),jsxRuntime.jsxs("span",{className:ui.cn("text-sm font-medium",m?"text-green-500":"text-red-500"),children:[m?"+":"",p,"%"]})]})]}),jsxRuntime.jsx("div",{className:"h-8 w-px bg-neutral-800"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:"Oracle Price"}),jsxRuntime.jsx("span",{className:"text-white font-medium",children:a?Dt(a):"-"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:"24h Volume"}),jsxRuntime.jsx("span",{className:"text-white font-medium",children:Rt(i)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:"Open Interest"}),jsxRuntime.jsx("span",{className:"text-white font-medium",children:Rt(o)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:"Funding / Countdown"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:ui.cn("font-medium",d>=0?"text-green-500":"text-red-500"),children:[(d*100).toFixed(4),"%"]}),jsxRuntime.jsx("span",{className:"text-neutral-400",children:Tr(e)})]})]})]})]})}function Ur({symbol:t}){let{marketData:e,isLoading:r,fundingCountdown:s}=Ie(t);return r?jsxRuntime.jsx(Ue,{}):e?jsxRuntime.jsx(Me,{marketData:e,fundingCountdown:s}):jsxRuntime.jsx(Te,{})}function De({onSelectCoin:t}={}){let[e,r]=react.useState(""),[s,n]=react.useState([]),{data:a,isPending:i}=xe(),{data:o,isPending:l}=be({symbols:a},{enabled:!!a&&a.length>0});react.useEffect(()=>{o&&n(o);},[o]);let u=react.useMemo(()=>{if(!e.trim())return s;let m=e.toLowerCase().trim();return s.filter(p=>p.symbol.toLowerCase().includes(m))},[s,e]);return {coins:s,isLoading:i||l,searchQuery:e,setSearchQuery:r,filteredCoins:u,handleSelectCoin:m=>{t?.(m);}}}function qt(t,e=2){return t>=1e9?`$${(t/1e9).toFixed(e)}B`:t>=1e6?`$${(t/1e6).toFixed(e)}M`:t>=1e3?`$${(t/1e3).toFixed(e)}K`:`$${t.toFixed(e)}`}function Br(t){return t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function Ee({coins:t,searchQuery:e,onSearchChange:r,onSelectCoin:s,isLoading:n}){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950",children:[jsxRuntime.jsx("div",{className:"p-3 border-b border-neutral-800",children:jsxRuntime.jsx(ui.Input,{type:"text",placeholder:"Search coins...",value:e,onChange:a=>r(a.target.value),startContent:jsxRuntime.jsx(ui.SearchIcon,{className:"w-4 h-4 text-neutral-400"}),classNames:{input:"text-sm",inputWrapper:"bg-neutral-900 border-neutral-800"}})}),jsxRuntime.jsx("div",{className:"flex-1 overflow-hidden",children:jsxRuntime.jsxs(ui.StyledTable,{isVirtualized:true,radius:"none",className:"h-full",classNames:{wrapper:"bg-neutral-950",th:"bg-neutral-900 text-neutral-400 text-xs font-medium",td:"text-sm"},maxTableHeight:600,rowHeight:48,"aria-label":"Search Coins",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{width:140,children:"Token"},"token"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"Last Price"},"lastPrice"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"24h Change"},"change24h"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"8h Funding"},"fundingRate"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"24h Volume"},"volume24h"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"Open Interest"},"openInterest")]}),jsxRuntime.jsx(ui.TableBody,{items:t,isLoading:n,emptyContent:jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center py-10",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:e?"No coins found":"No coins available"})}),children:a=>{let i=a.change24h>=0,o=(a.change24h*100).toFixed(2),l=(a.fundingRate*100).toFixed(4),u=a.fundingRate>=0;return jsxRuntime.jsxs(ui.TableRow,{onClick:()=>s(a.symbol),className:"cursor-pointer hover:bg-neutral-900/50 transition-colors",children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 rounded-full bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold text-white",children:a.symbol.charAt(0)})}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:a.symbol})]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-white font-medium",children:Br(a.price)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:ui.cn("font-medium",i?"text-green-500":"text-red-500"),children:[i?"+":"",o,"%"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:ui.cn("font-medium",u?"text-green-500":"text-red-500"),children:[l,"%"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-neutral-300",children:qt(a.volume24h)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-neutral-300",children:qt(a.openInterest)})})]},a.symbol)}})]})})]})}function Ar({onSelectCoin:t,className:e}){let{filteredCoins:r,isLoading:s,searchQuery:n,setSearchQuery:a,handleSelectCoin:i}=De({onSelectCoin:t});return jsxRuntime.jsx("div",{className:e,children:jsxRuntime.jsx(Ee,{coins:r,searchQuery:n,onSearchChange:a,onSelectCoin:i,isLoading:s})})}function $t(t,e){if(e<=0)return t;let r=new Map;return t.forEach(s=>{let n=Math.floor(s.price/e)*e,a=r.get(n);a?(a.quantity+=s.quantity,s.count&&(a.count=(a.count||0)+s.count)):r.set(n,{price:n,quantity:s.quantity,count:s.count});}),Array.from(r.values())}function Kt(t){let e=0,r=t.map(n=>(e+=n.quantity,{...n,total:e,percentage:0})),s=e;return r.map(n=>({...n,percentage:s>0?n.total/s*100:0}))}function Qe({symbol:t,maxLevel:e=20,precision:r=.01}){let[s,n]=react.useState(null),[a,i]=react.useState(r),{data:o,isPending:l}=he({symbol:t,maxLevel:e}),{data:u}=K({type:"orderBook",symbol:t,enabled:!!o});return react.useEffect(()=>{u?n(u):o&&n(o);},[u,o]),{...react.useMemo(()=>{if(!s)return {bids:[],asks:[],spread:0,spreadPercentage:0};let m=$t(s.bids,a),p=$t(s.asks,a),c=m.sort((V,q)=>q.price-V.price).slice(0,e),y=p.sort((V,q)=>V.price-q.price).slice(0,e),f=Kt(c),g=Kt(y),S=f[0]?.price||0,re=(g[0]?.price||0)-S,ue=S>0?re/S*100:0;return {bids:f,asks:g,spread:re,spreadPercentage:ue}},[s,a,e]),isLoading:l,precision:a,setPrecision:i}}function qe(t){return t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function pe(t){return t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":t.toFixed(2)}function Be({bids:t,asks:e,spread:r,spreadPercentage:s,onPriceClick:n}){let a=[...e].reverse();return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 text-xs",children:[jsxRuntime.jsx("div",{className:"flex-1 flex flex-col-reverse overflow-hidden",children:a.map((i,o)=>jsxRuntime.jsxs("div",{className:"relative h-6 flex items-center justify-between px-2 cursor-pointer hover:bg-neutral-900/50 transition-colors",onClick:()=>n?.(i.price),children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-red-500/10",style:{width:`${i.percentage}%`,right:0,left:"auto"}}),jsxRuntime.jsx("span",{className:"relative z-10 text-red-500 font-medium min-w-20",children:qe(i.price)}),jsxRuntime.jsxs("div",{className:"relative z-10 flex gap-4 text-neutral-300",children:[jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:pe(i.quantity)}),jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:pe(i.total)})]})]},`ask-${i.price}-${o}`))}),jsxRuntime.jsx("div",{className:"flex items-center justify-center py-2 border-y border-neutral-800 bg-neutral-900",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Spread:"}),jsxRuntime.jsx("span",{className:"text-neutral-200 font-medium",children:qe(r)}),jsxRuntime.jsxs("span",{className:"text-neutral-400",children:[s.toFixed(3),"%"]})]})}),jsxRuntime.jsx("div",{className:"flex-1 overflow-hidden",children:t.map((i,o)=>jsxRuntime.jsxs("div",{className:"relative h-6 flex items-center justify-between px-2 cursor-pointer hover:bg-neutral-900/50 transition-colors",onClick:()=>n?.(i.price),children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-green-500/10",style:{width:`${i.percentage}%`,right:0,left:"auto"}}),jsxRuntime.jsx("span",{className:"relative z-10 text-green-500 font-medium min-w-20",children:qe(i.price)}),jsxRuntime.jsxs("div",{className:"relative z-10 flex gap-4 text-neutral-300",children:[jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:pe(i.quantity)}),jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:pe(i.total)})]})]},`bid-${i.price}-${o}`))})]})}function Wr(){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 p-2 gap-1",children:[Array.from({length:15}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]},`ask-skeleton-${e}`)),jsxRuntime.jsx("div",{className:"py-2",children:jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-40 mx-auto rounded"})}),Array.from({length:15}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]},`bid-skeleton-${e}`))]})}function Lr(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full bg-neutral-950",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"No order book data available"})})}function Hr({symbol:t,maxLevel:e=20,onPriceClick:r,className:s}){let{bids:n,asks:a,spread:i,spreadPercentage:o,isLoading:l}=Qe({symbol:t,maxLevel:e});return l?jsxRuntime.jsx(Wr,{}):n.length===0&&a.length===0?jsxRuntime.jsx(Lr,{}):jsxRuntime.jsx("div",{className:s,children:jsxRuntime.jsx(Be,{bids:n,asks:a,spread:i,spreadPercentage:o,onPriceClick:r})})}function Ae({symbol:t,limit:e=50}){let[r,s]=react.useState([]),{data:n,isPending:a}=Pe({symbol:t,limit:e}),{data:i}=K({type:"trades",symbol:t,enabled:!!n});return react.useEffect(()=>{n&&s(n.filter(Lt));},[n]),react.useEffect(()=>{i&&s(o=>{let l=Vr(i);if(l.length===0)return o;let u=l.filter(m=>!o.some(p=>p.timestamp===m.timestamp&&p.price===m.price&&p.quantity===m.quantity));return u.length===0?o:[...u,...o].slice(0,e)});},[i,e]),{trades:r,isLoading:a}}function Vr(t){return (Array.isArray(t)?t:[t]).filter(Lt)}function Lt(t){return t?typeof t.symbol=="string"&&(t.side==="buy"||t.side==="sell")&&typeof t.price=="number"&&Number.isFinite(t.price)&&typeof t.quantity=="number"&&Number.isFinite(t.quantity)&&typeof t.timestamp=="number"&&Number.isFinite(t.timestamp):false}function Gr(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function Ht(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":t.toFixed(2)}function jr(t){if(typeof t!="number"||!Number.isFinite(t))return "-";let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),n=String(e.getSeconds()).padStart(2,"0");return `${r}:${s}:${n}`}function Ke({trades:t,onTradeClick:e}){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 overflow-auto",children:[jsxRuntime.jsx("div",{className:"sticky top-0 z-10 bg-neutral-900 border-b border-neutral-800 px-2 py-2",children:jsxRuntime.jsxs("div",{className:"flex justify-between text-xs text-neutral-400",children:[jsxRuntime.jsx("span",{className:"min-w-20",children:"Price"}),jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:"Amount"}),jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:"Total"}),jsxRuntime.jsx("span",{className:"min-w-16 text-right",children:"Time"})]})}),jsxRuntime.jsx("div",{className:"flex-1",children:t.map((r,s)=>{let n=r.side==="buy",a=typeof r.price=="number"&&Number.isFinite(r.price)&&typeof r.quantity=="number"&&Number.isFinite(r.quantity)?r.price*r.quantity:void 0;return jsxRuntime.jsxs("div",{className:"flex justify-between items-center px-2 py-1 hover:bg-neutral-900/50 cursor-pointer transition-colors text-xs",onClick:()=>e?.(r),children:[jsxRuntime.jsx("span",{className:ui.cn("min-w-20 font-medium",n?"text-green-500":"text-red-500"),children:Gr(r.price)}),jsxRuntime.jsx("span",{className:"min-w-16 text-right text-neutral-300",children:Ht(r.quantity)}),jsxRuntime.jsx("span",{className:"min-w-16 text-right text-neutral-300",children:Ht(a)}),jsxRuntime.jsx("span",{className:"min-w-16 text-right text-neutral-400",children:jr(r.timestamp)})]},`${r.timestamp}-${r.price}-${s}`)})})]})}function Jr(){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 p-2 gap-1",children:[jsxRuntime.jsxs("div",{className:"flex justify-between mb-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"})]}),Array.from({length:20}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]},`trade-skeleton-${e}`))]})}function Yr(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full bg-neutral-950",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"No recent trades"})})}function Xr({symbol:t,limit:e=50,onTradeClick:r,className:s}){let{trades:n,isLoading:a}=Ae({symbol:t,limit:e});return a?jsxRuntime.jsx(Jr,{}):n.length===0?jsxRuntime.jsx(Yr,{}):jsxRuntime.jsx("div",{className:s,children:jsxRuntime.jsx(Ke,{trades:n,onTradeClick:r})})}function Le({symbol:t,userAddress:e,onSuccess:r,onError:s}){let[n,a]=react.useState("long"),[i,o]=react.useState("market"),l=reactHookForm.useForm({defaultValues:{amount:0,leverage:1,takeProfitPercent:0,stopLossPercent:0}}),{data:u}=ae({symbol:t}),{mutateAsync:d,isPending:m}=ie({onSuccess:()=>{l.reset(),r?.();},onError:C=>{s?.(C);}}),p=l.watch(),{amount:c,leverage:y,price:f}=p,g=react.useMemo(()=>i==="limit"&&f?f:u?.price||0,[i,f,u?.price]),S=react.useMemo(()=>!c||!g?0:c*g*5e-4,[c,g]),k=react.useMemo(()=>!c||!g?0:c*g+S,[c,g,S]),re=react.useMemo(()=>{if(!c||!g||!y||y===1)return;let C=.005,ce=g;return n==="long"?ce*(1-(1/y-C)):ce*(1+(1/y-C))},[c,g,y,n]),ue=1e4,V=1e4,q=0,tr=react.useCallback(async C=>{if(!e)throw new Error("User address is required");let ce=i==="limit"?C.price:void 0,ot,lt;if(C.takeProfitPercent&&C.takeProfitPercent>0&&g){let se=C.takeProfitPercent/100;ot=n==="long"?g*(1+se):g*(1-se);}if(C.stopLossPercent&&C.stopLossPercent>0&&g){let se=C.stopLossPercent/100;lt=n==="long"?g*(1-se):g*(1+se);}await d({symbol:t,side:n,orderType:i,amount:C.amount,price:ce,leverage:C.leverage,takeProfitPrice:ot,stopLossPrice:lt,userAddress:e});},[t,n,i,g,e,d]);return {form:l,side:n,orderType:i,setSide:a,setOrderType:o,handleSubmit:tr,isSubmitting:m,currentPrice:g,estimatedFee:S,estimatedTotal:k,liquidationPrice:re,availableMargin:ue,accountValue:V,currentPosition:q}}function J(t,e=2){return t.toFixed(e)}function Vt({name:t,placeholder:e,endContent:r}){return jsxRuntime.jsx(ui.RHNumberInput,{name:t,placeholder:e,className:"w-full",endContent:r})}function He({methods:t,side:e,orderType:r,onSideChange:s,onOrderTypeChange:n,onSubmit:a,isSubmitting:i,symbol:o,currentPrice:l,estimatedFee:u,liquidationPrice:d,availableMargin:m,accountValue:p,currentPosition:c}){let y=t.watch("leverage")||1,f=t.watch("takeProfitPercent")||0,g=t.watch("stopLossPercent")||0,S=[{label:"0%",value:0},{label:"25%",value:25},{label:"50%",value:50},{label:"75%",value:75},{label:"100%",value:100}];return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 p-4 gap-4",children:[jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Button,{className:ui.cn("flex-1 h-10",e==="long"?"bg-green-600 hover:bg-green-700 text-white":"bg-neutral-800 hover:bg-neutral-700 text-neutral-400"),onClick:()=>s("long"),children:"Long"}),jsxRuntime.jsx(ui.Button,{className:ui.cn("flex-1 h-10",e==="short"?"bg-red-600 hover:bg-red-700 text-white":"bg-neutral-800 hover:bg-neutral-700 text-neutral-400"),onClick:()=>s("short"),children:"Short"})]}),jsxRuntime.jsxs("div",{className:"flex gap-2 text-sm",children:[jsxRuntime.jsx("button",{type:"button",className:ui.cn("px-4 py-2 rounded transition-colors",r==="market"?"bg-neutral-800 text-white":"text-neutral-400 hover:text-white"),onClick:()=>n("market"),children:"Market"}),jsxRuntime.jsx("button",{type:"button",className:ui.cn("px-4 py-2 rounded transition-colors",r==="limit"?"bg-neutral-800 text-white":"text-neutral-400 hover:text-white"),onClick:()=>n("limit"),children:"Limit"})]}),jsxRuntime.jsx(ui.RHForm,{methods:t,onSubmit:a,children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[r==="limit"&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs text-neutral-400 mb-1 block",children:"Price"}),jsxRuntime.jsx(Vt,{name:"price",placeholder:"0.0",endContent:jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:"USDC"})})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs text-neutral-400 mb-1 block",children:"Buy Amount"}),jsxRuntime.jsx(Vt,{name:"amount",placeholder:"0.0",endContent:jsxRuntime.jsx("span",{className:"text-neutral-400 text-xs",children:o.split("-")[0]})}),l&&jsxRuntime.jsxs("div",{className:"text-xs text-neutral-500 mt-1",children:["\u2248 ",J((t.watch("amount")||0)*l)," ","USDC"]})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-2",children:[jsxRuntime.jsx("label",{className:"text-xs text-neutral-400",children:"Leverage"}),jsxRuntime.jsxs("span",{className:"text-sm text-white font-medium",children:[y,"x"]})]}),jsxRuntime.jsx(ui.Slider,{value:[y],onChange:k=>t.setValue("leverage",Array.isArray(k)?k[0]:k),minValue:1,maxValue:10,step:1,className:"w-full"}),jsxRuntime.jsxs("div",{className:"flex justify-between text-xs text-neutral-500 mt-1",children:[jsxRuntime.jsx("span",{children:"1x"}),jsxRuntime.jsx("span",{children:"10x"})]})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs text-neutral-400 mb-2 block",children:"TP/SL"}),jsxRuntime.jsx("div",{className:"flex gap-2 mb-2",children:S.map(k=>jsxRuntime.jsx("button",{type:"button",className:ui.cn("flex-1 py-1.5 text-xs rounded transition-colors",f===k.value?"bg-green-600 text-white":"bg-neutral-800 text-neutral-400 hover:bg-neutral-700"),onClick:()=>t.setValue("takeProfitPercent",k.value),children:k.label},`tp-${k.value}`))}),jsxRuntime.jsx("div",{className:"flex gap-2",children:S.map(k=>jsxRuntime.jsx("button",{type:"button",className:ui.cn("flex-1 py-1.5 text-xs rounded transition-colors",g===k.value?"bg-red-600 text-white":"bg-neutral-800 text-neutral-400 hover:bg-neutral-700"),onClick:()=>t.setValue("stopLossPercent",k.value),children:k.label},`sl-${k.value}`))})]}),jsxRuntime.jsx(ui.Button,{type:"submit",isLoading:i,className:ui.cn("w-full h-12 font-semibold text-white",e==="long"?"bg-green-600 hover:bg-green-700":"bg-red-600 hover:bg-red-700"),children:e==="long"?"Buy / Long":"Sell / Short"}),jsxRuntime.jsx(ui.Button,{type:"button",className:"w-full h-10 bg-green-600 hover:bg-green-700 text-white font-medium",children:"Add More Funds"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2 text-xs border-t border-neutral-800 pt-4",children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Available Margin"}),jsxRuntime.jsxs("span",{className:"text-white",children:[J(m)," USDC"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Perps Account Value"}),jsxRuntime.jsxs("span",{className:"text-white",children:[J(p)," USDC"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Current Position"}),jsxRuntime.jsx("span",{className:"text-white",children:c?J(c):"0.00"})]}),d&&jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Est. Liquidation Price"}),jsxRuntime.jsx("span",{className:"text-red-400",children:J(d,4)})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Est. Fee"}),jsxRuntime.jsxs("span",{className:"text-white",children:[J(u,4)," USDC"]})]})]})]})})]})}function ns({symbol:t,userAddress:e,onSuccess:r,onError:s,className:n}){let{form:a,side:i,orderType:o,setSide:l,setOrderType:u,handleSubmit:d,isSubmitting:m,currentPrice:p,estimatedFee:c,estimatedTotal:y,liquidationPrice:f,availableMargin:g,accountValue:S,currentPosition:k}=Le({symbol:t,userAddress:e,onSuccess:r,onError:s});return jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(He,{methods:a,side:i,orderType:o,onSideChange:l,onOrderTypeChange:u,onSubmit:d,isSubmitting:m,symbol:t,currentPrice:p,estimatedFee:c,estimatedTotal:y,liquidationPrice:f,availableMargin:g,accountValue:S,currentPosition:k})})}function ze({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s}){let[n,a]=react.useState([]),{data:i,isLoading:o,error:l}=ve({userAddress:t,symbol:e},{enabled:!!t}),{data:u}=oe({type:"positions",userAddress:t||"",enabled:!!t}),{mutateAsync:d,isPending:m}=ie({onSuccess:()=>{r?.();},onError:c=>{s?.(c);}});react.useEffect(()=>{i?.positions&&a(i.positions);},[i]),react.useEffect(()=>{u&&a(c=>{let y=c.findIndex(f=>f.symbol===u.symbol);if(u.quantity===0)return y!==-1?c.filter((f,g)=>g!==y):c;if(y!==-1){let f=[...c];return f[y]=u,f}return [...c,u]});},[u]);let p=react.useCallback(async c=>{if(!t)throw new Error("User address is required");let y=c.side==="long"?"short":"long";await d({symbol:c.symbol,side:y,orderType:"market",amount:Math.abs(c.quantity),leverage:c.leverage,userAddress:t});},[t,d]);return {positions:n,isLoading:o,error:l,handleClosePosition:p,isClosing:m}}function Y(t,e=2){return t.toFixed(e)}function Ve(t){return Y(t,4)}function ls(t){return Y(Math.abs(t),4)}function us(t){return `${t>=0?"+":""}${Y(t,2)}`}function cs(t){return `${t>=0?"+":""}${Y(t,2)}%`}function _e({positions:t,onClosePosition:e,isClosing:r}){return t.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No open positions"}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800",children:[jsxRuntime.jsx("th",{className:"text-left py-3 px-4 text-neutral-400 font-normal",children:"Asset"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Position"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Position Value"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Entry Price"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Mark Price"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Liquidation Price"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Margin Used (PnL)"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"TP / SL"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Close"})]})}),jsxRuntime.jsx("tbody",{children:t.map(s=>{let a=s.unrealizedPnl>=0?"text-green-500":"text-red-500";return jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800 hover:bg-neutral-900/50",children:[jsxRuntime.jsx("td",{className:"py-3 px-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-white font-medium",children:s.symbol.split("-")[0]}),jsxRuntime.jsxs("span",{className:ui.cn("text-xs",s.side==="long"?"text-green-500":"text-red-500"),children:[s.leverage,"x ",s.side.toUpperCase()]})]})}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:ls(s.quantity)}),jsxRuntime.jsxs("td",{className:"py-3 px-4 text-right text-white",children:["$",Y(s.notionalValue)]}),jsxRuntime.jsxs("td",{className:"py-3 px-4 text-right text-white",children:["$",Ve(s.entryPrice)]}),jsxRuntime.jsxs("td",{className:"py-3 px-4 text-right text-white",children:["$",Ve(s.markPrice)]}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:s.liquidationPrice?`$${Ve(s.liquidationPrice)}`:"-"}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsxs("span",{className:"text-white",children:["$",Y(s.margin)]}),jsxRuntime.jsxs("span",{className:ui.cn("text-xs",a),children:[us(s.unrealizedPnl)," (",cs(s.unrealizedPnlPercent),")"]})]})}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-neutral-400",children:"-"}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",onClick:()=>e(s),isLoading:r,className:"bg-red-600 hover:bg-red-700 text-white text-xs px-3 py-1",children:"Close"})})]},s.symbol)})})]})})}function Ge(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function je(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No open positions"})}function ds({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s,className:n}){let{positions:a,isLoading:i,handleClosePosition:o,isClosing:l}=ze({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Ge,{})}):a.length===0?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(je,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(_e,{positions:a,onClosePosition:o,isClosing:l})})}function Je({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s}){let[n,a]=react.useState([]),{data:i,isLoading:o,error:l}=Ne({userAddress:t,symbol:e},{enabled:!!t}),{data:u}=oe({type:"orders",userAddress:t||"",enabled:!!t}),{mutateAsync:d,isPending:m}=ke({onSuccess:()=>{r?.();},onError:c=>{s?.(c);}});react.useEffect(()=>{i?.orders&&a(i.orders);},[i]),react.useEffect(()=>{u&&a(c=>{let y=c.findIndex(f=>f.orderId===u.orderId);if(u.status==="cancelled"||u.status==="filled"||u.status==="rejected")return y!==-1?c.filter((f,g)=>g!==y):c;if(y!==-1){let f=[...c];return f[y]=u,f}return [u,...c]});},[u]);let p=react.useCallback(async c=>{if(!t)throw new Error("User address is required");await d({orderId:c.orderId,symbol:c.symbol,userAddress:t});},[t,d]);return {orders:n,isLoading:o,error:l,handleCancelOrder:p,isCanceling:m}}function Xt(t,e=2){return t.toFixed(e)}function ys(t){return Xt(t,4)}function Ye(t){return Xt(t,4)}function gs(t){let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),n=String(e.getSeconds()).padStart(2,"0");return `${r}:${s}:${n}`}function Xe({orders:t,onCancelOrder:e,isCanceling:r}){return t.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No open orders"}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800",children:[jsxRuntime.jsx("th",{className:"text-left py-3 px-4 text-neutral-400 font-normal",children:"Asset"}),jsxRuntime.jsx("th",{className:"text-left py-3 px-4 text-neutral-400 font-normal",children:"Type"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Price"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Amount"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Filled"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Remaining"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Status"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Time"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Action"})]})}),jsxRuntime.jsx("tbody",{children:t.map(s=>jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800 hover:bg-neutral-900/50",children:[jsxRuntime.jsx("td",{className:"py-3 px-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-white font-medium",children:s.symbol.split("-")[0]}),jsxRuntime.jsxs("span",{className:ui.cn("text-xs",s.side==="long"?"text-green-500":"text-red-500"),children:[s.side.toUpperCase(),s.leverage?` ${s.leverage}x`:""]})]})}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-white capitalize",children:s.orderType}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:s.orderType==="market"?jsxRuntime.jsx("span",{className:"text-neutral-400",children:"Market"}):`$${ys(s.price)}`}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:Ye(s.quantity)}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:Ye(s.filledQuantity)}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:Ye(s.remainingQuantity)}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right",children:jsxRuntime.jsx("span",{className:ui.cn("text-xs px-2 py-1 rounded",s.status==="pending"&&"bg-yellow-600/20 text-yellow-500",s.status==="partially_filled"&&"bg-blue-600/20 text-blue-500",s.status==="filled"&&"bg-green-600/20 text-green-500",s.status==="cancelled"&&"bg-neutral-600/20 text-neutral-400",s.status==="rejected"&&"bg-red-600/20 text-red-500"),children:s.status.replace("_"," ")})}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-neutral-400",children:gs(s.timestamp)}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right",children:s.status==="pending"||s.status==="partially_filled"?jsxRuntime.jsx(ui.Button,{size:"sm",onClick:()=>e(s),isLoading:r,className:"bg-red-600 hover:bg-red-700 text-white text-xs px-3 py-1",children:"Cancel"}):jsxRuntime.jsx("span",{className:"text-neutral-600 text-xs",children:"-"})})]},s.orderId))})]})})}function Ze(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function et(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No open orders"})}function xs({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s,className:n}){let{orders:a,isLoading:i,handleCancelOrder:o,isCanceling:l}=Je({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Ze,{})}):a.length===0?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(et,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Xe,{orders:a,onCancelOrder:o,isCanceling:l})})}function bs(t){let e=Date.now(),r=e;switch(t){case "today":let s=new Date;return s.setHours(0,0,0,0),{startTime:s.getTime(),endTime:r};case "7d":return {startTime:e-10080*60*1e3,endTime:r};case "30d":return {startTime:e-720*60*60*1e3,endTime:r};default:return {}}}function rt({userAddress:t,symbol:e,initialTimeRange:r="7d",pageSize:s=50}){let[n,a]=react.useState(r),[i,o]=react.useState(1),[l,u]=react.useState([]),{startTime:d,endTime:m}=bs(n),{data:p,isLoading:c,error:y}=we({userAddress:t,symbol:e,startTime:d,endTime:m,limit:1e3},{enabled:!!t});react.useEffect(()=>{p?.trades&&(u(p.trades),o(1));},[p]),react.useEffect(()=>{o(1);},[n]);let f=Math.ceil(l.length/s),g=(i-1)*s,S=g+s;return {trades:l.slice(g,S),isLoading:c,error:y,timeRange:n,setTimeRange:a,currentPage:i,totalPages:f,goToNextPage:()=>{i<f&&o(i+1);},goToPreviousPage:()=>{i>1&&o(i-1);},goToPage:q=>{q>=1&&q<=f&&o(q);}}}function st(t,e=2){return t.toFixed(e)}function hs(t){return st(t,4)}function Ps(t){return st(t,4)}function vs(t){let e=new Date(t),r=String(e.getMonth()+1).padStart(2,"0"),s=String(e.getDate()).padStart(2,"0"),n=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return `${r}/${s} ${n}:${a}:${i}`}var Ns=[{label:"Today",value:"today"},{label:"7 Days",value:"7d"},{label:"30 Days",value:"30d"},{label:"All",value:"all"}];function nt({trades:t,timeRange:e,onTimeRangeChange:r,currentPage:s,totalPages:n,onNextPage:a,onPreviousPage:i,onGoToPage:o}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4",children:[jsxRuntime.jsx("div",{className:"flex gap-2",children:Ns.map(l=>jsxRuntime.jsx("button",{type:"button",className:ui.cn("px-4 py-2 text-sm rounded transition-colors",e===l.value?"bg-neutral-800 text-white":"text-neutral-400 hover:text-white hover:bg-neutral-800/50"),onClick:()=>r(l.value),children:l.label},l.value))}),t.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No trade history"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800",children:[jsxRuntime.jsx("th",{className:"text-left py-3 px-4 text-neutral-400 font-normal",children:"Asset"}),jsxRuntime.jsx("th",{className:"text-left py-3 px-4 text-neutral-400 font-normal",children:"Side"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Price"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Quantity"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Fee"}),jsxRuntime.jsx("th",{className:"text-center py-3 px-4 text-neutral-400 font-normal",children:"Maker/Taker"}),jsxRuntime.jsx("th",{className:"text-right py-3 px-4 text-neutral-400 font-normal",children:"Time"})]})}),jsxRuntime.jsx("tbody",{children:t.map(l=>jsxRuntime.jsxs("tr",{className:"border-b border-neutral-800 hover:bg-neutral-900/50",children:[jsxRuntime.jsx("td",{className:"py-3 px-4 text-white font-medium",children:l.symbol.split("-")[0]}),jsxRuntime.jsx("td",{className:"py-3 px-4",children:jsxRuntime.jsx("span",{className:ui.cn("text-xs px-2 py-1 rounded",l.side==="long"?"bg-green-600/20 text-green-500":"bg-red-600/20 text-red-500"),children:l.side.toUpperCase()})}),jsxRuntime.jsxs("td",{className:"py-3 px-4 text-right text-white",children:["$",hs(l.price)]}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-white",children:Ps(l.quantity)}),jsxRuntime.jsxs("td",{className:"py-3 px-4 text-right text-white",children:[st(l.fee,4)," ",l.feeCurrency]}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-center",children:jsxRuntime.jsx("span",{className:ui.cn("text-xs px-2 py-1 rounded",l.isMaker?"bg-blue-600/20 text-blue-500":"bg-purple-600/20 text-purple-500"),children:l.isMaker?"Maker":"Taker"})}),jsxRuntime.jsx("td",{className:"py-3 px-4 text-right text-neutral-400",children:vs(l.timestamp)})]},l.tradeId))})]})}),n>1&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"text-sm text-neutral-400",children:["Page ",s," of ",n]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",onClick:i,disabled:s===1,className:"bg-neutral-800 hover:bg-neutral-700 text-white disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),jsxRuntime.jsx("div",{className:"flex gap-1",children:Array.from({length:Math.min(5,n)},(l,u)=>{let d;return n<=5||s<=3?d=u+1:s>=n-2?d=n-4+u:d=s-2+u,jsxRuntime.jsx("button",{type:"button",className:ui.cn("w-8 h-8 text-sm rounded transition-colors",s===d?"bg-neutral-700 text-white":"text-neutral-400 hover:bg-neutral-800 hover:text-white"),onClick:()=>o(d),children:d},d)})}),jsxRuntime.jsx(ui.Button,{size:"sm",onClick:a,disabled:s===n,className:"bg-neutral-800 hover:bg-neutral-700 text-white disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})]})}function at(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function it(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-48 text-neutral-400 text-sm",children:"No trade history"})}function ks({userAddress:t,symbol:e,initialTimeRange:r="7d",pageSize:s=50,className:n}){let{trades:a,isLoading:i,timeRange:o,setTimeRange:l,currentPage:u,totalPages:d,goToNextPage:m,goToPreviousPage:p,goToPage:c}=rt({userAddress:t,symbol:e,initialTimeRange:r,pageSize:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(at,{})}):a.length===0?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(it,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(nt,{trades:a,timeRange:o,onTimeRangeChange:l,currentPage:u,totalPages:d,onNextPage:m,onPreviousPage:p,onGoToPage:c})})}
2
- exports.CoinInfoNotFoundUI=Te;exports.CoinInfoSkeletonsUI=Ue;exports.CoinInfoUI=Me;exports.CoinInfoWidget=Ur;exports.HyperliquidApiError=$;exports.HyperliquidPerpetualsClient=ge;exports.OpenOrdersEmpty=et;exports.OpenOrdersSkeleton=Ze;exports.OpenOrdersUI=Xe;exports.OpenOrdersWidget=xs;exports.OrderBookUI=Be;exports.OrderBookWidget=Hr;exports.PerpetualsContext=ne;exports.PerpetualsProvider=nr;exports.PlaceOrderFormUI=He;exports.PlaceOrderFormWidget=ns;exports.PositionsEmpty=je;exports.PositionsSkeleton=Ge;exports.PositionsUI=_e;exports.PositionsWidget=ds;exports.SearchCoinsUI=Ee;exports.SearchCoinsWidget=Ar;exports.TradeHistoryEmpty=it;exports.TradeHistorySkeleton=at;exports.TradeHistoryUI=nt;exports.TradeHistoryWidget=ks;exports.TradesUI=Ke;exports.TradesWidget=Xr;exports.cancelOrder=Ut;exports.coinsQueryKey=ct;exports.createOrder=Tt;exports.fetchCoins=dt;exports.fetchKlines=xt;exports.fetchMarket=mt;exports.fetchMarkets=yt;exports.fetchOrderBook=ht;exports.fetchOrders=Ct;exports.fetchPositions=wt;exports.fetchRecentTrades=vt;exports.fetchTrades=Ot;exports.klinesQueryKey=gt;exports.marketQueryKey=pt;exports.marketsQueryKey=ft;exports.orderBookQueryKey=bt;exports.ordersQueryKey=kt;exports.positionsQueryKey=Nt;exports.recentTradesQueryKey=Pt;exports.tradesQueryKey=St;exports.useCancelOrderMutation=ke;exports.useCandlesSubscription=wr;exports.useCoinInfo=Ie;exports.useCoinsQuery=xe;exports.useCreateOrderMutation=ie;exports.useKlinesQuery=dr;exports.useMarketDataSubscription=K;exports.useMarketQuery=ae;exports.useMarketsQuery=be;exports.useOpenOrdersScript=Je;exports.useOrderBookQuery=he;exports.useOrderBookScript=Qe;exports.useOrdersQuery=Ne;exports.usePerpetualsClient=h;exports.usePlaceOrderFormScript=Le;exports.usePositionsQuery=ve;exports.usePositionsScript=ze;exports.useRecentTradesQuery=Pe;exports.useSearchCoinsScript=De;exports.useTradeHistoryScript=rt;exports.useTradesQuery=we;exports.useTradesScript=Ae;exports.useUserDataSubscription=oe;exports.version=rr;//# sourceMappingURL=index.js.map
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactQuery=require('@tanstack/react-query'),ui=require('@liberfi.io/ui'),reactHookForm=require('react-hook-form');typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-perpetuals"]="0.1.97");var er="0.1.97";var de=class{ws=null;wsEndpoint;subscriptions=new Map;reconnectAttempts=0;maxReconnectAttempts=10;reconnectDelay=1e3;heartbeatInterval=null;messageQueue=[];isConnected=false;pingInterval=3e4;reconnectTimeout=null;isReconnecting=false;constructor(e){this.wsEndpoint=e;}async connect(){return new Promise((e,r)=>{try{this.ws&&this.ws.close(),this.ws=new WebSocket(this.wsEndpoint),this.ws.onopen=()=>{console.log("[WebSocket] Connected to Hyperliquid"),this.isConnected=!0,this.reconnectAttempts=0,this.isReconnecting=!1,this.startHeartbeat(),this.flushMessageQueue(),e();},this.ws.onmessage=s=>{this.handleMessage(s.data);},this.ws.onerror=s=>{console.error("[WebSocket] Error:",s),this.isConnected=!1,this.isReconnecting||r(new Error("WebSocket connection failed"));},this.ws.onclose=s=>{console.log(`[WebSocket] Closed: ${s.code} - ${s.reason||"No reason provided"}`),this.isConnected=!1,this.stopHeartbeat(),s.code!==1e3&&this.attemptReconnect();};}catch(s){r(s);}})}disconnect(){this.stopHeartbeat(),this.subscriptions.clear(),this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(1e3,"Normal closure"),this.ws=null),this.isConnected=false,this.isReconnecting=false,this.reconnectAttempts=0;}attemptReconnect(){if(this.isReconnecting)return;if(this.reconnectAttempts>=this.maxReconnectAttempts){console.error("[WebSocket] Max reconnection attempts reached");return}this.isReconnecting=true,this.reconnectAttempts++;let e=Math.min(this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1),3e4);console.log(`[WebSocket] Reconnecting in ${e}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`),this.reconnectTimeout=window.setTimeout(()=>{this.connect().then(()=>{this.resubscribeAll();}).catch(r=>{console.error("[WebSocket] Reconnection failed:",r),this.isReconnecting=false;});},e);}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.isConnected&&this.ws&&this.ws.readyState===WebSocket.OPEN&&this.send({method:"ping"});},this.pingInterval);}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null);}send(e){this.isConnected&&this.ws&&this.ws.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(e)):this.messageQueue.push(e);}flushMessageQueue(){for(;this.messageQueue.length>0;){let e=this.messageQueue.shift();e&&this.send(e);}}resubscribeAll(){this.subscriptions.forEach(e=>{this.sendSubscription(e.type,e.param);});}handleMessage(e){try{let r=JSON.parse(e);r.channel?this.handleChannelMessage(r):r.method;}catch(r){console.error("[WebSocket] Failed to parse message:",r,e);}}handleChannelMessage(e){let r=e.channel;this.subscriptions.forEach((s,n)=>{if(this.isChannelMatch(r,s.type,s.param))try{let o=this.transformData(s.type,e.data,s.param);s.callback(o);}catch(o){console.error(`[WebSocket] Error in subscription callback (${n}):`,o);}});}isChannelMatch(e,r,s){return r==="ticker"?e==="allMids":r==="trades"?e==="trades":r==="orderBook"?e==="l2Book":r==="candle"?e==="candle":r==="userFills"?e==="userFills":r==="userEvents"?e==="userEvents":false}transformData(e,r,s){return e==="ticker"?this.transformTickerData(r):e==="trades"?this.transformTradesData(r,s):e==="orderBook"?this.transformOrderBookData(r,s):e==="candle"?this.transformCandleData(r,s):e==="userFills"?this.transformUserFillsData(r):e==="userEvents"?this.transformUserEventsData(r):r}transformTickerData(e){let r=e.mids||{};return Object.entries(r).map(([s,n])=>({symbol:`${s}-USDC`,price:parseFloat(n),timestamp:Date.now()}))}transformTradesData(e,r){return Array.isArray(e)?e.map(s=>({symbol:r,side:s.side==="B"?"buy":"sell",price:parseFloat(s.px),quantity:parseFloat(s.sz),timestamp:s.time,tradeId:s.tid})):[]}transformOrderBookData(e,r){let[s,n]=e.levels||[[],[]];return {symbol:r,bids:s.map(o=>({price:parseFloat(o.px),quantity:parseFloat(o.sz),count:o.n})),asks:n.map(o=>({price:parseFloat(o.px),quantity:parseFloat(o.sz),count:o.n})),timestamp:e.time||Date.now()}}transformCandleData(e,r){let[s]=r.split(":");return {symbol:s,open:parseFloat(e.o),high:parseFloat(e.h),low:parseFloat(e.l),close:parseFloat(e.c),volume:parseFloat(e.v),timestamp:e.t,closeTimestamp:e.T}}transformUserFillsData(e){return Array.isArray(e)?e.map(r=>({tradeId:r.tid?.toString(),orderId:r.oid?.toString(),symbol:`${r.coin}-USDC`,side:r.dir?.includes("Long")?"long":"short",price:parseFloat(r.px),quantity:parseFloat(r.sz),fee:parseFloat(r.fee||"0"),feeCurrency:r.feeToken||"USDC",isMaker:r.side==="M",timestamp:r.time})):[]}transformUserEventsData(e){return e}sendSubscription(e,r){let s;if(e==="ticker")s={method:"subscribe",subscription:{type:"allMids"}};else if(e==="trades")s={method:"subscribe",subscription:{type:"trades",coin:r.split("-")[0]}};else if(e==="orderBook")s={method:"subscribe",subscription:{type:"l2Book",coin:r.split("-")[0]}};else if(e==="candle"){let[n,o]=r.split(":");s={method:"subscribe",subscription:{type:"candle",coin:n.split("-")[0],interval:o}};}else e==="userFills"?s={method:"subscribe",subscription:{type:"userFills",user:r}}:e==="userEvents"&&(s={method:"subscribe",subscription:{type:"userEvents",user:r}});s&&this.send(s);}sendUnsubscription(e,r){let s;if(e==="ticker")s={method:"unsubscribe",subscription:{type:"allMids"}};else if(e==="trades")s={method:"unsubscribe",subscription:{type:"trades",coin:r.split("-")[0]}};else if(e==="orderBook")s={method:"unsubscribe",subscription:{type:"l2Book",coin:r.split("-")[0]}};else if(e==="candle"){let[n,o]=r.split(":");s={method:"unsubscribe",subscription:{type:"candle",coin:n.split("-")[0],interval:o}};}else e==="userFills"?s={method:"unsubscribe",subscription:{type:"userFills",user:r}}:e==="userEvents"&&(s={method:"unsubscribe",subscription:{type:"userEvents",user:r}});s&&this.send(s);}subscribe(e,r,s){let n=`${e}:${r}`;return this.subscriptions.set(n,{type:e,param:r,callback:s}),this.sendSubscription(e,r),n}unsubscribe(e){let r=this.subscriptions.get(e);r&&(this.sendUnsubscription(r.type,r.param),this.subscriptions.delete(e));}isConnectedNow(){return this.isConnected}};var at={testnet:{api:"https://api.hyperliquid-testnet.xyz",ws:"wss://api.hyperliquid-testnet.xyz/ws"},mainnet:{api:"https://api.hyperliquid.xyz",ws:"wss://api.hyperliquid.xyz/ws"}},xe=class{apiEndpoint;_wsEndpoint;timeout;environment;wsManager=null;constructor(e={}){this.environment=e.environment||"testnet",this.apiEndpoint=e.apiEndpoint||at[this.environment].api,this._wsEndpoint=e.wsEndpoint||at[this.environment].ws,this.timeout=e.timeout||3e4;}async request(e,r){let s=`${this.apiEndpoint}${e}`;try{let n=new AbortController,o=setTimeout(()=>n.abort(),this.timeout),i=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r),signal:n.signal});if(clearTimeout(o),!i.ok)throw new H(`HTTP ${i.status}: ${i.statusText}`,i.status,await i.text());return await i.json()}catch(n){throw n.name==="AbortError"?new H(`Request timeout after ${this.timeout}ms`,408,""):n instanceof H?n:new H(`Network error: ${n.message}`,0,"")}}symbolToCoin(e){return e.split("-")[0]}parseInterval(e){return {"1m":6e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"4h":144e5,"1d":864e5,"1w":6048e5}[e]}async getSupportedCoins(){let[e]=await this.request("/info",{type:"metaAndAssetCtxs"});return e.universe.map(r=>`${r.name}-USDC`)}async getMarket(e){let r=await this.getMarkets([e]);return r.length>0?r[0]:null}async getMarkets(e){let[r,s]=await this.request("/info",{type:"metaAndAssetCtxs"}),n=r.universe.map((o,i)=>{let a=s[i],l=`${o.name}-USDC`,c=parseFloat(a.midPx||a.markPx||"0"),d=a.prevDayPx?parseFloat(a.prevDayPx):c,f=d>0?(c-d)/d*100:0;return {symbol:l,price:c,change24h:f,volume24h:parseFloat(a.dayNtlVlm||"0"),fundingRate:parseFloat(a.funding||"0"),openInterest:parseFloat(a.openInterest||"0"),markPrice:parseFloat(a.markPx||"0"),indexPrice:parseFloat(a.oraclePx||a.midPx||"0")}});if(e&&e.length>0){let o=new Set(e);return n.filter(i=>o.has(i.symbol))}return n}async getKlines(e,r,s=100){let n=this.symbolToCoin(e),o=this.parseInterval(r),i=Date.now(),a=i-o*s;return (await this.request("/info",{type:"candleSnapshot",req:{coin:n,interval:r,startTime:a,endTime:i}})).map(c=>({symbol:e,open:parseFloat(c.o),high:parseFloat(c.h),low:parseFloat(c.l),close:parseFloat(c.c),volume:parseFloat(c.v),timestamp:c.t,closeTimestamp:c.T}))}async getOrderBook(e,r=10){let s=this.symbolToCoin(e),n=await this.request("/info",{type:"l2Book",coin:s}),[o,i]=n.levels;return {symbol:e,bids:o.slice(0,r).map(a=>({price:parseFloat(a.px),quantity:parseFloat(a.sz),count:a.n})),asks:i.slice(0,r).map(a=>({price:parseFloat(a.px),quantity:parseFloat(a.sz),count:a.n})),timestamp:n.time}}async getRecentTrades(e,r=50){let s=this.symbolToCoin(e);return (await this.request("/info",{type:"recentTrades",coin:s})).slice(0,r).map(o=>({symbol:e,side:o.side==="B"?"buy":"sell",price:parseFloat(o.px),quantity:parseFloat(o.sz),timestamp:o.time,tradeId:o.tid}))}async placeOrder(e){throw new Error("placeOrder() requires wallet private key configuration for EIP-712 signature. Please configure authentication before calling this method. See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint")}async cancelOrder(e){throw new Error("cancelOrder() requires wallet private key configuration for EIP-712 signature. Please configure authentication before calling this method. See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint")}async getPositions(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"clearinghouseState",user:e.userAddress}),s=r.assetPositions.map(o=>{let i=o.position,a=`${i.coin}-USDC`,l=parseFloat(i.szi);if(l===0)return null;let c=parseFloat(i.entryPx),d=parseFloat(i.unrealizedPnl),f=parseFloat(i.positionValue);return {symbol:a,side:l>0?"long":"short",quantity:Math.abs(l),entryPrice:c,markPrice:c,unrealizedPnl:d,unrealizedPnlPercent:parseFloat(i.returnOnEquity)*100,leverage:i.leverage.value,liquidationPrice:i.liquidationPx?parseFloat(i.liquidationPx):void 0,margin:parseFloat(i.marginUsed),notionalValue:Math.abs(f)}}).filter(Boolean),n=e.symbol?s.filter(o=>o.symbol===e.symbol):s;return {positions:n,totalEquity:parseFloat(r.marginSummary.accountValue),availableBalance:parseFloat(r.marginSummary.accountValue)-parseFloat(r.marginSummary.totalMarginUsed),totalUnrealizedPnl:n.reduce((o,i)=>o+i.unrealizedPnl,0),raw:r}}async getOpenOrders(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"openOrders",user:e.userAddress}),s=r.map(o=>{let i=`${o.coin}-USDC`,a=parseFloat(o.origSz),l=parseFloat(o.sz),c=a-l;return {orderId:o.oid.toString(),clientOrderId:o.cloid,symbol:i,side:o.side?"long":"short",orderType:"limit",price:parseFloat(o.limitPx),quantity:a,filledQuantity:c,remainingQuantity:l,status:c>0&&l>0?"partially_filled":"pending",timestamp:o.timestamp,updateTimestamp:o.timestamp}}),n=e.symbol?s.filter(o=>o.symbol===e.symbol):s;return {orders:n,totalCount:n.length,raw:r}}async getTrades(e={}){if(!e.userAddress)throw new Error("Hyperliquid requires userAddress parameter. Example: { userAddress: '0x...' }");let r=await this.request("/info",{type:"userFills",user:e.userAddress}),s=r.map(n=>{let o=`${n.coin}-USDC`,i=n.dir.includes("Long");return {tradeId:n.tid.toString(),orderId:n.oid.toString(),symbol:o,side:i?"long":"short",price:parseFloat(n.px),quantity:parseFloat(n.sz),fee:parseFloat(n.fee||"0"),feeCurrency:n.feeToken||"USDC",isMaker:n.side==="M",timestamp:n.time}});return e.symbol&&(s=s.filter(n=>n.symbol===e.symbol)),e.startTime&&(s=s.filter(n=>n.timestamp>=e.startTime)),e.endTime&&(s=s.filter(n=>n.timestamp<=e.endTime)),e.limit&&(s=s.slice(0,e.limit)),{trades:s,totalCount:s.length,raw:r}}async connectWebSocket(){if(this.wsManager||(this.wsManager=new de(this._wsEndpoint)),this.wsManager.isConnectedNow()){console.log("[WebSocket] Already connected");return}await this.wsManager.connect();}disconnectWebSocket(){this.wsManager&&(this.wsManager.disconnect(),this.wsManager=null);}subscribeMarketData(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");return this.wsManager.subscribe(e,r,s)}subscribeCandles(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");let n=`${e}:${r}`;return this.wsManager.subscribe("candle",n,s)}subscribeUserData(e,r,s){if(!this.wsManager)throw new Error("WebSocket not connected. Call connectWebSocket() first.");let n=e==="fills"?"userFills":"userEvents";return this.wsManager.subscribe(n,r,s)}unsubscribe(e){this.wsManager&&this.wsManager.unsubscribe(e);}},H=class extends Error{constructor(r,s,n){super(r);this.statusCode=s;this.responseBody=n;this.name="HyperliquidApiError";}};var ne=react.createContext({});function rr({client:t,children:e}){return jsxRuntime.jsx(ne.Provider,{value:{client:t},children:e})}function P(){let t=react.useContext(ne);if(!t||!t.client)throw new Error("usePerpetualsClient must be used within a PerpetualsProvider");return t}function lt(){return ["perps","coins"]}async function ct(t){return await t.getSupportedCoins()}function he(t={}){let{client:e}=P();return reactQuery.useQuery({queryKey:lt(),queryFn:async()=>ct(e),staleTime:300*1e3,...t})}function dt(t){return ["perps","market",t.symbol]}async function ut(t,{symbol:e}){return await t.getMarket(e)}function oe(t,e={}){let{client:r}=P();return reactQuery.useQuery({queryKey:dt(t),queryFn:async()=>ut(r,t),staleTime:10*1e3,...e})}function pt(t={}){return ["perps","markets",JSON.stringify((t.symbols??[]).sort())]}async function mt(t,{symbols:e}={}){return await t.getMarkets(e)}function Pe(t={},e={}){let{client:r}=P();return reactQuery.useQuery({queryKey:pt(t),queryFn:async()=>mt(r,t),staleTime:10*1e3,...e})}function ft(t){return ["perps","klines",t.symbol,t.interval,String(t.limit??100)]}async function yt(t,{symbol:e,interval:r,limit:s}){return await t.getKlines(e,r,s)}function cr(t,e={}){let{client:r}=P();return reactQuery.useQuery({queryKey:ft(t),queryFn:async()=>yt(r,t),staleTime:30*1e3,...e})}function gt(t){return ["perps","orderBook",t.symbol,String(t.maxLevel??20)]}async function bt(t,{symbol:e,maxLevel:r}){return await t.getOrderBook(e,r)}function ve(t,e={}){let{client:r}=P();return reactQuery.useQuery({queryKey:gt(t),queryFn:async()=>bt(r,t),staleTime:5*1e3,...e})}function xt(t){return ["perps","recentTrades",t.symbol,String(t.limit??50)]}async function ht(t,{symbol:e,limit:r}){return await t.getRecentTrades(e,r)}function Se(t,e={}){let{client:r}=P();return reactQuery.useQuery({queryKey:xt(t),queryFn:async()=>ht(r,t),staleTime:5*1e3,...e})}function Pt(t){return ["perps","positions",t.userAddress??"",t.symbol??""]}async function vt(t,e){return await t.getPositions(e)}function ke(t,e={}){let{client:r}=P(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:Pt(n),queryFn:async()=>vt(r,n),enabled:s&&!!n.userAddress,staleTime:10*1e3,...e})}function St(t){return ["perps","orders",t.userAddress??"",t.symbol??""]}async function kt(t,e){return await t.getOpenOrders(e)}function Ce(t,e={}){let{client:r}=P(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:St(n),queryFn:async()=>kt(r,n),enabled:s&&!!n.userAddress,staleTime:5*1e3,...e})}function Ct(t){return ["perps","trades",t.userAddress??"",t.symbol??"",String(t.limit??50),String(t.startTime??""),String(t.endTime??"")]}async function Nt(t,e){return await t.getTrades(e)}function Ne(t,e={}){let{client:r}=P(),{enabled:s=true,...n}=t;return reactQuery.useQuery({queryKey:Ct(n),queryFn:async()=>Nt(r,n),enabled:s&&!!n.userAddress,staleTime:30*1e3,...e})}async function wt(t,e){return await t.placeOrder(e)}function ie(t={}){let{client:e}=P();return reactQuery.useMutation({mutationFn:async r=>wt(e,r),...t})}async function Tt(t,e){return await t.cancelOrder(e)}function we(t={}){let{client:e}=P();return reactQuery.useMutation({mutationFn:async r=>Tt(e,r),...t})}function K(t){let{type:e,symbol:r,enabled:s=true}=t,{client:n}=P(),[o,i]=react.useState(null),[a,l]=react.useState(false),[c,d]=react.useState(null),f=react.useCallback(m=>{i(m);},[]);return react.useEffect(()=>{if(!s)return;let m=null,p=true;return (async()=>{try{if(await n.connectWebSocket(),!p)return;l(!0),d(null),m=n.subscribeMarketData(e,r,f);}catch(y){p&&(d(y instanceof Error?y:new Error("Connection failed")),l(false));}})(),()=>{if(p=false,m)try{n.unsubscribe(m);}catch(y){console.error("Failed to unsubscribe:",y);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,f]),{data:o,isConnected:a,error:c}}function vr(t){let{symbol:e,interval:r,enabled:s=true}=t,{client:n}=P(),[o,i]=react.useState(null),[a,l]=react.useState(false),[c,d]=react.useState(null),f=react.useCallback(m=>{i(m);},[]);return react.useEffect(()=>{if(!s)return;let m=null,p=true;return (async()=>{try{if(await n.connectWebSocket(),!p)return;l(!0),d(null),m=n.subscribeCandles(e,r,f);}catch(y){p&&(d(y instanceof Error?y:new Error("Connection failed")),l(false));}})(),()=>{if(p=false,m)try{n.unsubscribe(m);}catch(y){console.error("Failed to unsubscribe:",y);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,f]),{data:o,isConnected:a,error:c}}function ae(t){let{type:e,userAddress:r,enabled:s=true}=t,{client:n}=P(),[o,i]=react.useState(null),[a,l]=react.useState(false),[c,d]=react.useState(null),f=react.useCallback(m=>{i(m);},[]);return react.useEffect(()=>{if(!s||!r)return;let m=null,p=true;return (async()=>{try{if(await n.connectWebSocket(),!p)return;l(!0),d(null),m=n.subscribeUserData(e,r,f);}catch(y){p&&(d(y instanceof Error?y:new Error("Connection failed")),l(false));}})(),()=>{if(p=false,m)try{n.unsubscribe(m);}catch(y){console.error("Failed to unsubscribe:",y);}n.disconnectWebSocket(),l(false),i(null);}},[n,e,r,s,f]),{data:o,isConnected:a,error:c}}function Me(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center px-4 py-3 bg-neutral-900 border-b border-neutral-800",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"Market data not available"})})}function Fe(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-6 px-4 py-3 bg-neutral-900 border-b border-neutral-800",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-28 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]}),jsxRuntime.jsx("div",{className:"h-8 w-px bg-neutral-800"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"})]})]})]})]})}function Re(t){let[e,r]=react.useState(),[s,n]=react.useState(0),{data:o,isPending:i}=oe({symbol:t}),{data:a,isConnected:l}=K({type:"ticker",symbol:t,enabled:!!o});return react.useEffect(()=>{o&&r(o);},[o]),react.useEffect(()=>{if(!a)return;let c=Cr(a,t);c&&r(d=>Nr(d??o??void 0,c,t));},[a,o,t]),react.useEffect(()=>{let c=()=>{let f=Date.now(),m=480*60*1e3,p=f%m,b=m-p;return Math.floor(b/1e3)};n(c());let d=setInterval(()=>{n(c());},1e3);return ()=>clearInterval(d)},[]),{marketData:e,isLoading:i,fundingCountdown:s}}function Cr(t,e){if(Array.isArray(t)){let r=t.find(s=>!s||typeof s!="object"?false:s.symbol===e);return r&&typeof r=="object"?r:null}return t&&typeof t=="object"?t:null}function j(t,e){return typeof t=="number"&&Number.isFinite(t)?t:e}function Nr(t,e,r){return {symbol:e.symbol??t?.symbol??r,price:j(e.price,t?.price??0),change24h:j(e.change24h,t?.change24h??0),volume24h:j(e.volume24h,t?.volume24h??0),fundingRate:j(e.fundingRate,t?.fundingRate??0),openInterest:j(e.openInterest,t?.openInterest??0),markPrice:j(e.markPrice,t?.markPrice??0),indexPrice:typeof e.indexPrice=="number"&&Number.isFinite(e.indexPrice)?e.indexPrice:t?.indexPrice,high24h:typeof e.high24h=="number"&&Number.isFinite(e.high24h)?e.high24h:t?.high24h,low24h:typeof e.low24h=="number"&&Number.isFinite(e.low24h)?e.low24h:t?.low24h}}function wr(t){let e=Math.floor(t/3600),r=Math.floor(t%3600/60),s=t%60;return `${String(e).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function Ft(t,e=2){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e9?`$${(t/1e9).toFixed(e)}B`:t>=1e6?`$${(t/1e6).toFixed(e)}M`:t>=1e3?`$${(t/1e3).toFixed(e)}K`:`$${t.toFixed(e)}`}function It(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e3?t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0}):t>=1?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:4}):t.toFixed(6)}function De({marketData:t,fundingCountdown:e}){let{symbol:r,price:s,change24h:n,indexPrice:o,volume24h:i,openInterest:a,fundingRate:l}=t,c=typeof n=="number"&&Number.isFinite(n)?n:0,d=typeof l=="number"&&Number.isFinite(l)?l:0,f=c>=0,m=c.toFixed(2);return jsxRuntime.jsxs("div",{className:"flex items-center gap-4 px-4",style:{minHeight:64,maxHeight:64},children:[jsxRuntime.jsxs("div",{className:"flex items-baseline gap-2",children:[jsxRuntime.jsx("span",{className:"text-white",style:{fontSize:18,fontWeight:500,lineHeight:"23px"},children:It(s)}),jsxRuntime.jsxs("span",{className:ui.cn(f?"text-green-500":"text-red-500"),style:{fontSize:12},children:[f?"+":"",m,"%"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4",style:{fontSize:13},children:[jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#c8c9d1"},children:"Oracle Price"}),jsxRuntime.jsx("span",{className:"text-white",style:{fontSize:13,fontWeight:400},children:o?It(o):"-"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#c8c9d1"},children:"24h Volume"}),jsxRuntime.jsx("span",{className:"text-white",style:{fontSize:13,fontWeight:400},children:Ft(i)})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#c8c9d1"},children:"Open Interest"}),jsxRuntime.jsx("span",{className:"text-white",style:{fontSize:13,fontWeight:400},children:Ft(a*(t.markPrice||s))})]}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#c8c9d1"},children:"Funding / Countdown"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{className:ui.cn(d>=0?"text-green-500":"text-red-500"),style:{fontSize:13},children:[(d*100).toFixed(5),"%"]}),jsxRuntime.jsx("span",{style:{fontSize:13,color:"#c8c9d1"},children:wr(e)})]})]})]})]})}function Tr({symbol:t}){let{marketData:e,isLoading:r,fundingCountdown:s}=Re(t);return r?jsxRuntime.jsx(Fe,{}):e?jsxRuntime.jsx(De,{marketData:e,fundingCountdown:s}):jsxRuntime.jsx(Me,{})}function ze({onSelectCoin:t}={}){let[e,r]=react.useState(""),[s,n]=react.useState([]),{data:o,isPending:i}=he(),{data:a,isPending:l}=Pe({symbols:o},{enabled:!!o&&o.length>0});react.useEffect(()=>{a&&n(a);},[a]);let c=react.useMemo(()=>{if(!e.trim())return s;let f=e.toLowerCase().trim();return s.filter(m=>m.symbol.toLowerCase().includes(f))},[s,e]);return {coins:s,isLoading:i||l,searchQuery:e,setSearchQuery:r,filteredCoins:c,handleSelectCoin:f=>{t?.(f);}}}function Et(t,e=2){return t>=1e9?`$${(t/1e9).toFixed(e)}B`:t>=1e6?`$${(t/1e6).toFixed(e)}M`:t>=1e3?`$${(t/1e3).toFixed(e)}K`:`$${t.toFixed(e)}`}function zr(t){return t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function Qe({coins:t,searchQuery:e,onSearchChange:r,onSelectCoin:s,isLoading:n}){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950",children:[jsxRuntime.jsx("div",{className:"p-3 border-b border-neutral-800",children:jsxRuntime.jsx(ui.Input,{type:"text",placeholder:"Search coins...",value:e,onChange:o=>r(o.target.value),startContent:jsxRuntime.jsx(ui.SearchIcon,{className:"w-4 h-4 text-neutral-400"}),classNames:{input:"text-sm",inputWrapper:"bg-neutral-900 border-neutral-800"}})}),jsxRuntime.jsx("div",{className:"flex-1 overflow-hidden",children:jsxRuntime.jsxs(ui.StyledTable,{isVirtualized:true,radius:"none",className:"h-full",classNames:{wrapper:"bg-neutral-950",th:"bg-neutral-900 text-neutral-400 text-xs font-medium",td:"text-sm"},maxTableHeight:600,rowHeight:48,"aria-label":"Search Coins",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{width:140,children:"Token"},"token"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"Last Price"},"lastPrice"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"24h Change"},"change24h"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"8h Funding"},"fundingRate"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"24h Volume"},"volume24h"),jsxRuntime.jsx(ui.TableColumn,{width:100,align:"end",children:"Open Interest"},"openInterest")]}),jsxRuntime.jsx(ui.TableBody,{items:t,isLoading:n,emptyContent:jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center py-10",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:e?"No coins found":"No coins available"})}),children:o=>{let i=o.change24h>=0,a=o.change24h.toFixed(2),l=(o.fundingRate*100).toFixed(4),c=o.fundingRate>=0;return jsxRuntime.jsxs(ui.TableRow,{onClick:()=>s(o.symbol),className:"cursor-pointer hover:bg-neutral-900/50 transition-colors",children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 rounded-full bg-gradient-to-br from-blue-500 to-purple-600 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold text-white",children:o.symbol.charAt(0)})}),jsxRuntime.jsx("span",{className:"font-medium text-white",children:o.symbol})]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-white font-medium",children:zr(o.price)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:ui.cn("font-medium",i?"text-green-500":"text-red-500"),children:[i?"+":"",a,"%"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:ui.cn("font-medium",c?"text-green-500":"text-red-500"),children:[l,"%"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-neutral-300",children:Et(o.volume24h)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-neutral-300",children:Et(o.openInterest*o.price)})})]},o.symbol)}})]})})]})}function Qr({onSelectCoin:t,className:e}){let{filteredCoins:r,isLoading:s,searchQuery:n,setSearchQuery:o,handleSelectCoin:i}=ze({onSelectCoin:t});return jsxRuntime.jsx("div",{className:e,children:jsxRuntime.jsx(Qe,{coins:r,searchQuery:n,onSearchChange:o,onSelectCoin:i,isLoading:s})})}function qt(t,e){if(e<=0)return t;let r=new Map;return t.forEach(s=>{let n=Math.floor(s.price/e)*e,o=r.get(n);o?(o.quantity+=s.quantity,s.count&&(o.count=(o.count||0)+s.count)):r.set(n,{price:n,quantity:s.quantity,count:s.count});}),Array.from(r.values())}function Bt(t){let e=0,r=t.map(n=>{let o=n.quantity*n.price;return e+=o,{...n,quantity:o,total:e,percentage:0}}),s=e;return r.map(n=>({...n,percentage:s>0?n.total/s*100:0}))}function qe({symbol:t,maxLevel:e=20,precision:r=.01}){let[s,n]=react.useState(null),[o,i]=react.useState(r),{data:a,isPending:l}=ve({symbol:t,maxLevel:e}),{data:c}=K({type:"orderBook",symbol:t,enabled:!!a});return react.useEffect(()=>{c?n(c):a&&n(a);},[c,a]),{...react.useMemo(()=>{if(!s)return {bids:[],asks:[],spread:0,spreadPercentage:0};let f=qt(s.bids,o),m=qt(s.asks,o),p=f.sort((W,D)=>D.price-W.price).slice(0,e),b=m.sort((W,D)=>W.price-D.price).slice(0,e),y=Bt(p),N=Bt(b),h=y[0]?.price||0,I=(N[0]?.price||0)-h,A=h>0?I/h*100:0;return {bids:y,asks:N,spread:I,spreadPercentage:A}},[s,o,e]),isLoading:l,precision:o,setPrecision:i}}function Lr(t){return t>=1e3?t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0}):t>=1?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:4}):t.toFixed(6)}function Lt(t){return Math.round(t).toLocaleString("en-US")}function At({price:t,quantity:e,total:r,percentage:s,side:n,onClick:o}){let i=n==="ask";return jsxRuntime.jsxs("div",{className:"relative flex items-center cursor-pointer hover:bg-white/5 transition-colors",style:{height:22,minHeight:22,maxHeight:22,padding:"0 16px",gap:16,fontSize:11},onClick:o,children:[jsxRuntime.jsx("div",{className:"absolute left-0 top-0",style:{height:20,width:`${s}%`,background:i?"linear-gradient(to right, rgba(209,57,236,0), rgb(236,57,122))":"linear-gradient(to right, rgba(47,194,227,0), rgb(47,227,172))",opacity:.15}}),jsxRuntime.jsx("div",{className:"relative z-10 flex items-center",style:{flex:"1 1 0%"},children:jsxRuntime.jsx("span",{style:{color:i?"#ec397a":"#2fe3ac",fontWeight:400},children:Lr(t)})}),jsxRuntime.jsx("div",{className:"relative z-10 flex items-center justify-end",style:{flex:"1 1 0%",color:"#fcfcfc"},children:Lt(e)}),jsxRuntime.jsx("div",{className:"relative z-10 flex items-center justify-end",style:{flex:"1 1 0%",color:"#fcfcfc"},children:Lt(r)})]})}function Be({bids:t,asks:e,spread:r,spreadPercentage:s,onPriceClick:n}){let o=[...e].reverse();return jsxRuntime.jsxs("div",{className:"flex flex-col h-full",style:{backgroundColor:"#06070b",fontSize:11},children:[jsxRuntime.jsxs("div",{className:"flex items-center",style:{height:28,minHeight:28,padding:"0 16px",gap:16,color:"#777a8c",fontSize:11},children:[jsxRuntime.jsx("div",{className:"flex items-center",style:{flex:"1 1 0%"},children:"Price"}),jsxRuntime.jsx("div",{className:"flex items-center justify-end",style:{flex:"1 1 0%"},children:"Amount (USD)"}),jsxRuntime.jsx("div",{className:"flex items-center justify-end",style:{flex:"1 1 0%"},children:"Total (USD)"})]}),jsxRuntime.jsx("div",{className:"flex-1 flex flex-col-reverse overflow-hidden",children:o.map((i,a)=>jsxRuntime.jsx(At,{price:i.price,quantity:i.quantity,total:i.total,percentage:i.percentage,side:"ask",onClick:()=>n?.(i.price)},`ask-${i.price}-${a}`))}),jsxRuntime.jsx("div",{className:"flex items-center justify-center",style:{height:24,minHeight:24,padding:"0 16px",backgroundColor:"rgba(34,36,45,0.5)"},children:jsxRuntime.jsxs("div",{className:"flex items-center",style:{gap:12,fontSize:12,color:"#fcfcfc"},children:[jsxRuntime.jsx("span",{style:{color:"#fcfcfc"},children:"Spread:"}),jsxRuntime.jsx("button",{type:"button",className:"hover:text-white transition-colors cursor-pointer",style:{color:"#fcfcfc",fontWeight:400,background:"none",border:"none",padding:0},onClick:()=>n?.(r),children:r>=1?Math.round(r).toLocaleString("en-US"):r.toFixed(4)}),jsxRuntime.jsxs("span",{style:{color:"#fcfcfc"},children:[s.toFixed(3),"%"]})]})}),jsxRuntime.jsx("div",{className:"flex-1 overflow-hidden",children:t.map((i,a)=>jsxRuntime.jsx(At,{price:i.price,quantity:i.quantity,total:i.total,percentage:i.percentage,side:"bid",onClick:()=>n?.(i.price)},`bid-${i.price}-${a}`))})]})}function Ar(){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 p-2 gap-1",children:[Array.from({length:15}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]},`ask-skeleton-${e}`)),jsxRuntime.jsx("div",{className:"py-2",children:jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-40 mx-auto rounded"})}),Array.from({length:15}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]})]},`bid-skeleton-${e}`))]})}function Wr(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full bg-neutral-950",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"No order book data available"})})}function $r({symbol:t,maxLevel:e=20,onPriceClick:r,className:s}){let{bids:n,asks:o,spread:i,spreadPercentage:a,isLoading:l}=qe({symbol:t,maxLevel:e});return l?jsxRuntime.jsx(Ar,{}):n.length===0&&o.length===0?jsxRuntime.jsx(Wr,{}):jsxRuntime.jsx("div",{className:s,children:jsxRuntime.jsx(Be,{bids:n,asks:o,spread:i,spreadPercentage:a,onPriceClick:r})})}function Le({symbol:t,limit:e=50}){let[r,s]=react.useState([]),{data:n,isPending:o}=Se({symbol:t,limit:e}),{data:i}=K({type:"trades",symbol:t,enabled:!!n});return react.useEffect(()=>{n&&s(n.filter($t));},[n]),react.useEffect(()=>{i&&s(a=>{let l=Kr(i);if(l.length===0)return a;let c=l.filter(f=>!a.some(m=>m.timestamp===f.timestamp&&m.price===f.price&&m.quantity===f.quantity));return c.length===0?a:[...c,...a].slice(0,e)});},[i,e]),{trades:r,isLoading:o}}function Kr(t){return (Array.isArray(t)?t:[t]).filter($t)}function $t(t){return t?typeof t.symbol=="string"&&(t.side==="buy"||t.side==="sell")&&typeof t.price=="number"&&Number.isFinite(t.price)&&typeof t.quantity=="number"&&Number.isFinite(t.quantity)&&typeof t.timestamp=="number"&&Number.isFinite(t.timestamp):false}function Vr(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t.toFixed(6)}function Ht(t){return typeof t!="number"||!Number.isFinite(t)?"-":t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":t.toFixed(2)}function _r(t){if(typeof t!="number"||!Number.isFinite(t))return "-";let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),n=String(e.getSeconds()).padStart(2,"0");return `${r}:${s}:${n}`}function We({trades:t,onTradeClick:e}){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full overflow-auto",style:{backgroundColor:"#06070b",fontSize:11},children:[jsxRuntime.jsxs("div",{className:"sticky top-0 z-10 flex items-center",style:{height:28,minHeight:28,padding:"0 16px",gap:16,color:"#c8c9d1",fontSize:11},children:[jsxRuntime.jsx("div",{className:"flex-1",style:{maxWidth:100},children:"Price"}),jsxRuntime.jsx("div",{className:"flex-1 text-right",children:"Amount"}),jsxRuntime.jsx("div",{className:"flex-1 text-right",style:{maxWidth:100},children:"Total"}),jsxRuntime.jsx("div",{className:"flex-1 text-right",style:{maxWidth:70},children:"Time"})]}),jsxRuntime.jsx("div",{className:"flex-1",children:t.map((r,s)=>{let n=r.side==="buy",o=typeof r.price=="number"&&Number.isFinite(r.price)&&typeof r.quantity=="number"&&Number.isFinite(r.quantity)?r.price*r.quantity:void 0;return jsxRuntime.jsxs("div",{className:"flex items-center cursor-pointer hover:bg-white/5 transition-colors",style:{height:22,minHeight:22,maxHeight:22,padding:"0 16px",gap:16,fontSize:11},onClick:()=>e?.(r),children:[jsxRuntime.jsx("div",{className:"flex-1",style:{maxWidth:100},children:jsxRuntime.jsx("span",{style:{color:n?"#2fe3ac":"#ec397a",fontWeight:400},children:Vr(r.price)})}),jsxRuntime.jsx("div",{className:"flex-1 text-right",style:{color:"#fcfcfc"},children:Ht(r.quantity)}),jsxRuntime.jsx("div",{className:"flex-1 text-right",style:{maxWidth:100,color:"#fcfcfc"},children:Ht(o)}),jsxRuntime.jsx("div",{className:"flex-1 text-right",style:{maxWidth:70,color:"#c8c9d1"},children:_r(r.timestamp)})]},`${r.timestamp}-${r.price}-${s}`)})})]})}function Gr(){return jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-neutral-950 p-2 gap-1",children:[jsxRuntime.jsxs("div",{className:"flex justify-between mb-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-16 rounded"})]}),Array.from({length:20}).map((t,e)=>jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-20 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-16 rounded"})]},`trade-skeleton-${e}`))]})}function jr(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full bg-neutral-950",children:jsxRuntime.jsx("span",{className:"text-neutral-400 text-sm",children:"No recent trades"})})}function Jr({symbol:t,limit:e=50,onTradeClick:r,className:s}){let{trades:n,isLoading:o}=Le({symbol:t,limit:e});return o?jsxRuntime.jsx(Gr,{}):n.length===0?jsxRuntime.jsx(jr,{}):jsxRuntime.jsx("div",{className:s,children:jsxRuntime.jsx(We,{trades:n,onTradeClick:r})})}function He({symbol:t,userAddress:e,maxLeverage:r=150,onSuccess:s,onError:n}){let[o,i]=react.useState("long"),[a,l]=react.useState("market"),c=reactHookForm.useForm({defaultValues:{amount:0,leverage:20,takeProfitPrice:void 0,takeProfitPercent:void 0,stopLossPrice:void 0,stopLossPercent:void 0}}),{data:d}=oe({symbol:t}),{mutateAsync:f,isPending:m}=ie({onSuccess:()=>{c.reset(),s?.();},onError:C=>{n?.(C);}}),p=c.watch(),{amount:b,leverage:y,price:N}=p,h=react.useMemo(()=>a==="limit"&&N?N:d?.price||0,[a,N,d?.price]),q=react.useMemo(()=>!b||!h?0:b*h*5e-4,[b,h]),I=react.useMemo(()=>!b||!h?0:b*h+q,[b,h,q]),A=react.useMemo(()=>{if(!b||!h||!y||y===1)return;let C=.005,G=h;return o==="long"?G*(1-(1/y-C)):G*(1+(1/y-C))},[b,h,y,o]),W=1e4,D=1e4,ye=0,U=react.useCallback(async C=>{if(!e)throw new Error("User address is required");let G=a==="limit"?C.price:void 0,ge=C.takeProfitPrice,be=C.stopLossPrice;if(!ge&&C.takeProfitPercent&&C.takeProfitPercent>0&&h){let se=C.takeProfitPercent/100;ge=o==="long"?h*(1+se):h*(1-se);}if(!be&&C.stopLossPercent&&C.stopLossPercent>0&&h){let se=C.stopLossPercent/100;be=o==="long"?h*(1-se):h*(1+se);}await f({symbol:t,side:o,orderType:a,amount:C.amount,price:G,leverage:C.leverage,takeProfitPrice:ge,stopLossPrice:be,userAddress:e});},[t,o,a,h,e,f]);return {form:c,side:o,orderType:a,setSide:i,setOrderType:l,handleSubmit:U,isSubmitting:m,currentPrice:h,estimatedFee:q,estimatedTotal:I,liquidationPrice:A,availableMargin:W,accountValue:D,currentPosition:ye,maxLeverage:r}}function pe(t,e=2){return t.toFixed(e)}function rs({leverage:t,maxLeverage:e,onLeverageChange:r,onClose:s}){let n=[1,2,3,5,10,20,25,50,100].filter(o=>o<=e);return jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:s,onKeyDown:o=>o.key==="Escape"&&s(),role:"button",tabIndex:-1,"aria-label":"Close"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-72 bg-neutral-900 border border-neutral-700 rounded-lg p-4 shadow-2xl",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("h3",{className:"text-sm font-medium text-white",children:"Adjust Leverage"}),jsxRuntime.jsx("button",{type:"button",onClick:s,className:"text-neutral-400 hover:text-white",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),jsxRuntime.jsxs("div",{className:"text-center text-2xl font-bold text-white mb-4",children:[t,"x"]}),jsxRuntime.jsx(ui.Slider,{value:[t],onChange:o=>r(Array.isArray(o)?o[0]:o),minValue:1,maxValue:e,step:1,className:"w-full mb-3"}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(o=>jsxRuntime.jsxs("button",{type:"button",className:ui.cn("px-2.5 py-1 text-xs rounded transition-colors",t===o?"bg-green-600 text-white":"bg-neutral-800 text-neutral-400 hover:bg-neutral-700"),onClick:()=>r(o),children:[o,"x"]},o))}),jsxRuntime.jsx("button",{type:"button",className:"w-full mt-4 text-white h-9 rounded cursor-pointer transition-colors",style:{backgroundColor:"#16a34a"},onClick:s,children:"Confirm"})]})]})}function Ke({methods:t,side:e,orderType:r,onSideChange:s,onOrderTypeChange:n,onSubmit:o,isSubmitting:i,symbol:a,currentPrice:l,estimatedFee:c,liquidationPrice:d,availableMargin:f,accountValue:m,currentPosition:p,maxLeverage:b}){let[y,N]=react.useState(false),[h,q]=react.useState(false),I=t.watch("leverage")||20,A=t.watch("amount")||0,W=a.split("-")[0],D=f>0&&l?Math.min(A*l/(f*I)*100,100):0,ye=U=>{let C=(Array.isArray(U)?U[0]:U)/100;if(l&&l>0){let G=f*I*C/l;t.setValue("amount",Number(G.toFixed(6)));}};return jsxRuntime.jsxs("div",{className:"flex flex-col h-full",style:{backgroundColor:"#06070b"},children:[jsxRuntime.jsxs("div",{className:"flex-1 overflow-y-auto",style:{padding:"16px 16px",display:"flex",flexDirection:"column",gap:16},children:[jsxRuntime.jsxs("div",{className:"flex",style:{gap:4},children:[jsxRuntime.jsx("button",{type:"button",className:"flex-1 cursor-pointer transition-colors",style:{height:32,fontSize:12,borderRadius:4,backgroundColor:e==="long"?"#2fe3ac":"transparent",color:e==="long"?"#090909":"#c8c9d1",fontWeight:e==="long"?700:500},onClick:()=>s("long"),children:"Long"}),jsxRuntime.jsx("button",{type:"button",className:"flex-1 cursor-pointer transition-colors",style:{height:32,fontSize:12,borderRadius:4,backgroundColor:e==="short"?"#ec397a":"transparent",color:e==="short"?"#090909":"#c8c9d1",fontWeight:e==="short"?700:500},onClick:()=>s("short"),children:"Short"})]}),jsxRuntime.jsxs("div",{className:"flex items-center",style:{gap:8},children:[jsxRuntime.jsxs("div",{className:"flex",style:{gap:4},children:[jsxRuntime.jsx("button",{type:"button",className:"cursor-pointer transition-colors",style:{height:24,padding:"0 8px",fontSize:12,borderRadius:4,backgroundColor:"transparent",color:r==="market"?"#fcfcfc":"#c8c9d1",fontWeight:500,border:"none",borderBottom:r==="market"?"2px solid #fcfcfc":"none"},onClick:()=>n("market"),children:"Market"}),jsxRuntime.jsx("button",{type:"button",className:"cursor-pointer transition-colors",style:{height:24,padding:"0 8px",fontSize:12,borderRadius:4,backgroundColor:"transparent",color:r==="limit"?"#fcfcfc":"#c8c9d1",fontWeight:500,border:"none",borderBottom:r==="limit"?"2px solid #fcfcfc":"none"},onClick:()=>n("limit"),children:"Limit"})]}),jsxRuntime.jsx("div",{className:"flex-1"}),jsxRuntime.jsxs("button",{type:"button",className:"cursor-pointer transition-colors",style:{height:24,padding:"0 5px",fontSize:12,borderRadius:4,backgroundColor:"rgba(34,36,45,0.5)",color:"#c8c9d1",fontWeight:500,border:"1px solid rgba(34,36,45,0.5)"},onClick:()=>N(true),children:["Leverage: ",I,"x"]})]}),jsxRuntime.jsx(ui.RHForm,{methods:t,onSubmit:o,children:jsxRuntime.jsxs("div",{className:"space-y-3 w-full",children:[r==="limit"&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs text-neutral-400",children:"Price"}),jsxRuntime.jsx("span",{className:"text-xs text-neutral-500",children:"USDC"})]}),jsxRuntime.jsx(ui.RHNumberInput,{name:"price",placeholder:"0.0",className:"w-full",endContent:jsxRuntime.jsx("span",{className:"text-neutral-500 text-xs",children:"USDC"})})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center mb-1",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c"},children:"Buy Amount"}),jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c"},children:W})]}),jsxRuntime.jsx("div",{className:"perp-buy-amt",style:{borderRadius:4,padding:8,backgroundColor:"rgba(34,36,45,0.5)",border:"1px solid rgb(34,36,45)",height:64},children:jsxRuntime.jsx(ui.RHNumberInput,{name:"amount",placeholder:"0.0 USDC",className:"w-full"})})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("style",{children:`
2
+ .perp-buy-amt input { font-size: 18px !important; }
3
+ .perp-slider { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; width: 100%; height: 16px; }
4
+ .perp-slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #22242d; }
5
+ .perp-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #2fe3ac; margin-top: -4px; border: none; }
6
+ .perp-slider::-moz-range-track { height: 4px; border-radius: 2px; background: #22242d; border: none; }
7
+ .perp-slider::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #2fe3ac; border: none; }
8
+ `}),jsxRuntime.jsx("input",{type:"range",value:Math.round(D),onChange:U=>ye(Number(U.target.value)),min:0,max:100,step:1,className:"perp-slider"}),jsxRuntime.jsxs("div",{className:"flex justify-between",style:{fontSize:10,color:"#c8c9d1",marginTop:4},children:[jsxRuntime.jsx("span",{children:"0%"}),jsxRuntime.jsx("span",{children:"25%"}),jsxRuntime.jsx("span",{children:"50%"}),jsxRuntime.jsx("span",{children:"75%"}),jsxRuntime.jsx("span",{children:"100%"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center",style:{gap:6},children:[jsxRuntime.jsx("div",{onClick:()=>q(U=>!U),style:{width:16,height:16,borderRadius:4,border:"1px solid #323542",backgroundColor:h?"#2fe3ac":"transparent",flexShrink:0,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:h&&jsxRuntime.jsx("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:jsxRuntime.jsx("path",{d:"M1 4L3.5 6.5L9 1",stroke:"#090909",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("span",{style:{fontSize:12,fontWeight:400,color:"#c8c9d1"},children:"TP/SL"})]}),jsxRuntime.jsxs("div",{style:{fontSize:12,color:"#777a8c"},children:[jsxRuntime.jsx("span",{children:"Est. Liq. Price: "}),jsxRuntime.jsx("span",{style:{color:"#fcfcfc"},children:d?pe(d,2):"--"})]})]}),h&&jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[jsxRuntime.jsxs("div",{className:"flex",style:{gap:8},children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c",marginBottom:2,display:"block"},children:"TP Price"}),jsxRuntime.jsx(ui.RHNumberInput,{name:"takeProfitPrice",placeholder:"Enter TP price",className:"w-full",style:{fontSize:12,height:32,padding:"0 8px",border:"1px solid #22242d",borderRadius:4}})]}),jsxRuntime.jsxs("div",{style:{width:70},children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c",marginBottom:2,display:"block"},children:"TP %"}),jsxRuntime.jsx(ui.RHNumberInput,{name:"takeProfitPercent",placeholder:"0.0",className:"w-full",style:{fontSize:12,height:32,padding:"0 8px",border:"1px solid #22242d",borderRadius:4}})]})]}),jsxRuntime.jsxs("div",{className:"flex",style:{gap:8},children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c",marginBottom:2,display:"block"},children:"SL Price"}),jsxRuntime.jsx(ui.RHNumberInput,{name:"stopLossPrice",placeholder:"Enter SL price",className:"w-full",style:{fontSize:12,height:32,padding:"0 8px",border:"1px solid #22242d",borderRadius:4}})]}),jsxRuntime.jsxs("div",{style:{width:70},children:[jsxRuntime.jsx("span",{style:{fontSize:12,color:"#777a8c",marginBottom:2,display:"block"},children:"SL %"}),jsxRuntime.jsx(ui.RHNumberInput,{name:"stopLossPercent",placeholder:"0.0",className:"w-full",style:{fontSize:12,height:32,padding:"0 8px",border:"1px solid #22242d",borderRadius:4}})]})]})]}),jsxRuntime.jsx("button",{type:"button",className:"w-full cursor-pointer transition-colors",style:{height:36,fontSize:14,fontWeight:700,color:"#06070b",backgroundColor:"#2fe3ac",borderRadius:9999,border:"none"},children:"Add More Funds"})]})})]}),jsxRuntime.jsxs("div",{style:{padding:"10px 16px",fontSize:12,display:"flex",flexDirection:"column",gap:6},children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center",children:[jsxRuntime.jsx("span",{style:{color:"#777a8c"},children:"Available Margin"}),jsxRuntime.jsxs("span",{style:{color:"#6683ff",fontSize:12},children:[pe(f)," USDC"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{style:{color:"#777a8c"},children:"Perps Account Value"}),jsxRuntime.jsxs("span",{style:{color:"#c8c9d1",fontSize:12},children:[pe(m)," USDC"]})]}),jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{style:{color:"#777a8c"},children:"Current Position"}),jsxRuntime.jsx("span",{style:{color:"#c8c9d1",fontSize:12},children:p?pe(p):"--"})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-end",style:{gap:6,paddingTop:8},children:[jsxRuntime.jsx("span",{style:{fontSize:11,color:"#777a8c"},children:"powered by"}),jsxRuntime.jsx("img",{src:"https://axiom-assets.sfo3.cdn.digitaloceanspaces.com/images/hyperliquid-logo.svg",alt:"Hyperliquid",className:"h-3 opacity-60",onError:U=>{let C=U.target;C.style.display="none";}})]})]}),y&&jsxRuntime.jsx(rs,{leverage:I,maxLeverage:b,onLeverageChange:U=>t.setValue("leverage",U),onClose:()=>N(false)})]})}function ss({symbol:t,userAddress:e,maxLeverage:r,onSuccess:s,onError:n,className:o}){let{form:i,side:a,orderType:l,setSide:c,setOrderType:d,handleSubmit:f,isSubmitting:m,currentPrice:p,estimatedFee:b,estimatedTotal:y,liquidationPrice:N,availableMargin:h,accountValue:q,currentPosition:I,maxLeverage:A}=He({symbol:t,userAddress:e,maxLeverage:r,onSuccess:s,onError:n});return jsxRuntime.jsx("div",{className:o,children:jsxRuntime.jsx(Ke,{methods:i,side:a,orderType:l,onSideChange:c,onOrderTypeChange:d,onSubmit:f,isSubmitting:m,symbol:t,currentPrice:p,estimatedFee:b,estimatedTotal:y,liquidationPrice:N,availableMargin:h,accountValue:q,currentPosition:I,maxLeverage:A})})}function Ve({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s}){let[n,o]=react.useState([]),{data:i,isLoading:a,error:l}=ke({userAddress:t,symbol:e},{enabled:!!t}),{data:c}=ae({type:"positions",userAddress:t||"",enabled:!!t}),{mutateAsync:d,isPending:f}=ie({onSuccess:()=>{r?.();},onError:p=>{s?.(p);}});react.useEffect(()=>{i?.positions&&o(i.positions);},[i]),react.useEffect(()=>{c&&o(p=>{let b=p.findIndex(y=>y.symbol===c.symbol);if(c.quantity===0)return b!==-1?p.filter((y,N)=>N!==b):p;if(b!==-1){let y=[...p];return y[b]=c,y}return [...p,c]});},[c]);let m=react.useCallback(async p=>{if(!t)throw new Error("User address is required");let b=p.side==="long"?"short":"long";await d({symbol:p.symbol,side:b,orderType:"market",amount:Math.abs(p.quantity),leverage:p.leverage,userAddress:t});},[t,d]);return {positions:n,isLoading:a,error:l,handleClosePosition:m,isClosing:f}}function Z(t,e=2){return t.toFixed(e)}function _e(t){return Z(t,4)}function ls(t){return Z(Math.abs(t),4)}function cs(t){return `${t>=0?"+":""}${Z(t,2)}`}function ds(t){return `${t>=0?"+":""}${Z(t,2)}%`}function Ge({positions:t,onClosePosition:e,isClosing:r}){let s=jsxRuntime.jsxs("tr",{style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("th",{className:"text-left py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Asset"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Position"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Position Value"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Entry Price"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Mark Price"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Liquidation"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Margin Used (PNL) \u2193"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"TP"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"SL"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:12,color:"#777a8c"},children:"Close"})]});return t.length===0?jsxRuntime.jsxs("div",{className:"w-full overflow-x-auto bg-transparent",children:[jsxRuntime.jsx("table",{className:"w-full",style:{fontSize:12},children:jsxRuntime.jsx("thead",{children:s})}),jsxRuntime.jsx("div",{className:"flex items-center justify-center",style:{fontSize:14,color:"#c8c9d1",padding:"24px 0"},children:"No open positions"})]}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto bg-transparent",children:jsxRuntime.jsxs("table",{className:"w-full",style:{fontSize:12},children:[jsxRuntime.jsx("thead",{children:s}),jsxRuntime.jsx("tbody",{children:t.map(n=>{let i=n.unrealizedPnl>=0?"text-green-500":"text-red-500";return jsxRuntime.jsxs("tr",{className:"hover:bg-neutral-900/50",style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("td",{className:"py-1.5 px-3",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium",style:{color:"#fcfcfc"},children:n.symbol.split("-")[0]}),jsxRuntime.jsxs("span",{className:ui.cn(n.side==="long"?"text-green-500":"text-red-500"),children:[n.leverage,"x ",n.side.toUpperCase()]})]})}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:ls(n.quantity)}),jsxRuntime.jsxs("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:["$",Z(n.notionalValue)]}),jsxRuntime.jsxs("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:["$",_e(n.entryPrice)]}),jsxRuntime.jsxs("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:["$",_e(n.markPrice)]}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:n.liquidationPrice?`$${_e(n.liquidationPrice)}`:"-"}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-end",children:[jsxRuntime.jsxs("span",{style:{color:"#fcfcfc"},children:["$",Z(n.margin)]}),jsxRuntime.jsxs("span",{className:i,children:[cs(n.unrealizedPnl)," (",ds(n.unrealizedPnlPercent),")"]})]})}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#c8c9d1"},children:"-"}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#c8c9d1"},children:"-"}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",onClick:()=>e(n),isLoading:r,className:"bg-red-600 hover:bg-red-700 text-white text-xs px-3 py-1",children:"Close"})})]},n.symbol)})})]})})}function je(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function us(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-24",style:{fontSize:14,color:"#c8c9d1"},children:"No open positions"})}function ps({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s,className:n}){let{positions:o,isLoading:i,handleClosePosition:a,isClosing:l}=Ve({userAddress:t,symbol:e,onCloseSuccess:r,onCloseError:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(je,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Ge,{positions:o,onClosePosition:a,isClosing:l})})}function Je({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s}){let[n,o]=react.useState([]),{data:i,isLoading:a,error:l}=Ce({userAddress:t,symbol:e},{enabled:!!t}),{data:c}=ae({type:"orders",userAddress:t||"",enabled:!!t}),{mutateAsync:d,isPending:f}=we({onSuccess:()=>{r?.();},onError:p=>{s?.(p);}});react.useEffect(()=>{i?.orders&&o(i.orders);},[i]),react.useEffect(()=>{c&&o(p=>{let b=p.findIndex(y=>y.orderId===c.orderId);if(c.status==="cancelled"||c.status==="filled"||c.status==="rejected")return b!==-1?p.filter((y,N)=>N!==b):p;if(b!==-1){let y=[...p];return y[b]=c,y}return [c,...p]});},[c]);let m=react.useCallback(async p=>{if(!t)throw new Error("User address is required");await d({orderId:p.orderId,symbol:p.symbol,userAddress:t});},[t,d]);return {orders:n,isLoading:a,error:l,handleCancelOrder:m,isCanceling:f}}function Yt(t,e=2){return t.toFixed(e)}function gs(t){return Yt(t,4)}function Ye(t){return Yt(t,4)}function bs(t){let e=new Date(t),r=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),n=String(e.getSeconds()).padStart(2,"0");return `${r}:${s}:${n}`}function Xe({orders:t,onCancelOrder:e,isCanceling:r}){return t.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-24",style:{fontSize:11,color:"#c8c9d1"},children:"No open orders"}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto bg-transparent",children:jsxRuntime.jsxs("table",{className:"w-full",style:{fontSize:11},children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("th",{className:"text-left py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Asset"}),jsxRuntime.jsx("th",{className:"text-left py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Type"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Price"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Amount"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Filled"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Remaining"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Status"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Time"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Action"})]})}),jsxRuntime.jsx("tbody",{children:t.map(s=>jsxRuntime.jsxs("tr",{className:"hover:bg-neutral-900/50",style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("td",{className:"py-1.5 px-3",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-medium",style:{color:"#fcfcfc"},children:s.symbol.split("-")[0]}),jsxRuntime.jsxs("span",{className:ui.cn(s.side==="long"?"text-green-500":"text-red-500"),children:[s.side.toUpperCase(),s.leverage?` ${s.leverage}x`:""]})]})}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 capitalize",style:{color:"#fcfcfc"},children:s.orderType}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:s.orderType==="market"?jsxRuntime.jsx("span",{style:{color:"#c8c9d1"},children:"Market"}):`$${gs(s.price)}`}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:Ye(s.quantity)}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:Ye(s.filledQuantity)}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:Ye(s.remainingQuantity)}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",children:jsxRuntime.jsx("span",{className:ui.cn("px-2 py-0.5 rounded","text-[11px]",s.status==="pending"&&"bg-yellow-600/20 text-yellow-500",s.status==="partially_filled"&&"bg-blue-600/20 text-blue-500",s.status==="filled"&&"bg-green-600/20 text-green-500",s.status==="cancelled"&&"bg-neutral-600/20 text-neutral-400",s.status==="rejected"&&"bg-red-600/20 text-red-500"),children:s.status.replace("_"," ")})}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#c8c9d1"},children:bs(s.timestamp)}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",children:s.status==="pending"||s.status==="partially_filled"?jsxRuntime.jsx(ui.Button,{size:"sm",onClick:()=>e(s),isLoading:r,className:"bg-red-600 hover:bg-red-700 text-white text-xs px-3 py-1",children:"Cancel"}):jsxRuntime.jsx("span",{className:"text-[11px]",style:{color:"#6b6d7a"},children:"-"})})]},s.orderId))})]})})}function Ze(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function et(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-24",style:{fontSize:11,color:"#c8c9d1"},children:"No open orders"})}function xs({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s,className:n}){let{orders:o,isLoading:i,handleCancelOrder:a,isCanceling:l}=Je({userAddress:t,symbol:e,onCancelSuccess:r,onCancelError:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Ze,{})}):o.length===0?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(et,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(Xe,{orders:o,onCancelOrder:a,isCanceling:l})})}function hs(t){let e=Date.now(),r=e;switch(t){case "today":let s=new Date;return s.setHours(0,0,0,0),{startTime:s.getTime(),endTime:r};case "7d":return {startTime:e-10080*60*1e3,endTime:r};case "30d":return {startTime:e-720*60*60*1e3,endTime:r};default:return {}}}function rt({userAddress:t,symbol:e,initialTimeRange:r="7d",pageSize:s=50}){let[n,o]=react.useState(r),[i,a]=react.useState(1),[l,c]=react.useState([]),{startTime:d,endTime:f}=hs(n),{data:m,isLoading:p,error:b}=Ne({userAddress:t,symbol:e,startTime:d,endTime:f,limit:1e3},{enabled:!!t});react.useEffect(()=>{m?.trades&&(c(m.trades),a(1));},[m]),react.useEffect(()=>{a(1);},[n]);let y=Math.ceil(l.length/s),N=(i-1)*s,h=N+s;return {trades:l.slice(N,h),isLoading:p,error:b,timeRange:n,setTimeRange:o,currentPage:i,totalPages:y,goToNextPage:()=>{i<y&&a(i+1);},goToPreviousPage:()=>{i>1&&a(i-1);},goToPage:D=>{D>=1&&D<=y&&a(D);}}}function st(t,e=2){return t.toFixed(e)}function Ps(t){return st(t,4)}function vs(t){return st(t,4)}function Ss(t){let e=new Date(t),r=String(e.getMonth()+1).padStart(2,"0"),s=String(e.getDate()).padStart(2,"0"),n=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return `${r}/${s} ${n}:${o}:${i}`}var ks=[{label:"Today",value:"today"},{label:"7 Days",value:"7d"},{label:"30 Days",value:"30d"},{label:"All",value:"all"}];function nt({trades:t,timeRange:e,onTimeRangeChange:r,currentPage:s,totalPages:n,onNextPage:o,onPreviousPage:i,onGoToPage:a}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4",children:[jsxRuntime.jsx("div",{className:"flex gap-2",children:ks.map(l=>{let c=e===l.value;return jsxRuntime.jsx("button",{type:"button",className:ui.cn("rounded px-3 transition-colors",!c&&"hover:bg-[#1a1c24]"),style:{height:24,fontSize:11,border:"1px solid #22242d",backgroundColor:c?"#22242d":"transparent",color:c?"#fcfcfc":"#c8c9d1"},onClick:()=>r(l.value),children:l.label},l.value)})}),t.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-24",style:{fontSize:11,color:"#c8c9d1"},children:"No trade history"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto bg-transparent",children:jsxRuntime.jsxs("table",{className:"w-full",style:{fontSize:11},children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("th",{className:"text-left py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Asset"}),jsxRuntime.jsx("th",{className:"text-left py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Side"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Price"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Quantity"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Fee"}),jsxRuntime.jsx("th",{className:"text-center py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Maker/Taker"}),jsxRuntime.jsx("th",{className:"text-right py-1.5 px-3 font-normal",style:{fontSize:11,color:"#c8c9d1"},children:"Time"})]})}),jsxRuntime.jsx("tbody",{children:t.map(l=>jsxRuntime.jsxs("tr",{className:"hover:bg-neutral-900/50",style:{borderBottom:"1px solid #22242d"},children:[jsxRuntime.jsx("td",{className:"py-1.5 px-3 font-medium",style:{color:"#fcfcfc"},children:l.symbol.split("-")[0]}),jsxRuntime.jsx("td",{className:"py-1.5 px-3",children:jsxRuntime.jsx("span",{className:ui.cn("px-2 py-0.5 rounded text-[11px]",l.side==="long"?"bg-green-600/20 text-green-500":"bg-red-600/20 text-red-500"),children:l.side.toUpperCase()})}),jsxRuntime.jsxs("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:["$",Ps(l.price)]}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:vs(l.quantity)}),jsxRuntime.jsxs("td",{className:"py-1.5 px-3 text-right",style:{color:"#fcfcfc"},children:[st(l.fee,4)," ",l.feeCurrency]}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-center",children:jsxRuntime.jsx("span",{className:ui.cn("px-2 py-0.5 rounded text-[11px]",l.isMaker?"bg-blue-600/20 text-blue-500":"bg-purple-600/20 text-purple-500"),children:l.isMaker?"Maker":"Taker"})}),jsxRuntime.jsx("td",{className:"py-1.5 px-3 text-right",style:{color:"#c8c9d1"},children:Ss(l.timestamp)})]},l.tradeId))})]})}),n>1&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"text-sm text-neutral-400",children:["Page ",s," of ",n]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",onClick:i,disabled:s===1,className:"bg-neutral-800 hover:bg-neutral-700 text-white disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),jsxRuntime.jsx("div",{className:"flex gap-1",children:Array.from({length:Math.min(5,n)},(l,c)=>{let d;return n<=5||s<=3?d=c+1:s>=n-2?d=n-4+c:d=s-2+c,jsxRuntime.jsx("button",{type:"button",className:ui.cn("w-8 h-8 text-sm rounded transition-colors",s===d?"bg-neutral-700 text-white":"text-neutral-400 hover:bg-neutral-800 hover:text-white"),onClick:()=>a(d),children:d},d)})}),jsxRuntime.jsx(ui.Button,{size:"sm",onClick:o,disabled:s===n,className:"bg-neutral-800 hover:bg-neutral-700 text-white disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})]})}function ot(){return jsxRuntime.jsxs("div",{className:"w-full space-y-4 p-4",children:[jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"}),jsxRuntime.jsx("div",{className:"h-4 bg-neutral-800 rounded w-full animate-pulse"})]})}function it(){return jsxRuntime.jsx("div",{className:"flex items-center justify-center h-24",style:{fontSize:11,color:"#c8c9d1"},children:"No trade history"})}function Ns({userAddress:t,symbol:e,initialTimeRange:r="7d",pageSize:s=50,className:n}){let{trades:o,isLoading:i,timeRange:a,setTimeRange:l,currentPage:c,totalPages:d,goToNextPage:f,goToPreviousPage:m,goToPage:p}=rt({userAddress:t,symbol:e,initialTimeRange:r,pageSize:s});return i?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(ot,{})}):o.length===0?jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(it,{})}):jsxRuntime.jsx("div",{className:n,children:jsxRuntime.jsx(nt,{trades:o,timeRange:a,onTimeRangeChange:l,currentPage:c,totalPages:d,onNextPage:f,onPreviousPage:m,onGoToPage:p})})}
9
+ exports.CoinInfoNotFoundUI=Me;exports.CoinInfoSkeletonsUI=Fe;exports.CoinInfoUI=De;exports.CoinInfoWidget=Tr;exports.HyperliquidApiError=H;exports.HyperliquidPerpetualsClient=xe;exports.OpenOrdersEmpty=et;exports.OpenOrdersSkeleton=Ze;exports.OpenOrdersUI=Xe;exports.OpenOrdersWidget=xs;exports.OrderBookUI=Be;exports.OrderBookWidget=$r;exports.PerpetualsContext=ne;exports.PerpetualsProvider=rr;exports.PlaceOrderFormUI=Ke;exports.PlaceOrderFormWidget=ss;exports.PositionsEmpty=us;exports.PositionsSkeleton=je;exports.PositionsUI=Ge;exports.PositionsWidget=ps;exports.SearchCoinsUI=Qe;exports.SearchCoinsWidget=Qr;exports.TradeHistoryEmpty=it;exports.TradeHistorySkeleton=ot;exports.TradeHistoryUI=nt;exports.TradeHistoryWidget=Ns;exports.TradesUI=We;exports.TradesWidget=Jr;exports.cancelOrder=Tt;exports.coinsQueryKey=lt;exports.createOrder=wt;exports.fetchCoins=ct;exports.fetchKlines=yt;exports.fetchMarket=ut;exports.fetchMarkets=mt;exports.fetchOrderBook=bt;exports.fetchOrders=kt;exports.fetchPositions=vt;exports.fetchRecentTrades=ht;exports.fetchTrades=Nt;exports.klinesQueryKey=ft;exports.marketQueryKey=dt;exports.marketsQueryKey=pt;exports.orderBookQueryKey=gt;exports.ordersQueryKey=St;exports.positionsQueryKey=Pt;exports.recentTradesQueryKey=xt;exports.tradesQueryKey=Ct;exports.useCancelOrderMutation=we;exports.useCandlesSubscription=vr;exports.useCoinInfo=Re;exports.useCoinsQuery=he;exports.useCreateOrderMutation=ie;exports.useKlinesQuery=cr;exports.useMarketDataSubscription=K;exports.useMarketQuery=oe;exports.useMarketsQuery=Pe;exports.useOpenOrdersScript=Je;exports.useOrderBookQuery=ve;exports.useOrderBookScript=qe;exports.useOrdersQuery=Ce;exports.usePerpetualsClient=P;exports.usePlaceOrderFormScript=He;exports.usePositionsQuery=ke;exports.usePositionsScript=Ve;exports.useRecentTradesQuery=Se;exports.useSearchCoinsScript=ze;exports.useTradeHistoryScript=rt;exports.useTradesQuery=Ne;exports.useTradesScript=Le;exports.useUserDataSubscription=ae;exports.version=er;//# sourceMappingURL=index.js.map
3
10
  //# sourceMappingURL=index.js.map