1"use strict";(self.webpackChunkmayabot_frontend=self.webpackChunkmayabot_frontend||[]).push([[6727],{1958:(e,t,s)=>{s.d(t,{$:()=>o});const r=new Set(["USDT","USDC","BUSD","DAI","TUSD","USDP","FDUSD","USDD","GUSD","FRAX"]),o=e=>r.has(e.toUpperCase())},6719:(e,t,s)=>{s.d(t,{A:()=>l});var r=s(9950),o=s(6722),a=s(2932),i=s(3869),n=s(4414);const l=e=>{let{symbol:t,interval:s,currentPrice:l}=e;const c=(0,r.useRef)(null),d=(0,r.useRef)(null),x=(0,r.useRef)(null),u=(0,r.useRef)(null),[m,b]=(0,r.useState)(!0),[h,p]=(0,r.useState)(null),g=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!c.current)return;const e=(0,o.R9)(c.current,{layout:{background:"#111827",textColor:"#9CA3AF"},grid:{vertLines:{color:"#1F2937"},horzLines:{color:"#1F2937"}},width:c.current.clientWidth,height:500,rightPriceScale:{borderColor:"#374151"},timeScale:{borderColor:"#374151",timeVisible:!0,secondsVisible:!1},crosshair:{mode:1}});d.current=e;const t=e.addCandlestickSeries({upColor:"#10b981",downColor:"#ef4444",borderUpColor:"#10b981",borderDownColor:"#ef4444",wickUpColor:"#10b981",wickDownColor:"#ef4444"});x.current=t;const s=e.addHistogramSeries({color:"#4f46e5",priceFormat:{type:"volume"},priceScaleId:"volume",lastValueVisible:!1});e.priceScale("volume").applyOptions({scaleMargins:{top:.8,bottom:0},borderVisible:!1,visible:!1}),u.current=s;const r=()=>{c.current&&d.current&&d.current.applyOptions({width:c.current.clientWidth})};return window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r),d.current&&d.current.remove()}},[]);const f=(0,r.useCallback)(async()=>{try{b(!0),p(null);const r={"1m":1e3,"5m":500,"15m":672,"1h":720,"4h":360,"1d":365,"1w":104}[s]||100,o=await a.A.getChartCandles(t,{interval:s,limit:r});let i=[];if(o.success){var e;const t=o;null!==(e=t.data)&&void 0!==e&&e.candles&&Array.isArray(t.data.candles)?i=t.data.candles:Array.isArray(t.candles)?i=t.candles:Array.isArray(t.data)&&(i=t.data)}if(i.length>0){const e=(e,t)=>{const s=e.timestamp||e.open_time||e.time;return"number"===typeof s?s>1e12?Math.floor(s/1e3):s:"string"===typeof s?Math.floor(new Date(s).getTime()/1e3):Math.floor(Date.now()/1e3)-60*(null!==t&&void 0!==t?t:0)},s=new Map,r=[];i.forEach((t,o)=>{const a=e(t,i.length-o);s.has(a)?r[s.get(a)]=t:(s.set(a,r.length),r.push(t))});const o=r.map((t,s)=>{const o=e(t,r.length-s),a=parseFloat(t.open),i=parseFloat(t.high),n=parseFloat(t.low),l=parseFloat(t.close);return isNaN(a)||isNaN(i)||isNaN(n)||isNaN(l)?null:{time:o,open:a,high:i,low:n,close:l}}).filter(e=>null!==e),a=r.map((t,s)=>{const o=e(t,r.length-s),a=parseFloat(t.volume||0);return isNaN(a)?null:{time:o,value:a,color:parseFloat(t.close)>=parseFloat(t.open)?"#10b98180":"#ef444480"}}).filter(e=>null!==e);x.current&&u.current&&d.current?(x.current.setData(o),u.current.setData(a),o.length>0&&(g.current=o[o.length-1]),d.current.timeScale().fitContent(),b(!1)):(console.warn("[TradingChart] Chart series not initialized for ".concat(t,", retrying...")),setTimeout(()=>{x.current&&u.current&&d.current?(x.current.setData(o),u.current.setData(a),o.length>0&&(g.current=o[o.length-1]),d.current.timeScale().fitContent(),b(!1)):b(!1)},100))}else console.warn("[TradingChart] API returned no candles for ".concat(t,", using mock data")),b(!1),j()}catch(h){console.error("[TradingChart] Error loading chart data for ".concat(t,":"),h),b(!1),p("Failed to load chart data"),j()}},[t,s]),v=(0,r.useCallback)(async()=>{if(!m&&g.current&&x.current&&d.current)try{const e=await a.A.getChartTicker(t),s=e.data||e;if(e.success&&s&&x.current&&d.current){const e=parseFloat(s.price||s.current_price),t=g.current,r={time:t.time,open:t.open,high:Math.max(t.high,e),low:Math.min(t.low,e),close:e};x.current&&d.current&&(x.current.update(r),g.current=r)}}catch(h){}},[t,m]);(0,r.useEffect)(()=>{b(!0),p(null),g.current=null;let e=!0;return e&&f(),()=>{e=!1}},[t,s]),(0,r.useEffect)(()=>{if(!t)return;const e="market.".concat(t),s=i.A.channel(e),r=e=>{if(console.log("[TradingChart] Price update received:",e),g.current&&x.current&&d.current){const s=e.price||e.current_price||(e.symbol===t?e.price:null);if(s){const e=parseFloat(String(s)),t=g.current,r={time:t.time,open:t.open,high:Math.max(t.high,e),low:Math.min(t.low,e),close:e};x.current.update(r),g.current=r}}};return s.listen(".price.updated",r),s.listen("price.updated",r),s.listen("PriceUpdated",r),s.listen(".PriceUpdated",r),s.listenToAll((t,s)=>{console.log("[TradingChart] Received event on",e,":",t,s)}),()=>{s.stopListening(".price.updated",r),s.stopListening("price.updated",r),s.stopListening("PriceUpdated",r),s.stopListening(".PriceUpdated",r),s.stopListeningToAll(),i.A.leaveChannel(e)}},[t]),(0,r.useEffect)(()=>
1{if(!l||!g.current||!x.current||m)return;const e=g.current;if(Math.abs(l-e.close)/e.close>1e-4){const t={time:e.time,open:e.open,high:Math.max(e.high,l),low:Math.min(e.low,l),close:l};x.current.update(t),g.current=t}},[l,m]),(0,r.useEffect)(()=>{if(!t||m)return;const e=setInterval(()=>{v()},2e3);return()=>clearInterval(e)},[t,m,v]);const j=(0,r.useCallback)(()=>{try{const e=Math.floor(Date.now()/1e3),t={"1m":60,"5m":300,"15m":900,"1h":3600,"4h":14400,"1d":86400,"1w":604800}[s]||3600,r=100;if(!l||l<=0)return void b(!1);let o=l;const a=[],i=[];for(let s=r;s>0;s--){const r=e-s*t,n=o,l=.002*o,c=n+Math.random()*l,d=n-Math.random()*l,x=d+Math.random()*(c-d),u=100*Math.random()+50;a.push({time:r,open:n,high:c,low:d,close:x}),i.push({time:r,value:u,color:x>=n?"#10b98180":"#ef444480"}),o=x}x.current&&u.current&&(x.current.setData(a),u.current.setData(i),a.length>0&&(g.current=a[a.length-1]),d.current&&d.current.timeScale().fitContent()),b(!1)}catch(h){console.error("Error generating mock chart data:",h),p("Failed to load chart"),b(!1)}},[s,l]);return(0,r.useEffect)(()=>{!l||l<=0||m||!g.current&&x.current&&(console.log("[TradingChart] Price available (".concat(l,"), generating mock data for ").concat(t)),j())},[l,m,t,j]),(0,n.jsxs)("div",{className:"relative w-full h-full",children:[m&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900/80 z-10",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mx-auto mb-4"}),(0,n.jsx)("p",{className:"text-gray-400",children:"Loading chart data..."})]})}),h&&!m&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900/80 z-10",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsxs)("p",{className:"text-red-400 mb-2",children:["\u26a0\ufe0f ",h]}),(0,n.jsx)("button",{onClick:f,className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded text-white text-sm",children:"Retry"})]})}),(0,n.jsx)("div",{ref:c,className:"w-full h-full"})]})}},6727:(e,t,s)=>{s.r(t),s.d(t,{default:()=>m});var r=s(9950),o=s(8429),a=s(6142),i=s(7871),n=s(2932),l=s(6468),c=s(1958),d=s(6719),x=s(4414);const u=e=>{const t="string"===typeof e?parseFloat(e):Number(e);return!isFinite(t)||isNaN(t)?"0.00":t>=1e3?t.toFixed(2):t>=1?t.toFixed(4):t>=.01?t.toFixed(6):t.toFixed(8)},m=()=>{const{symbol:e}=(0,o.g)(),t=(0,o.Zp)(),{user:s}=(0,a.A)(),m=e||"BTCUSDT",b=m.replace("USDT","");(0,r.useEffect)(()=>{b&&!(0,c.$)(b)||t("/futures/BTCUSDT",{replace:!0})},[b,t]);const{showSuccess:h,showError:p,showWarning:g,confirm:f}=(0,i.dj)(),[v,j]=(0,r.useState)(0),[N,y]=(0,r.useState)(0),[w,k]=(0,r.useState)({bids:[],asks:[]}),[F,C]=(0,r.useState)(null),[S,T]=(0,r.useState)([]),[A,_]=(0,r.useState)(!0),[D,M]=(0,r.useState)("LONG"),[U,L]=(0,r.useState)(10),[P,z]=(0,r.useState)(""),[E,O]=(0,r.useState)("MARKET"),[B,W]=(0,r.useState)(null),[R,I]=(0,r.useState)(!1),[V,H]=(0,r.useState)(null),[$,q]=(0,r.useState)(!1),[G,K]=(0,r.useState)("spot_to_futures"),[X,Y]=(0,r.useState)(""),[Z,J]=(0,r.useState)(!1),[Q,ee]=(0,r.useState)("0.00"),[te,se]=(0,r.useState)("orderform"),re=(0,r.useMemo)(()=>{const e=parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0");return Math.max(0,e)},[null===F||void 0===F?void 0:F.futures_available]),oe=(0,r.useMemo)(()=>{const e=parseFloat(P)||0,t=e*v/U;return re<=0?{isValid:!1,error:"No available balance. Transfer USDT to futures first.",canSubmit:!1}:!P||e<=0?{isValid:!1,error:null,canSubmit:!1}:t>re?{isValid:!1,error:"Insufficient margin. Need ".concat(t.toFixed(2)," USDT, have ").concat(re.toFixed(2)," USDT"),canSubmit:!1}:{isValid:!0,error:null,canSubmit:!0}},[P,v,U,re]);(0,r.useEffect)(()=>{W(oe.error)},[oe.error]),(0,r.useEffect)(()=>{const e=async()=>{try{const e=await n.A.getFuturesTicker(m);e.success&&e.data&&(j(e.data.current_price||e.data.mark_price||e.data.price||0),y(e.data.change_24h||e.data.price_change_percent||0));const t=await n.A.getOrderBook(m,20);if(t.success&&t.data&&k({bids:t.data.bids||[],asks:t.data.asks||[]}),s){const e=await n.A.getFuturesBalances();e.success&&e.data&&e.data.length>0&&C(e.data[0]);const t=await n.A.getFuturesPositions();if(t.success&&t.data){const e=t.data.filter(e=>"OPEN"===e.status);T(e)}}_(!1)}catch(e){console.error("[FuturesPageNew] Error loading data:",e),_(!1)}};e();const t=setInterval(e,2e3);return()=>clearInterval(t)},[m,s]);const ae=(0,r.useCallback)(async()=>
1{if(s)try{const e=await n.A.getTradingBalances();if(e.success&&e.data){const t=e.data.balances||e.data;if(Array.isArray(t)){const e=t.find(e=>"USDT"===e.asset||"USDT"===e.symbol);e&&ee(parseFloat(e.available||e.free||"0").toFixed(2))}else t.USDT&&ee(parseFloat(t.USDT.available||t.USDT.free||"0").toFixed(2))}}catch(e){console.error("Error loading spot balance:",e)}},[s]);return A?(0,x.jsxs)("div",{className:"min-h-screen bg-bitox-bg text-white",children:[(0,x.jsx)(l.A,{}),(0,x.jsxs)("div",{className:"pt-16 px-4 py-4 space-y-4",children:[(0,x.jsx)("div",{className:"bg-bitox-surface-1 rounded-xl p-4 border border-bitox-border",children:(0,x.jsxs)("div",{className:"flex items-center gap-4",children:[(0,x.jsx)("div",{className:"skeleton-modern h-7 w-40"}),(0,x.jsx)("div",{className:"skeleton-modern h-5 w-20"}),(0,x.jsx)("div",{className:"skeleton-modern h-5 w-24"}),(0,x.jsx)("div",{className:"skeleton-modern h-5 w-16"})]})}),(0,x.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4",children:[(0,x.jsx)("div",{className:"lg:col-span-3 bg-bitox-surface-1 rounded-xl border border-bitox-border p-4",children:(0,x.jsx)("div",{className:"skeleton-modern h-[400px] w-full rounded-lg"})}),(0,x.jsxs)("div",{className:"bg-bitox-surface-1 rounded-xl border border-bitox-border p-4 space-y-2",children:[(0,x.jsx)("div",{className:"skeleton-modern h-5 w-24 mb-4"}),[...Array(10)].map((e,t)=>(0,x.jsxs)("div",{className:"flex justify-between",children:[(0,x.jsx)("div",{className:"skeleton-modern h-4 w-20"}),(0,x.jsx)("div",{className:"skeleton-modern h-4 w-16"})]},t))]})]}),(0,x.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[(0,x.jsxs)("div",{className:"bg-bitox-surface-1 rounded-xl border border-bitox-border p-6 space-y-4",children:[(0,x.jsx)("div",{className:"skeleton-modern h-10 w-full rounded-lg"}),(0,x.jsx)("div",{className:"skeleton-modern h-10 w-full rounded-lg"}),(0,x.jsx)("div",{className:"skeleton-modern h-8 w-full rounded-lg"}),(0,x.jsx)("div",{className:"skeleton-modern h-12 w-full rounded-lg"})]}),(0,x.jsxs)("div",{className:"lg:col-span-2 bg-bitox-surface-1 rounded-xl border border-bitox-border p-6",children:[(0,x.jsx)("div",{className:"skeleton-modern h-5 w-32 mb-4"}),(0,x.jsx)("div",{className:"skeleton-modern h-24 w-full rounded-lg"})]})]})]})]}):(0,x.jsxs)("div",{className:"min-h-screen bg-bitox-bg text-white",children:[(0,x.jsx)(l.A,{}),(0,x.jsxs)("div",{className:"pt-16",children:[(0,x.jsx)("div",{className:"bg-bitox-surface-1 border-b border-bitox-border px-4 py-3",children:(0,x.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[(0,x.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,x.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,x.jsx)("h1",{className:"text-xl font-bold text-white tracking-tight",children:m}),(0,x.jsx)("span",{className:"px-2 py-0.5 text-xs font-medium bg-bitox-accent/10 text-bitox-accent rounded",children:"Perpetual"})]}),(0,x.jsx)("div",{children:(0,x.jsxs)("div",{className:"text-2xl font-bold ".concat(N>=0?"text-bitox-green":"text-bitox-red"),children:["$",u(v)]})}),(0,x.jsx)("div",{className:"hidden sm:flex items-center space-x-6",children:(0,x.jsxs)("div",{children:[(0,x.jsx)("div",{className:"text-bitox-text-muted text-xs",children:"24h Change"}),(0,x.jsxs)("div",{className:"font-medium ".concat(N>=0?"text-bitox-green":"text-bitox-red"),children:[N>=0?"+":"",N.toFixed(2),"%"]})]})})]}),(0,x.jsxs)("div",{className:"flex items-center gap-4",children:[F?(0,x.jsxs)("div",{className:"text-right",children:[(0,x.jsx)("div",{className:"text-bitox-text-muted text-xs",children:"Available"}),(0,x.jsxs)("div",{className:"font-bold ".concat(re>0?"text-bitox-accent":"text-bitox-red"),children:[re.toFixed(2)," USDT"]}),(0,x.jsxs)("div",{className:"text-xs text-bitox-text-muted",children:["PNL: ",(0,x.jsx)("span",{className:parseFloat(F.futures_unrealized_pnl||"0")>=0?"text-bitox-green":"text-bitox-red",children:parseFloat(F.futures_unrealized_pnl||"0").toFixed(2)})]})]}):(0,x.jsxs)("div",{className:"text-right",children:[(0,x.jsx)("div",{className:"text-bitox-text-muted text-xs",children:"Available"}),(0,x.jsx)("div",{className:"font-bold text-bitox-accent",children:"0.00 USDT"})]}),(0,x.jsxs)("button",{onClick:()=>{ae(),Y(""),q(!0)},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold bg-bitox-accent/10 hover:bg-bitox-accent/20 text-bitox-accent rounded-lg border border-bitox-accent/30 transition-colors",children:[(0,x.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,x.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})}),"Transfer"]})]})]})}),(0,x.jsxs)("div",{className:"lg:hidden flex border-b border-bitox-border mt-4",children:[(0,x.jsx)("button",{onClick:()=>se("chart"),className:"flex-1 py-3 text-sm font-medium transition-colors ".concat("chart"===te?"text-bitox-accent border-b-2 border-bitox-accent":"text-bitox-text-muted hover:text-white"),children:"Chart"}),(0,x.jsx)("button",{onClick:()=>se("orderbook"),className:"flex-1 py-3 text-sm font-medium transition-colors ".concat("orderbook"===te?"text-bitox-accent border-b-2 border-bitox-accent":"text-bitox-text-muted hover:text-white"),children:"Order Book"}),(0,x.jsx)("button",{onClick:()=>se("orderform"),className:"flex-1 py-3 text-sm font-medium transition-colors ".concat("orderform"===te?"text-bitox-accent border-b-2 border-bitox-accent":"text-bitox-text-muted hover:text-white"),children:"Trade"})]}),(0,x.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-px bg-bitox-surface-3 mt-4",children:[(0,x.jsxs)("div",{className:"lg:col-span-3 bg-bitox-surface-1 p-3 lg:p-4 ".concat("orderbook"!==te?"hidden lg:block":""),children:[(0,x.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-bitox-text-secondary mb-3",children:"Order Book"}),(0,x.jsxs)("div",{className:"space-y-0.5 mb-2",children:[(0,x.jsxs)("div",{className:"grid grid-cols-3 text-2xs font-medium text-bitox-text-muted uppercase tracking-wider pb-2 mb-2 border-b border-bitox-border",children:[(0,x.jsx)("span",{children:"Price(USDT)"}),(0,x.jsx)("span",{className:"text-right",children:"Amount"}),(0,x.jsx)("span",{className:"text-right",children:"Total"})]}),w.asks.slice(0,12).reverse().map((e,t)=>{var s,r,o;const a=e.price||parseFloat(e[0])||0,i=e.quantity||parseFloat(e[1])||0,n=e.total||a*i,l=(null===(s=w.asks[0])||void 0===s?void 0:s.total)||((null===(r=w.asks[0])||void 0===r?void 0:r.price)||1)*((null===(o=w.asks[0])||void 0===o?void 0:o.quantity)||1);return(0,x.jsxs)("div",{className:"grid grid-cols-3 text-xs hover:bg-bitox-red/5 cursor-pointer py-[3px] relative group transition-colors",children:[(0,x.jsx)("div",{className:"absolute right-0 top-0 h-full bg-gradient-to-l from-bitox-red/10 to-transparent",style:{width:"".concat(Math.min(n/l*100,100),"%")}}),(0,x.jsx)("span",{className:"text-bitox-red font-mono relative z-10",children:u(a)}),(0,x.jsx)("span",{className:"text-right text-bitox-text-secondary font-mono relative z-10",children:i.toFixed(4)}),(0,x.jsx)("span",{className:"text-right text-bitox-text-muted font-mono relative z-10",children:u(n)})]},t)})]}),(0,x.jsxs)("div",{className:"py-2 text-center border-y border-bitox-border bg-bitox-surface-2/50",children:[(0,x.jsxs)("div",{className:"text-lg font-bold ".concat(N>=0?"text-bitox-green":"text-bitox-red"),children:["$",u(v)]}),(0,x.jsxs)("div",{className:"text-xs mt-0.5 ".concat(N>=0?"text-bitox-green":"text-bitox-red"),children:[N>=0?"\u2191":"\u2193"," ",Math.abs(N).toFixed(2),"%"]})]}),(0,x.jsx)("div",{className:"space-y-0.5 mt-2",children:w.bids.slice(0,12).map((e,t)=>{var s,r,o;const a=e.price||parseFloat(e[0])||0,i=e.quantity||parseFloat(e[1])||0,n=e.total||a*i,l=(null===(s=w.bids[0])||void 0===s?void 0:s.total)||((null===(r=w.bids[0])||void 0===r?void 0:r.price)||1)*((null===(o=w.bids[0])||void 0===o?void 0:o.quantity)||1);return(0,x.jsxs)("div",{className:"grid grid-cols-3 text-xs hover:bg-bitox-green/5 curs
1or-pointer py-[3px] relative group transition-colors",children:[(0,x.jsx)("div",{className:"absolute right-0 top-0 h-full bg-gradient-to-l from-bitox-green/10 to-transparent",style:{width:"".concat(Math.min(n/l*100,100),"%")}}),(0,x.jsx)("span",{className:"text-bitox-green font-mono relative z-10",children:u(a)}),(0,x.jsx)("span",{className:"text-right text-bitox-text-secondary font-mono relative z-10",children:i.toFixed(4)}),(0,x.jsx)("span",{className:"text-right text-bitox-text-muted font-mono relative z-10",children:u(n)})]},t)})})]}),(0,x.jsxs)("div",{className:"lg:col-span-6 bg-bitox-surface-1 p-3 lg:p-4 ".concat("chart"!==te?"hidden lg:block":""),children:[(0,x.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,x.jsx)("div",{className:"flex items-center space-x-1",children:["1m","5m","15m","1h","4h","1d"].map(e=>(0,x.jsx)("button",{onClick:()=>{},className:"px-3 py-1.5 text-xs font-medium rounded-md transition-colors ".concat("15m"===e?"bg-bitox-surface-3 text-bitox-accent border border-bitox-accent/30":"text-bitox-text-secondary hover:text-white border border-transparent"),children:e},e))})}),(0,x.jsx)("div",{className:"h-[350px] lg:h-[500px]",children:(0,x.jsx)(d.A,{symbol:m,interval:"15m",currentPrice:v})}),(0,x.jsxs)("div",{className:"sticky bottom-0 lg:relative lg:bottom-auto grid grid-cols-2 gap-2 sm:gap-3 mt-0 lg:mt-3 px-3 lg:px-0 pb-2 lg:pb-0 bg-bitox-surface-1 lg:bg-transparent z-10",children:[(0,x.jsxs)("button",{onClick:()=>{M("LONG"),window.innerWidth<1024&&se("orderform")},className:"bg-bitox-green hover:bg-bitox-green/90 active:bg-bitox-green/80 text-white font-bold py-3 sm:py-4 rounded-lg transition-colors flex items-center justify-center gap-2 text-base sm:text-lg shadow-md",children:[(0,x.jsx)("svg",{className:"w-4 h-4 sm:w-5 sm:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,x.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 15l7-7 7 7"})}),"Long"]}),(0,x.jsxs)("button",{onClick:()=>{M("SHORT"),window.innerWidth<1024&&se("orderform")},className:"bg-bitox-red hover:bg-bitox-red/90 active:bg-bitox-red/80 text-white font-bold py-3 sm:py-4 rounded-lg transition-colors flex items-center justify-center gap-2 text-base sm:text-lg shadow-md",children:[(0,x.jsx)("svg",{className:"w-4 h-4 sm:w-5 sm:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,x.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M19 9l-7 7-7-7"})}),"Short"]})]})]}),(0,x.jsxs)("div",{className:"lg:col-span-3 bg-bitox-surface-1 p-4 ".concat("orderform"!==te?"hidden lg:block":""),children:[(0,x.jsxs)("div",{className:"grid grid-cols-2 rounded-lg overflow-hidden mb-4",children:[(0,x.jsx)("button",{onClick:()=>M("LONG"),className:"py-2.5 text-sm font-semibold transition-colors ".concat("LONG"===D?"bg-bitox-green text-white":"bg-bitox-surface-2 text-bitox-text-secondary hover:text-white"),children:"Long"}),(0,x.jsx)("button",{onClick:()=>M("SHORT"),className:"py-2.5 text-sm font-semibold transition-colors ".concat("SHORT"===D?"bg-bitox-red text-white":"bg-bitox-surface-2 text-bitox-text-secondary hover:text-white"),children:"Short"})]}),(0,x.jsxs)("div",{className:"mb-4",children:[(0,x.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,x.jsx)("label",{className:"text-sm font-medium",children:"Leverage"}),(0,x.jsxs)("span",{className:"text-2xl font-bold text-bitox-accent",children:[U,"x"]})]}),(0,x.jsx)("div",{className:"grid grid-cols-5 gap-1.5 mb-2",children:[1,5,10,25,50].map(e=>(0,x.jsxs)("button",{onClick:()=>L(e),className:"py-1.5 rounded text-xs font-medium transition-colors ".concat(U===e?"bg-bitox-accent text-bitox-bg":"bg-bitox-surface-3 text-bitox-text-secondary hover:bg-bitox-surface-2"),children:[e,"x"]},e))}),(0,x.jsx)("input",{type:"range",min:"1",max:"100",value:U,onChange:e=>L(parseInt(e.target.value)),className:"w-full"})]}),(0,x.jsxs)("div",{className:"mb-4",children:[(0,x.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,x.jsx)("label",{className:"text-sm font-medium",children:"Amount"}),(0,x.jsxs)("span",{className:"text-xs text-bitox-text-muted",children:["Available: ",(0,x.jsxs)("span",{className:re>0?"text-bitox-accent":"text-bitox-red",children:[re.toFixed(2)," USDT"]})]})]}),(0,x.jsx)("input",{type:"text",inputMode:"decimal",value:P,onChange:e=>{const t=(e=>{let t=e.replace(/[^0-9.]/g,"");const s=t.split(".");return s.length>2&&(t=s[0]+"."+s.slice(1).join("")),t})(e.target.value);z(t)},placeholder:"0.00",className:"w-full bg-bitox-surface-2 border rounded-lg px-4 py-3 text-white text-lg font-mono focus:outline-none ".concat(B?"border-bitox-red focus:border-bitox-red":"border-bitox-border focus:border-bitox-accent")}),B&&(0,x.jsxs)("p",{className:"text-bitox-red text-xs mt-1 flex items-center gap-1",children:[(0,x.jsx)("svg",{className:"w-3 h-3",fill:"
1currentColor",viewBox:"0 0 20 20",children:(0,x.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),B]}),(0,x.jsx)("div",{className:"grid grid-cols-4 gap-2 mt-2",children:[25,50,75,100].map(e=>(0,x.jsxs)("button",{onClick:()=>{if(re>0&&v>0){const t=re*U*(e/100)/v;z(Math.max(0,t).toFixed(8))}},disabled:re<=0,className:"py-2 text-xs font-medium rounded border transition-colors ".concat(re<=0?"bg-bitox-surface-2 text-bitox-text-muted border-bitox-border/50 cursor-not-allowed opacity-50":"bg-bitox-surface-2 hover:bg-bitox-accent/10 hover:text-bitox-accent text-bitox-text-secondary border-bitox-border"),children:[e,"%"]},e))})]}),(0,x.jsx)("button",{onClick:async()=>{if(s){if(!P||parseFloat(P)<=0)g("Invalid Amount","Please enter a valid amount.");else if(!R){I(!0);try{const t={symbol:m,side:D,quantity:P,leverage:U};console.log("[FuturesPageNew] Opening position:",t);const s=await n.A.openFuturesPosition(t);var e;if(s.success)h("Position Opened! \ud83d\ude80","".concat(D," position at $").concat((null===(e=s.data)||void 0===e?void 0:e.entry_price)||"N/A")),z("");else p("Failed",s.message||"Could not open position.")}catch(a){var r,o;console.error("[FuturesPageNew] Error:",a),p("Error",(null===(r=a.response)||void 0===r||null===(o=r.data)||void 0===o?void 0:o.message)||a.message||"Failed to open position.")}finally{I(!1)}}}else t("/login")},disabled:!s||!oe.canSubmit||R,className:"w-full py-4 rounded-lg font-bold text-lg transition-all flex items-center justify-center gap-2 ".concat(s&&oe.canSubmit&&!R?"LONG"===D?"bg-bitox-green hover:bg-bitox-green/90 text-white":"bg-bitox-red hover:bg-bitox-red/90 text-white":"bg-bitox-surface-3 text-bitox-text-muted cursor-not-allowed opacity-60"),children:R?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)("svg",{className:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,x.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,x.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):s?B||"Open ".concat(D," ").concat(b):"Log In to Trade"})]})]}),s&&(0,x.jsxs)("div",{className:"mt-px bg-bitox-surface-1 p-4",children:[(0,x.jsx)("h3",{className:"text-sm font-semibold uppercase tracking-wider text-white mb-4",children:"Open Positions"}),0===S.length?(0,x.jsx)("div",{className:"text-center py-8 text-bitox-text-muted",children:"No open positions"}):(0,x.jsx)("div",{className:"overflow-x-auto -mx-4 px-4",children:(0,x.jsxs)("table",{className:"table-modern w-full text-sm min-w-[800px]",children:[(0,x.jsx)("thead",{className:"sticky top-0 bg-bitox-surface-1",children:(0,x.jsxs)("tr",{className:"text-bitox-text-muted text-xs border-b border-bitox-border",children:[(0,x.jsx)("th",{className:"text-left py-2",children:"Symbol"}),(0,x.jsx)("th",{className:"text-left py-2",children:"Side"}),(0,x.jsx)("th",{className:"text-right py-2",children:"Size"}),(0,x.jsx)("th",{className:"text-right py-2",children:"Entry"}),(0,x.jsx)("th",{className:"text-right py-2",children:"Mark"}),(0,x.jsx)("th",{className:"text-right py-2",children:"Liq. Price"}),(0,x.jsx)("th",{className:"text-right py-2",children:"PNL (ROE%)"}),(0,x.jsx)("th",{className:"text-center py-2",children:"Action"})]})}),(0,x.jsx)("tbody",{children:S.map(e=>{const t=parseFloat(e.entry_price),s=e.symbol===m?v:parseFloat(e.mark_price),r=parseFloat(e.quantity),o=parseFloat(e.margin);let a=0;a="LONG"===e.side?(s-t)*r:(t-s)*r;const i=o>0?a/o*100:0;return(0,x.jsxs)("tr",{className:"border-b border-bitox-border hover:bg-bitox-surface-2/50",children:[(0,x.jsx)("td",{className:"py-3",children:(0,x.jsxs)("div",{className:"flex items-center gap-2",children:[(0,x.jsx)("span",{className:"font-medium",children:e.symbol}),(0,x.jsxs)("span",{className:"px-2 py-0.5 text-xs font-bold rounded ".concat("LONG"===e.side?"bg-bitox-green/20 text-bitox-green":"bg-bitox-red/20 text-bitox-red"),children:[e.side," ",e.leverage,"x"]})]})}),(0,x.jsx)("td",{className:"py-3",children:e.side}),(0,x.jsx)("td",{className:"py-3 text-right font-mono",children:r.toFixed(4)}),(0,x.jsxs)("td",{className:"py-3 text-right font-mono",children:["$",u(t)]}),(0,x.jsxs)("td",{className:"py-3 text-right font-mono",children:["$",u(s)]}),(0,x.jsxs)("td",{className:"py-3 text-right font-mono text-bitox-accent",children:["$",u(e.liquidation_price)]}),(0,x.jsx)("td",{className:"py-3 text-right",children:(0,x.jsxs)("div",{className:"inline-block px-3 py-1 rounded font-mono font-bold ".concat(a>=0?"bg-bitox-green/10 text-bitox-green border border-bitox-green/30":"bg-bitox-red/10 text-bitox-red border border-bitox-red/30"),children:[a>
1=0?"+":"",a.toFixed(2)," (",i>=0?"+":"",i.toFixed(2),"%)"]})}),(0,x.jsx)("td",{className:"py-3 text-center",children:(0,x.jsx)("button",{onClick:()=>(async e=>{if(V===e)return;if(await f({title:"Close Position?",message:"Are you sure you want to close this futures position at market price?",confirmText:"Close Position",cancelText:"Keep Open",type:"warning"})){H(e);try{const s=await n.A.closeFuturesPosition(e);if(s.success){var t;const e=(null===(t=s.data)||void 0===t?void 0:t.pnl)||"0";parseFloat(e)>=0?h("Position Closed! \ud83d\udcb0","PNL: +".concat(e," USDT")):g("Position Closed","PNL: ".concat(e," USDT"))}else p("Failed",s.message||"Could not close position.")}catch(s){p("Error",s.message||"Failed to close position.")}finally{H(null)}}})(e.id),disabled:V===e.id,className:"px-4 py-1 rounded text-xs font-semibold flex items-center gap-1 ".concat(V===e.id?"bg-bitox-surface-3 text-bitox-text-muted cursor-not-allowed":"bg-bitox-accent/10 hover:bg-bitox-accent/20 text-bitox-accent border border-bitox-accent/30"),children:V===e.id?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)("svg",{className:"animate-spin h-3 w-3",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,x.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,x.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Closing..."]}):"Close"})})]},e.id)})})]})})]})]}),$&&(0,x.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm",onClick:()=>q(!1),children:(0,x.jsxs)("div",{className:"bg-bitox-surface-1 border border-bitox-border rounded-2xl w-full max-w-md mx-4 p-6 shadow-2xl",onClick:e=>e.stopPropagation(),children:[(0,x.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,x.jsx)("h3",{className:"text-lg font-bold text-white",children:"Transfer"}),(0,x.jsx)("button",{onClick:()=>q(!1),className:"text-bitox-text-muted hover:text-white transition-colors",children:(0,x.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,x.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,x.jsx)("div",{className:"mb-5",children:(0,x.jsxs)("div",{className:"flex items-center justify-between bg-bitox-surface-2 rounded-xl p-4",children:[(0,x.jsxs)("div",{className:"text-center flex-1",children:[(0,x.jsx)("div",{className:"text-xs text-bitox-text-muted mb-1",children:"From"}),(0,x.jsx)("div",{className:"text-sm font-semibold text-white",children:"spot_to_futures"===G?"Main Wallet":"Futures Wallet"}),(0,x.jsx)("div",{className:"text-xs text-bitox-text-muted mt-1",children:"".concat("spot_to_futures"===G?Q:parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0").toFixed(2)," USDT")})]}),(0,x.jsx)("button",{onClick:()=>K(e=>"spot_to_futures"===e?"futures_to_spot":"spot_to_futures"),className:"mx-3 w-10 h-10 flex items-center justify-center rounded-full bg-bitox-accent/10 hover:bg-bitox-accent/20 border border-bitox-accent/30 transition-all hover:rotate-180 duration-300",children:(0,x.jsx)("svg",{className:"w-5 h-5 text-bitox-accent",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,x.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),(0,x.jsxs)("div",{className:"text-center flex-1",children:[(0,x.jsx)("div",{className:"text-xs text-bitox-text-muted mb-1",children:"To"}),(0,x.jsx)("div",{className:"text-sm font-semibold text-white",children:"spot_to_futures"===G?"Futures Wallet":"Main Wallet"})]})]})}),(0,x.jsxs)("div",{className:"mb-4",children:[(0,x.jsx)("label",{className:"text-xs text-bitox-text-muted mb-2 block",children:"Coin"}),(0,x.jsxs)("div",{className:"flex items-center bg-bitox-surface-2 rounded-lg px-4 py-3 border border-bitox-border",children:[(0,x.jsx)("div",{className:"w-6 h-6 rounded-full bg-green-500/20 flex items-center justify-center mr-3",children:(0,x.jsx)("span",{className:"text-xs font-bold text-green-400",children:"$"})}),(0,x.jsx)("span",{className:"text-white font-medium",children:"USDT"}),(0,x.jsx)("span",{className:"ml-2 text-bitox-text-muted text-sm",children:"Tether"})]})]}),(0,x.jsxs)("div",{className:"mb-5",children:[(0,x.jsx)("label",{className:"text-xs text-bitox-text-muted mb-2 block",children:"Amount"}),(0,x.jsxs)("div",{className:"relative",children:[(0,x.jsx)("input",{type:"number",value:X,onChange:e=>Y(e.target.value),placeholder:"0.00",className:"w-full bg-bitox-surface-2 border border-bitox-border rounded-lg px-4 py-3 text-white placeholder-bitox-text-muted focus:outline-none focus:border-bitox-accent/50 transition-colors"}),(0,x.jsx)("button",{onClick:()=>{const e="spot_to_futures"===G?Q:parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0").toFixed(2);Y(e)},className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-semibold text-bitox-accent hover:text-bitox-accent/80 transition-colors",children:"MAX"})]}),(0,x.jsxs)("div",{className:"flex justify-between mt-2 text-xs text-bitox-text-muted",children:[(0,x.jsx)("span",{children:"Available:"}),(0,x.jsx)("span",{className:"text-bitox-text-secondary font-mono",children:"".concat("spot_to_futures"===G?Q:parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0").toFixed(2)," USDT")})]}),(0,x.jsx)("div",{className:"grid grid-cols-4 gap-2 mt-3",children:[25,50,75,100].map(e=>{const t="spot_to_futures"===G?parseFloat(Q):parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0");return(0,x.jsxs)("button",{onClick:()=>Y((t*e/100).toFixed(2)),className:"py-1.5 text-xs font-medium bg-bitox-surface-3 hover:bg-bitox-accent/10 hover:text-bitox-accent text-bitox-text-secondary rounded transition-colors",children:[e,"%"]},e)})})]}),(0,x.jsx)("button",{onClick:async()=>{const e=parseFloat(X);if(isNaN(e)||e<=0)return void g("Invalid Amount","Please enter a valid amount");const t="spot_to_futures"===G?parseFloat(Q):Math.max(0,parseFloat((null===F||void 0===F?void 0:F.futures_available)||"0"));if(e>t)g("Insufficient Balance","You only have ".concat(t.toFixed(2)," USDT available"));else{J(!0);try{const t=await n.A.transferFunds({asset:"USDT",amount:X,direction:G});t.success?(h("Transfer Successful","".concat(e.toFixed(2)," USDT transferred successfully")),Y(""),q(!1)):p("Transfer Failed",t.message||"Failed to transfer funds")}catch(s){console.error("Error transferring funds:",s),p("Transfer Error","An error occurred during transfer")}finally{J(!1)}}},disabled:Z||!X||parseFloat(X)<=0,className:"w-full py-3.5 rounded-xl font-bold text-sm bg-bitox-accent hover:bg-bitox-accent/90 text-bitox-bg transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:Z?(0,x.jsxs)("span",{className:"flex items-center justify-center gap-2",children:[(0,x.jsxs)("svg",{className:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,x.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,x.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Transferring..."]}):"Transfer ".concat(X||"0.00"," USDT")})]})})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.