@orderly.network/ui-orders 2.0.7 → 2.1.0

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.js CHANGED
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var react = require('react');
4
- var ui$1 = require('@orderly.network/ui');
4
+ var ui = require('@orderly.network/ui');
5
5
  var types = require('@orderly.network/types');
6
6
  var uiConnector = require('@orderly.network/ui-connector');
7
7
  var hooks = require('@orderly.network/hooks');
8
+ var i18n = require('@orderly.network/i18n');
8
9
  var jsxRuntime = require('react/jsx-runtime');
9
10
  var utils = require('@orderly.network/utils');
10
11
  var uiTpsl = require('@orderly.network/ui-tpsl');
@@ -12,18 +13,18 @@ var uiShare = require('@orderly.network/ui-share');
12
13
  var dateFns = require('date-fns');
13
14
  var reactApp = require('@orderly.network/react-app');
14
15
 
15
- var bt=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:n}=e,o=react.useRef(null);return react.useImperativeHandle(e.ref,()=>({download:()=>{o.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:o,sharePnLConfig:n}};var H=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ae(e){if(typeof e.type<"u"){let t=new Array;if(e.parent_algo_type){if(e.algo_type===types.AlgoOrderType.STOP_LOSS){let o=e.type===types.OrderType.CLOSE_POSITION?["Position","SL"]:["SL"];t.push(...o);}if(e.algo_type===types.AlgoOrderType.TAKE_PROFIT){let o=e.type===types.OrderType.CLOSE_POSITION?["Position","TP"]:["TP"];t.push(...o);}return t}(typeof e.type=="string"?[e.type.replace("_ORDER","").toLowerCase()]:[e.type]).map(o=>H(o));let n=typeof e.type=="string"?e.type.replace("_ORDER","").toLowerCase():H(e.type);return [types.OrderType.ASK,types.OrderType.BID].includes(e.type)?[H(types.OrderType.LIMIT)]:e.algo_order_id===void 0||e.algo_order_id&&e.algo_type==="BRACKET"?[H(n)]:[`Stop ${n}`]}if(typeof e.algo_type<"u"){let t=new Array;e.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL&&t.push("Position");let r=e?.child_orders?.find(o=>o.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!o.trigger_price),n=e?.child_orders?.find(o=>o.algo_type===types.AlgoOrderType.STOP_LOSS&&!!o.trigger_price);return (r||n)&&t.push(r&&n?"TP/SL":r?"TP":"SL"),t}}function ee(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function Yo(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(o=>o.algo_type===types.AlgoOrderType.TAKE_PROFIT),n=t?.child_orders?.find(o=>o.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:n}}function et(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:n}=Yo(e);if(!r&&!n||typeof e.price===void 0||!e.price)return t;let o=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&hooks.utils.priceToPnl({qty:o,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=n?.trigger_price&&hooks.utils.priceToPnl({qty:o,price:n?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:n.algo_type}),s=i?hooks.utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:d}}}var Pr=react.createContext({}),M=()=>react.useContext(Pr),Pt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(Pr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var xr=react.createContext({}),J=()=>react.useContext(xr),xt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:n,editAlgoOrder:o}=e,i=hooks.useSymbolsInfo(),a=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?n(l.root_algo_order_id,l.symbol):n(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),s=react.useCallback(async(l,P)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:false;await ui$1.modal.sheet({title:"Edit Order",classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[]),d=react.useCallback((l,P,u)=>{let{min_notional:x}=i[l]();return hooks.checkNotional(P,u,x)},[i]);return jsxRuntime.jsx(xr.Provider,{value:{onCancelOrder:a,onEditOrder:s,editOrder:r,editAlgoOrder:o,checkMinNotional:d},children:e.children})};var hr=react.createContext({}),V=()=>react.useContext(hr),Ot=e=>{let{quote_dp:t}=M(),[r,n]=react.useState(),[o]=hooks.useMutation("/v1/algo/order","DELETE"),[i]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),l=async S=>o(null,{order_id:S.algo_order_id,symbol:S.symbol}),P=async(S,N)=>i({order_id:S.algo_order_id,child_orders:S.child_orders.map(v=>({order_id:v.algo_order_id,quantity:N.order_quantity}))}),u=S=>a.cache.get(d)?.data.rows.find(v=>v.symbol===S),{sl_trigger_price:x,tp_trigger_price:L,tpPnL:_,slPnL:I}=pn({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??false)){let S=u(e.order.symbol);S&&n(S);}},[e.order.symbol]),jsxRuntime.jsx(hr.Provider,{value:{order:e.order,sl_trigger_price:x,tp_trigger_price:L,tpPnL:_,slPnL:I,onCancelOrder:l,onUpdateOrder:P,getRelatedPosition:u,position:r},children:e.children})};function pn(e){let{order:t,position:r,quote_dp:n}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:o,tp_trigger_price:i}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:n}}):void 0,l=typeof a=="number"&&typeof o=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:o,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:n}}):void 0;return {sl_trigger_price:o,tp_trigger_price:i,slPnL:l,tpPnL:d}}var we=e=>{let{type:t,base:r,value:n,cancelPopover:o,isSubmitting:i,onConfirm:a}=e,s=react.useMemo(()=>{switch(t){case 0:return `You agree changing the quantity of ${r}-PERP order to `;case 1:return `You agree changing the price of ${r}-PERP order to `;case 2:return `You agree changing the trigger price of ${r}-PERP order to `}},[t]);return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:[s,jsxRuntime.jsx("span",{className:"oui-text-warning-darken",children:utils.commify(n)}),"."]}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui$1.Button,{color:"secondary",size:"md",onClick:o,disabled:i,children:"Cancel"}),jsxRuntime.jsx(ui$1.ThrottledButton,{size:"md",loading:i,onClick:a,children:"Confirm"})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:o,children:jsxRuntime.jsx(ui$1.CloseIcon,{size:16,color:"white",opacity:1})})]})};var Ie=e=>{let{inputRef:t,dp:r,value:n,setValue:o,setEditing:i,error:a,handleKeyDown:s,onClick:d,onClose:l,onFocus:P,onBlur:u,hintInfo:x}=e;react.useEffect(()=>{let _=t.current;if(_){let I=_.value.length;_.setSelectionRange(I,I);}i(true);},[]);let L=(x?.length||0)>0;return jsxRuntime.jsx(ui$1.Tooltip,{content:x,open:L,children:jsxRuntime.jsx(ui$1.Input,{ref:t,type:"text",size:"sm",formatters:[ui$1.inputFormatter.numberFormatter,ui$1.inputFormatter.dpFormatter(r),ui$1.inputFormatter.currencyFormatter],value:n,onValueChange:_=>o(_),helpText:a,onClick:_=>{_.stopPropagation(),_.preventDefault();},autoComplete:"off",onFocus:P,onBlur:u,onKeyDown:s,autoFocus:true,color:L?"danger":void 0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsxRuntime.jsx("button",{onClick:d,children:jsxRuntime.jsx(ui$1.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Nt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:n}=t,[o,i]=react.useState(t.quantity.toString()),[a,s]=react.useState(false);react.useEffect(()=>{m(t.quantity.toString());},[e.order.quantity]);let[d,l]=react.useState(false),[P,u]=react.useState(),{editOrder:x,editAlgoOrder:L,checkMinNotional:_}=J(),{onUpdateOrder:I,position:S}=V(),{base_dp:N,base:v,base_tick:k}=M(),m=async(f,q)=>{i(f);let g=Math.abs(S?.position_qty||0);if(S&&n&&Number(f)>g)u(`Quantity should be less than position quantity : ${g}`);else {let $=Number(f);q&&$>q?u(`Quantity should be less than ${utils.commifyOptional(q,{fix:N})}`):u(void 0);}return Promise.resolve()},F=()=>{l(false),s(false);},A=()=>{l(false),m(t.quantity.toString()),s(false);},[U,p]=react.useState(false),h=react.useRef(null),D=()=>{if(P)return;if(Number(o)===Number(t.quantity)){s(false);return}let f=t.algo_order_id!==void 0?t.trigger_price:t.price;if(f!==null&&t.reduce_only!==true){let q=_(t.symbol,f,o);if(q){ui$1.toast.error(q),p(false),A();return}}l(true);},ce=f=>{f?.stopPropagation(),f?.preventDefault(),D();},w=f=>{f.key==="Enter"&&(f?.stopPropagation(),f?.preventDefault(),D());},O=react.useCallback(()=>{p(true);let f={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:o,algo_order_id:t.algo_order_id};if(typeof f.algo_order_id<"u"&&f.order_type==="MARKET"){let{order_price:g,...$}=f;f=$;}typeof t.reduce_only<"u"&&(f.reduce_only=t.reduce_only),t.order_tag!==void 0&&(f={...f,order_tag:t.order_tag}),t?.visible_quantity===0&&(f.visible_quantity=0),t?.tag!==void 0&&(f.order_tag=t.tag);let q;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?q=I(t,f):t.algo_order_id!==void 0?q=L(t.algo_order_id.toString(),f):q=x(t.order_id.toString(),f),q.then(g=>{F(),m(o.toString());},g=>{ui$1.toast.error(g.message),m(t.quantity.toString()),A();}).finally(()=>p(false));},[o]),E=react.useRef(null),G=react.useRef(null),ie=f=>{E.current&&G.current&&!E.current.contains(f.target)&&!G.current.contains(f.target)&&!d&&A();};react.useEffect(()=>(document.addEventListener("mousedown",ie),()=>{document.removeEventListener("mousedown",ie);}),[d,t.quantity]);let Te=()=>!a||e.disableEdit?jsxRuntime.jsx(kn,{order:t,quantity:o,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(qn,{inputRef:h,quantitySliderRef:G,base_dp:N,base_tick:k,quantity:o,setQuantity:m,editing:a,setEditing:s,handleKeyDown:w,onClick:ce,onClose:A,symbol:t.symbol,reduce_only:n,positionQty:S?.position_qty,error:P,confirmOpen:d,side:t.side,order:t,setError:u});return jsxRuntime.jsx(ui$1.Popover,{open:d,onOpenChange:l,content:jsxRuntime.jsx(we,{type:0,base:v,value:o,cancelPopover:A,isSubmitting:U,onConfirm:O}),contentProps:{onOpenAutoFocus:f=>{}},children:jsxRuntime.jsx("div",{onClick:f=>{f.stopPropagation(),f.preventDefault();},ref:E,children:Te()})})},kn=e=>{let{order:t,quantity:r}=e,n=t.total_executed_quantity;return jsxRuntime.jsxs(ui$1.Flex,{direction:"row",justify:"start",gap:1,className:ui$1.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",ee(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:n}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui$1.Flex,{r:"base",className:ui$1.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui$1.Text,{size:"2xs",children:r})})]})},qn=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:n,base_tick:o,quantity:i,setQuantity:a,editing:s,setEditing:d,handleKeyDown:l,onClick:P,onClose:u,error:x,symbol:L,reduce_only:_,positionQty:I,confirmOpen:S,side:N,order:v}=e,k=hooks.useMaxQty(L,v.side,v.reduce_only),m=react.useMemo(()=>_?Math.abs(I??0):v.quantity+Math.abs(k),[v.quantity,k,_,I]),[F,A]=react.useState(void 0);react.useEffect(()=>{if(F===void 0){let p=new utils.Decimal(i).div(m).abs().mul(100).toNumber();A(p);}},[F,m,i]);let U=async p=>(o>0&&(p=hooks.utils.formatNumber(p,o)??p),a(`${p}`,m));return jsxRuntime.jsxs(ui$1.PopoverRoot,{open:!S,children:[jsxRuntime.jsx(ui$1.PopoverTrigger,{children:jsxRuntime.jsx(Ie,{inputRef:t,dp:n,value:i,setValue:p=>{let h=Math.abs(Math.min(Number(p),m)).toString();if(a(p,m),p.endsWith("."))return;if(Number(h)===0){A(0);return}let D=new utils.Decimal(p).div(m).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();A(Math.min(100,D));},setEditing:d,handleKeyDown:l,onClick:P,onClose:u,onBlur:p=>{U(p.target.value);},hintInfo:x})}),jsxRuntime.jsx(ui$1.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:p=>{p.preventDefault();},children:jsxRuntime.jsxs(ui$1.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui$1.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${F}`}),jsxRuntime.jsxs(ui$1.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui$1.Slider,{markCount:4,value:[F??0],onValueChange:p=>{let h=Array.from(p.values());A(h[0]);let D=new utils.Decimal(h[0]).div(100).mul(m).abs().toFixed(n,utils.Decimal.ROUND_DOWN);a(D,m);},onValueCommit:p=>{let h=new utils.Decimal(p[0]).div(100).mul(m).abs().toFixed(n,utils.Decimal.ROUND_DOWN);U(h).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Rn,{onClick:p=>{A(p*100);let h=new utils.Decimal(p).mul(m).abs().toFixed(n,utils.Decimal.ROUND_DOWN);h=hooks.utils.formatNumber(h,o)??h,a(h,m),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(h.length,h.length);},100);}})]})]})})]})},Rn=e=>jsxRuntime.jsx(ui$1.Flex,{gap:2,width:"100%",children:[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:"Max",value:1}].map((r,n)=>jsxRuntime.jsx(ui$1.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:o=>{o.stopPropagation(),o.preventDefault(),e.onClick(r.value);},className:"oui-w-1/5",children:r.label},n))});var kr=e=>{let{order:t}=e,[r,n]=react.useState(()=>t.type===types.OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[o,i]=react.useState(false),[a,s]=react.useState(false),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[P,u]=react.useState(false),{editOrder:x,editAlgoOrder:L,checkMinNotional:_}=J(),{base:I,quote_dp:S}=M(),N=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),v=()=>{i(false),s(false);},k=()=>{i(false),n(t.price?.toString()??"Market"),s(false);},m=react.useMemo(()=>!N||l||!a?"":Number(r)>N.max?`Price can not be greater than ${N.max} USDC.`:Number(r)<N.min?`Price can not be less than ${N.min} USDC.`:"",[l,a,N,r]),F=O=>{if(O?.stopPropagation(),O?.preventDefault(),!(m.length>0)){if(r===`${t.price}`){s(false);return}if(t.reduce_only!==true){let E=_(t.symbol,r,t.quantity);if(E){ui$1.toast.error(E),u(false),k();return}}i(true);}},A=O=>{O.key==="Enter"&&F(O);},U=()=>{u(true);let O=t.order_id,E={order_price:r,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(E.reduce_only=t.reduce_only),t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),d&&(O=t.algo_order_id,E={...E,order_id:O,price:r,algo_order_id:O}),t?.visible_quantity===0&&(E.visible_quantity=0),t.tag!==void 0&&(E.order_tag=t.tag);let G;t.algo_order_id!==void 0?G=L(t.algo_order_id.toString(),E):G=x(t.order_id.toString(),E),G.then(ie=>{v(),n(r);},ie=>{ui$1.toast.error(ie.message),k();}).finally(()=>u(false));},p=react.useRef(null);react.useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let h=react.useRef(null),D=O=>{h.current&&!h.current.contains(O.target)&&!o&&k();};if(react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[o,t.price]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let w=()=>!a||e.disableEdit?jsxRuntime.jsx(Hn,{order:t,price:r,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(Ie,{inputRef:p,dp:S,value:r,setValue:n,setEditing:s,handleKeyDown:A,onClick:F,onClose:k,hintInfo:m});return jsxRuntime.jsx(ui$1.Popover,{open:o,onOpenChange:i,content:jsxRuntime.jsx(we,{type:1,base:I,value:r,cancelPopover:k,isSubmitting:P,onConfirm:U}),children:jsxRuntime.jsx("div",{onClick:O=>{O.stopPropagation(),O.preventDefault();},ref:h,children:w()})})},Hn=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui$1.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ee(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui$1.Flex,{r:"base",className:ui$1.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui$1.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var zr=e=>{let{order:t}=e,[r,n]=react.useState("");react.useEffect(()=>{n(t.trigger_price?.toString()??"0");},[t.trigger_price]);let o=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=react.useState(false),[d,l]=react.useState(false),[P,u]=react.useState(false),{editAlgoOrder:x,checkMinNotional:L}=J(),{base:_,quote_dp:I,quote_max:S,quote_min:N}=M(),v=react.useMemo(()=>{if(!((!o||i)&&!d)){if(Number(r)>S)return `Trigger price must be less than ${S}`;if(Number(r)<N)return `Trigger price must be greater than ${N}`}},[d,r,o,i]),k=()=>{s(false),l(false);},m=()=>{n(t.trigger_price?.toString()??"0"),s(false),l(false);},F=react.useRef(null),A=w=>{F.current&&!F.current.contains(w.target)&&!a&&m();};react.useEffect(()=>(document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A);}),[a,t.trigger_price]);let U=w=>{if(w?.stopPropagation(),w?.preventDefault(),l(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let O=L(t.symbol,t.price,t.quantity);if(O){ui$1.toast.error(O),u(false),m();return}}s(true);}},p=w=>{w.key==="Enter"&&U(w);},h=()=>{if((v??"").length>0)return;u(true);let w={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(w={...w,order_tag:t.order_tag}),x(`${t.algo_order_id}`,w).then(O=>{k(),n(r);},O=>{ui$1.toast.error(O.message),n(t.trigger_price?.toString()??"--"),m();}).finally(()=>u(false));},D=react.useRef(null);if(!o||i)return jsxRuntime.jsx(ui$1.Text,{children:"--"});let ce=()=>!d||e.disableEdit?jsxRuntime.jsx(Jn,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(Ie,{inputRef:D,dp:I,value:r,setValue:n,setEditing:l,handleKeyDown:p,onClick:U,onClose:m,hintInfo:v});return jsxRuntime.jsx(ui$1.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(we,{type:2,base:_,value:r,cancelPopover:m,isSubmitting:P,onConfirm:h}),children:jsxRuntime.jsx("div",{onClick:w=>{w.stopPropagation(),w.preventDefault();},ref:F,children:ce()})})},Jn=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui$1.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ee(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui$1.Flex,{r:"base",className:ui$1.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui$1.Text,{size:"2xs",children:r})})})};var nt=e=>{let{order:t}=e,{onCancelOrder:r}=J(),[n,o]=react.useState(false);return jsxRuntime.jsx(ui$1.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:i=>{r&&(i.preventDefault(),i.stopPropagation(),o(true),r(t).then(a=>a,a=>{ui$1.toast.error(a.message);}).finally(()=>{o(false);}));},loading:n,children:"Cancel"})};var Ur=e=>{let{record:t}=e,[r,n]=react.useState(false),[o,{data:i,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),P=react.useCallback(()=>{n(false);let u={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(u.visible_quantity=0),typeof t.reduce_only<"u"&&(u.reduce_only=t.reduce_only),o(u);},[]);return jsxRuntime.jsx(ui$1.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:u=>{d||(u.preventDefault(),u.stopPropagation(),P());},children:"Renew"})};var Kr=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:n}=V();return jsxRuntime.jsx(ui,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:n,tooltip:true})},ui=e=>{let{direction:t="row",order:r,position:n}=e,o=hooks.useSymbolsInfo(),i=react.useMemo(()=>{let d=[];if(!e.tooltip||!r||!n)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=n.position_qty),e.takeProfitPrice&&d.push(jsxRuntime.jsx(Qr,{qty:l,price:e.takeProfitPrice,entryPrice:n.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:o[r.symbol]()},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(Qr,{qty:l,price:e.stopLossPrice,entryPrice:n.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:o[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:d})},[e.takeProfitPrice,e.stopLossPrice,n?.average_open_price,r?.side,r?.quantity,r?.algo_type]),a=react.useMemo(()=>{let d=[];return r?.symbol?(e.takeProfitPrice&&d.push(jsxRuntime.jsx(ui$1.Text.numeral,{className:ui$1.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:o[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"TP\xA0-\xA0"}):""},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(ui$1.Text.numeral,{className:ui$1.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:o[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"SL\xA0-\xA0"}):""},"sl")),d.length===0?jsxRuntime.jsx("span",{children:"-"}):(d.length===2&&t==="row"&&d.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),d)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol]),s=jsxRuntime.jsx("div",{className:ui$1.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:a});return e.tooltip?jsxRuntime.jsx(ui$1.Tooltip,{content:i,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:s}):s},Qr=e=>{let{qty:t,price:r,entryPrice:n,orderSide:o,orderType:i,symbolInfo:a}=e,s=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:n,orderSide:o,orderType:i},{symbol:a}),d=i===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL";return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:`${d} PnL:`}),jsxRuntime.jsx(ui$1.Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:s===0?"oui-text-base-contrast-36":s>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:s===0?"":s>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(s)}`})]})};var Yr=e=>{let{order:t}=e,{quote_dp:r,base_dp:n}=M(),{sl_trigger_price:o,tp_trigger_price:i}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:a,roi:s}=et(t);return !i&&!o?"--":jsxRuntime.jsx(ui$1.Tooltip,{content:jsxRuntime.jsxs(ui$1.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof a.tpPnL<"u"&&jsxRuntime.jsx(ui$1.Text.numeral,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:a.tpPnL}),typeof a.slPnL<"u"&&jsxRuntime.jsx(ui$1.Text.numeral,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:a.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui$1.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Vr,{type:"TP",value:i,quote_dp:r}),jsxRuntime.jsx(Vr,{type:"SL",value:o,quote_dp:r})]})})},Vr=e=>{let{type:t,value:r,quote_dp:n}=e;return r?jsxRuntime.jsx(ui$1.Text.numeral,{className:ui$1.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:n,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${t}`,"\xA0-\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Gr=e=>{let{position:t,order:r}=V(),{quote_dp:n,base_dp:o}=M();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:n,baseDP:o,position:t,order:r,label:"Edit",isEditing:true})};var Jr=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=V();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"TP\xA0-\xA0"}),jsxRuntime.jsx("span",{children:"Market"})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"SL\xA0-\xA0"}),jsxRuntime.jsx("span",{children:"Market"})]}):null]})};function Xr(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:hooks.utils.findTPSLFromOrder(e);return {tpTriggerPrice:r?"TP - Market":void 0,slTriggerPrice:t?"SL - Market":void 0}}var Ft=e=>e.sharePnLConfig==null?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("button",{type:"button",onClick:t=>{t.stopPropagation(),ui$1.modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?"LONG":"SHORT",openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsxRuntime.jsx(ui$1.ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})});var Zr=e=>{let{sharePnLConfig:t,order:r,modalId:n,iconSize:o}=e,{getFirstRefCode:i}=hooks.useReferralInfo(),a=react.useMemo(()=>i()?.code,[i]),s=hooks.useSymbolLeverage(e.order.symbol);return {iconSize:o,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:n}};var Qe=e=>{let t=Zr(e);return jsxRuntime.jsx(Ft,{...t})};var ro=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:n,sharePnLConfig:o}=e;return react.useMemo(()=>{switch(t){case "all":return [xe({width:130,showType:true,onSymbolChange:r,enableSort:false}),ve({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),Ae({width:130,title:"Order price",disableEdit:true,enableSort:false}),at({width:130,enableSort:false}),jr({width:130,symbolsInfo:e.symbolsInfo}),kt({width:124,pnlNotionalDecimalPrecision:n,sharePnLConfig:o,symbolsInfo:e.symbolsInfo}),De({width:130,enableSort:false}),He({width:130}),Ve({width:130}),_e({width:130}),Fe({width:130}),eo({width:130}),ke({width:160,enableSort:false})];case "pending":return [xe({width:172,showType:true,onSymbolChange:r,enableSort:false}),ve({width:162,className:"oui-pr-0",enableSort:false}),Ae({width:162,className:"oui-pr-0",enableSort:false}),Ke({width:162,className:"oui-pr-0"}),qi({width:130}),De({width:162,isPending:true}),_e({width:162}),Fe({width:162}),ke({width:162,enableSort:false}),Bi({width:162})];case "tp_sl":return [xe({width:176,showType:true,onSymbolChange:r,enableSort:false}),Di({width:176}),jr({width:176,symbolsInfo:e.symbolsInfo}),Fi({width:176}),Ri({width:176}),_e({width:176}),ke({width:176,enableSort:false}),Mi({width:176})];case "filled":return [xe({showType:true,width:154,onSymbolChange:r}),ve({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),Ae({width:124,title:"Order price",disableEdit:true}),ki({width:124}),Ke({width:124,disableEdit:true}),kt({width:124,pnlNotionalDecimalPrecision:n,sharePnLConfig:o,symbolsInfo:e.symbolsInfo,hideShare:true}),De({width:124}),He({width:124}),Ve({width:124}),_e({width:124}),Fe({width:124}),ke({width:176})];case "cancelled":return [xe({showType:true,width:154,onSymbolChange:r,enableSort:false}),ve({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),Ae({width:124,disableEdit:true,enableSort:false}),at({width:124,enableSort:false}),Ke({width:124,disableEdit:true}),De({width:124}),He({width:124}),Ve({width:124}),_e({width:124}),Fe({width:124})];case "rejected":return [xe({showType:true,width:154,onSymbolChange:r}),ve({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),Ae({width:124,disableEdit:true}),at({width:124}),Ke({width:124,disableEdit:true}),De({width:124}),He({width:124}),Ve({width:124}),_e({width:124}),Fe({width:124}),ke({width:176})];case "orderHistory":return [xe({showType:true,width:154,onSymbolChange:r}),ve({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),Ae({width:124,disableEdit:true}),at({width:124}),Ke({width:124,disableEdit:true}),kt({width:124,pnlNotionalDecimalPrecision:n,sharePnLConfig:o,symbolsInfo:e.symbolsInfo}),De({width:124}),He({width:124}),Ve({width:124}),_e({width:124}),Fe({width:124}),ke({width:150}),eo({width:80})]}},[t,n,o])};function xe(e){return {title:"Symbol",dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let n=ae(r)?.join(",");return `${t.split("_")[1]}-PERP (${n})`},render:(t,r)=>{let n=ee(r);return jsxRuntime.jsxs(ui$1.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui$1.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui$1.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui$1.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:o=>{e?.onSymbolChange?.({symbol:t}),o.stopPropagation(),o.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui$1.Flex,{direction:"row",gap:1,children:ae(r)?.map((o,i)=>jsxRuntime.jsx(ui$1.Badge,{color:o.toLocaleLowerCase()==="position"?n?"neutral":"primary":"neutral",size:"xs",children:o},i))})]})]})}}}function ve(e){return {title:"Filled / Quantity",dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let n=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,o=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return Ge(n,o)}:void 0,renderPlantText:(t,r)=>{if(r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED)return "Entire position";let n=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${n} / `)+`${r.quantity}`},render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(Nt,{order:r,disableEdit:e?.disableEdit})}}function Di(e){return {title:"Quantity",className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let n=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,o=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return Ge(n,o)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL)return "Entire position";let n=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${n}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Nt,{order:r})}}function Ae(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,n)=>Ge(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>utils.commifyOptional(r.price?.toString(),{fallback:"Market"}),render:(t,r)=>jsxRuntime.jsx(kr,{order:r,disableEdit:e?.disableEdit})}}function Fi(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:n,slTriggerPrice:o}=Xr(r),i=`${n||""}${o?`${n?`
16
- `:""}${o}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsxRuntime.jsx(Jr,{})}}function ki(e){return {title:"Avg. price",dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>utils.commifyOptional(t)}}function Ke(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let n=r?.algo_order_id!==void 0,o=r?.algo_type==="BRACKET";return !n||o?"--":utils.commifyOptional(t)},render:(t,r)=>jsxRuntime.jsx(zr,{order:r,disableEdit:e?.disableEdit})}}function jr(e){return {title:e?.title??"Trigger",className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let n=e?.symbolsInfo?.[r.symbol],o=n?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r),s=(a!=null?`TP: ${utils.commifyOptional(a,{fix:o,padEnd:true})}`:"")+(i!=null?`${a?`
17
- `:""}SL: ${utils.commifyOptional(i,{fix:o,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsxRuntime.jsx(Kr,{})}}function qi(e){return {title:"TP/SL",className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let n=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:o,tp_trigger_price:i}=n(),a=(i!=null?`TP: ${i}`:"")+(o!=null?`${i?`
18
- `:""}SL: ${o}`:"");return a.length>0?a:"--"},render:(t,r)=>jsxRuntime.jsx(Yr,{order:r})}}function De(e){return {title:"Notional",dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,n)=>{let o=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return Ge(o,i)}:void 0,renderPlantText:(t,r)=>qt(r,e?.isPending??false)==="Entire position"?"Entire position":utils.commifyOptional(qt(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let n=qt(r,e?.isPending??false);return n==="Entire position"?"Entire position":jsxRuntime.jsx(ui$1.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:n})}}}function kt(e){return {title:"Real. PnL",dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let n=e?.symbolsInfo?.[r.symbol],o=n?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??o,a=new utils.Decimal(t??0).toDecimalPlaces(i,utils.Decimal.ROUND_DOWN).toNumber(),s=utils.commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:n}=M(),o=e?.pnlNotionalDecimalPrecision??n,i=new utils.Decimal(t??0).toDecimalPlaces(o,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsxs(ui$1.Flex,{gap:1,children:[jsxRuntime.jsx(ui$1.Text.numeral,{dp:o,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsxRuntime.jsx(Qe,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:uiShare.SharePnLDialogId})]})}}}function _e(e){return {title:"Reduce only",dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?"Yes":"No",render:t=>jsxRuntime.jsx(ui$1.Text,{children:t?"Yes":"No"})}}function Fe(e){return {title:"Hidden",dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?"No":"Yes",render:(t,r)=>jsxRuntime.jsx(ui$1.Text,{children:r.visible_quantity!==0?"No":"Yes"})}}function ke(e){return {title:"Order time",dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let n=new Date(t);return dateFns.format(n,"yyyy-MM-dd HH:mm:ss")},render:t=>jsxRuntime.jsx(ui$1.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function He(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function Ri(e){return {title:"Notional",dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":utils.commifyOptional(r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(ui$1.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function Ve(e){return {title:"Status",dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let n=t||r.algo_status;return n==="NEW"?H("pending"):H(n)},render:(t,r)=>{let n=t||r.algo_status;return n==="NEW"?H("pending"):H(n)}}}function at(e){return {title:"Avg. open",dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>Ge(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===types.OrderType.MARKET&&!t?"--":jsxRuntime.jsx(ui$1.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>utils.commifyOptional(t,{fix:2})}}function eo(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===types.OrderStatus.CANCELLED?jsxRuntime.jsx(Ur,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(nt,{order:r}):null}}function Bi(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(nt,{order:r})}}function Mi(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui$1.Flex,{gap:3,children:[jsxRuntime.jsx(Gr,{order:r}),jsxRuntime.jsx(nt,{order:r})]})}}function Ge(e,t){return e>t?1:e<t?-1:0}function qt(e,t){return t?e.price&&e.quantity?new utils.Decimal(e.price).mul(e.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--":e.type===types.OrderType.CLOSE_POSITION&&e.status!==types.OrderStatus.FILLED?"Entire position":e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var so=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY;return jsxRuntime.jsx(ui$1.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui$1.Badge,{color:r?"success":"danger",size:"xs",children:r?"Buy":"Sell"}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},lo=e=>{let {item:t}=e;react.useCallback(()=>{let n=typeof t.type=="string"?t.type.replace("_ORDER","").toLowerCase():t.type;return t.algo_order_id&&t.algo_type!==types.AlgoOrderRootType.BRACKET?`Stop ${n}`:H(t.type)},[t]);return jsxRuntime.jsx(ui$1.Flex,{direction:"row",gap:1,children:ae(e.item)?.map((n,o)=>jsxRuntime.jsx(ui$1.Badge,{color:n.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:n},o))})},uo=e=>{let{item:t}=e;return jsxRuntime.jsx(ui$1.Text.formatted,{rule:"date",formatString:"yyyy-MM-dd hh:mm:ss",intensity:36,size:"2xs",children:t.updated_time})},co=e=>{let{item:t}=e,r=t.status||t.algo_status,n=()=>r==="NEW"?H("pending"):H(r);return jsxRuntime.jsx(ui$1.Text.formatted,{intensity:80,size:"2xs",children:n()})},Rt=e=>{let{item:t}=e,r=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui$1.Statistic,{label:"Qty.",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:"Entire position",intensity:80,children:r?"--":t.quantity})})},Bt=e=>{let{item:t}=e;return jsxRuntime.jsx(ui$1.Statistic,{label:jsxRuntime.jsx(ui$1.Text,{children:"Filled"}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var mo=e=>{let{item:t}=e,r=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui$1.Statistic,{align:"end",label:jsxRuntime.jsxs(ui$1.Text,{children:["Notional",jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:r})})},Mt=e=>{let{item:t}=e;return jsxRuntime.jsx(ui$1.Statistic,{label:"Trigger price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},fo=e=>{let{item:t}=e;return jsxRuntime.jsx(ui$1.Statistic,{label:"Mark price",align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},po=e=>{let{item:t}=e,r=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&r;return jsxRuntime.jsx(ui$1.Statistic,{label:"Limit price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsxRuntime.jsx(ui$1.Text,{children:"Market"}):jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},go=e=>{let{tp_trigger_price:t,tpPnL:r}=V();return jsxRuntime.jsx(ui$1.Statistic,{label:"TP trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(lt,{content:r&&jsxRuntime.jsx(ui$1.Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxRuntime.jsx(ui$1.Text,{intensity:54,children:"TP PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},yo=e=>{let{sl_trigger_price:t,slPnL:r}=V();return jsxRuntime.jsx(ui$1.Statistic,{label:"SL trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(lt,{content:r&&jsxRuntime.jsx(ui$1.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsx(ui$1.Text,{intensity:54,children:"SL PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},bo=e=>jsxRuntime.jsx(ui$1.Statistic,{label:"TP price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"Market"})}),Po=e=>jsxRuntime.jsx(ui$1.Statistic,{label:"SL price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"Market"})}),So=e=>{let{item:t}=e,r=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:"Entire position"}):jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t]);return jsxRuntime.jsx(ui$1.Statistic,{label:"Quantity",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:r})},xo=e=>jsxRuntime.jsx(ui$1.Statistic,{label:jsxRuntime.jsxs(ui$1.Text,{children:["Avg price",jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:e.item?.average_executed_price??"--"})}),_o=e=>jsxRuntime.jsx(ui$1.Statistic,{label:jsxRuntime.jsxs(ui$1.Text,{children:["Order price",jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,placeholder:"Market",children:e.item?.price??"--"})}),Oo=e=>{let t=e?.item?.realized_pnl;return jsxRuntime.jsx(ui$1.Statistic,{label:jsxRuntime.jsxs(ui$1.Text,{children:["Real. PnL",jsxRuntime.jsx(ui$1.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsxs(ui$1.Flex,{gap:1,children:[jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"}),jsxRuntime.jsx(Qe,{order:e.item,sharePnLConfig:e.sharePnLConfig,modalId:uiShare.SharePnLBottomSheetId,iconSize:12})]})})},lt=e=>{let{classNames:t,content:r}=e,[n,o]=react.useState(false);return typeof r>"u"?e.children:jsxRuntime.jsx(ui$1.Tooltip,{content:r,className:t?.content,open:n,onOpenChange:o,arrow:{className:t?.arrow},children:jsxRuntime.jsx("div",{onClick:()=>o(i=>!i),children:e.children})})};var Wt=e=>{let {item:t}=e;t.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui$1.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:"Edit"})})};var To=e=>{let{side:t}=e.item,{price:r,quantity:n,triggerPrice:o,isAlgoOrder:i}=e,a=t===types.OrderSide.BUY;return jsxRuntime.jsxs("div",{className:"oui-pt-2",children:[jsxRuntime.jsx(ui$1.Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxRuntime.jsxs(ui$1.Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsxRuntime.jsx(ui$1.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,children:e.item.symbol}),jsxRuntime.jsxs(ui$1.Flex,{direction:"row",gap:1,children:[ae(e.item)?.map((s,d)=>jsxRuntime.jsx(ui$1.Badge,{color:s.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:s},d)),a&&jsxRuntime.jsx(ui$1.Badge,{color:"success",size:"xs",children:"Buy"}),!a&&jsxRuntime.jsx(ui$1.Badge,{color:"danger",size:"xs",children:"Sell"})]})]}),jsxRuntime.jsx(ui$1.Divider,{}),jsxRuntime.jsxs(ui$1.Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[i&&jsxRuntime.jsxs(ui$1.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui$1.Text,{children:"Trigger price"}),jsxRuntime.jsx(ui$1.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui$1.Text,{intensity:54,children:" USDC"}),children:o??"--"})]}),jsxRuntime.jsxs(ui$1.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui$1.Text,{children:"Price"}),jsxRuntime.jsx(ui$1.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui$1.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?"Market":"--",children:e.isStopMarket?"Market":r??"--"})]}),jsxRuntime.jsxs(ui$1.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui$1.Text,{children:"Qty."}),jsxRuntime.jsx(ui$1.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,children:n??"--"})]})]}),jsxRuntime.jsxs(ui$1.Flex,{className:"oui-gap-[2px]",children:[jsxRuntime.jsx(ui$1.Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:s=>{e.setOrderConfirm(!s);}}),jsxRuntime.jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:"Disable order confirmation"})]})]})};var Ht=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,n=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,o=i=>{let a=e.baseTick;if(a&&a>0){let s=hooks.utils.formatNumber(i,a)??i;e.setQuantity(s);}};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui$1.Flex,{direction:"column",gap:3,width:"100%",itemAlign:"start",className:"oui-text-sm",children:[jsxRuntime.jsxs(ui$1.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui$1.Text.formatted,{rule:"symbol",showIcon:true,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui$1.Flex,{direction:"row",gap:1,children:[ae(e.item)?.map((i,a)=>jsxRuntime.jsx(ui$1.Badge,{color:i.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:i},a)),r&&jsxRuntime.jsx(ui$1.Badge,{color:"success",size:"xs",children:"Buy"}),!r&&jsxRuntime.jsx(ui$1.Badge,{color:"danger",size:"xs",children:"Sell"})]})]}),jsxRuntime.jsx(ui$1.Divider,{intensity:8,className:"oui-w-full"}),jsxRuntime.jsxs(ui$1.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui$1.Text,{children:"Last price"}),jsxRuntime.jsx(ui$1.Text.numeral,{dp:e.item?.symbolInfo?.duote_dp,children:e.curMarkPrice??"--"})]}),jsxRuntime.jsxs(ui$1.Flex,{width:"100%",direction:"column",itemAlign:"stretch",gap:2,children:[e.isAlgoOrder&&jsxRuntime.jsx(ui$1.Input.tooltip,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:"Trigger price"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.trigger_price?.message?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui$1.inputFormatter.numberFormatter,ui$1.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:i=>e.setTriggerPrice(i),tooltip:e.errors?.trigger_price?.message,tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98 oui-w-full",root:ui$1.cn("oui-outline-line-12",e.errors?.trigger_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui$1.Input.tooltip,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:"Price"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.order_price?.message?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui$1.inputFormatter.numberFormatter,ui$1.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?"Market":e.price,onValueChange:i=>e.setPrice(i),tooltip:e.errors?.order_price?.message,tooltipProps:{content:{className:"oui-bg-base-5"},arrow:{className:"oui-fill-base-5"}},classNames:{input:"oui-text-base-contrast-98",root:ui$1.cn("oui-outline-line-12",e.errors?.order_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui$1.Input.tooltip,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:"Quantity"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:e.errors?.order_quantity?.message?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui$1.inputFormatter.numberFormatter,ui$1.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:i=>{e.setQuantity(i);},onBlur:i=>o(i.target.value),tooltip:e.errors?.order_quantity?.message,tooltipProps:{content:{className:"oui-bg-base-6"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98",root:ui$1.cn("oui-outline-line-12",e.errors?.order_quantity?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui$1.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:i=>{e.setSliderValue(i[0]);},color:"primary"}),jsxRuntime.jsxs(ui$1.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui$1.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:false,rule:"percentages",children:`${n??0}`}),jsxRuntime.jsxs(ui$1.Flex,{gap:1,children:[jsxRuntime.jsx(ui$1.Text,{size:"2xs",color:"primary",children:"Max"}),jsxRuntime.jsx(ui$1.Text.numeral,{intensity:54,size:"2xs",dp:e.base_dp,children:e.maxQty})]})]})]}),jsxRuntime.jsxs(ui$1.Flex,{width:"100%",gap:3,mt:2,children:[jsxRuntime.jsx(ui$1.Button,{fullWidth:true,color:"secondary",onClick:i=>{e.onClose();},children:"Cancel"}),jsxRuntime.jsx(ui$1.ThrottledButton,{fullWidth:true,onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:"Confirm"})]})]}),jsxRuntime.jsx(ui$1.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:"Edit order",size:"xs",actions:{primary:{label:"Confirm",onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:true},secondary:{label:"Cancel",onClick:e.onCloseDialog,fullWidth:true}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(To,{...e})})]})};var Jt=e=>{let {state:t,editAlgoOrder:r,editOrder:n,autoCheckInput:o=true,position:i}=e,{item:a}=t,{hide:s}=ui$1.useModal(),[d,l]=react.useState(false),P=a?.algo_order_id!==void 0&&a.algo_type!==types.AlgoOrderRootType.BRACKET,u=a?.type==="MARKET"&&P;u||a?.type==="MARKET";let [L,_]=react.useState(false),I=react.useMemo(()=>P&&a.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${a.type}`:a.type,[a,P]),[S,N]=hooks.useLocalStorage("orderly_order_confirm",true),{base_dp:v,base_tick:k}=e.state,{formattedOrder:m,setValue:F,markPrice:U,errors:p,validate:h,maxQty:D}=ca({order:a,orderType:I,position:i}),ce=()=>{h().then(g=>{S?l(true):G(m);},g=>{g?.total?.message&&ui$1.toast.error(g?.total.message);}).catch(g=>{});},w=react.useCallback(()=>{l(false);},[]),O=()=>m?G(m):Promise.reject(),E=react.useCallback(()=>{s();},[]),G=react.useCallback(async g=>{let $,pt=a.visible_quantity!==void 0?a.visible_quantity===0:a.visible!==void 0?a.visible===0:false;if(a.algo_order_id!==void 0){if(u&&"order_price"in g){let{order_price:Le,...gt}=g;g=gt;}$=r(a.algo_order_id.toString(),{...g});}else $=n(a.order_id.toString(),{...g,...pt?{visible_quantity:0}:{}});try{_(!0);let Le=await $;E();}catch(Le){ui$1.toast.error(Le?.message??`${Le}`);}finally{_(false);}},[r,n]),ie=react.useMemo(()=>{let g=m.order_quantity;return g&&Number(g)!==0&&D!==0?new utils.Decimal(g).div(D).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[m.order_quantity,D]),Te=a.price!=m.order_price||a.quantity!=m.order_quantity||a.trigger_price!=m.trigger_price,f=hooks.useThrottledCallback(g=>{let $=new utils.Decimal(g).div(100).mul(D).toDecimalPlaces(v,utils.Decimal.ROUND_DOWN).toNumber();F("order_quantity",hooks.utils.formatNumber($,k));},50,{}),q=(g,$)=>{F(g,$);};return {...t,curMarkPrice:U,isAlgoOrder:P,isStopMarket:u,price:m.order_price,setPrice:g=>q("order_price",g),priceEdit:!u,triggerPrice:m.trigger_price,setTriggerPrice:g=>q("trigger_price",g),quantity:m.order_quantity,setQuantity:g=>{q("order_quantity",g);},maxQty:D,sliderValue:ie,setSliderValue:f,onClose:E,onSheetConfirm:ce,errors:p,orderType:I,isChanged:Te,baseTick:k,dialogOpen:d,setDialogOpen:l,onDialogConfirm:O,onCloseDialog:w,submitting:L,orderConfirm:S,setOrderConfirm:N}},ca=e=>{let{order:t,orderType:r,position:n}=e,[o,i]=react.useState({side:t.side,order_type:r,order_price:t.price,order_quantity:t.quantity,trigger_price:t.trigger_price,reduce_only:t.reduce_only,symbol:t.symbol}),{reduce_only:a}=t,s=n?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),l=react.useMemo(()=>a?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,a,s]),{symbolInfo:P,markPrice:u,errors:x,validate:L}=hooks.useOrderEntity({...o,symbol:t.symbol},{maxQty:l});return {symbolInfo:P,markPrice:u,errors:x,validate:L,setValue:(I,S)=>{i(N=>({...N,[I]:S}));},formattedOrder:o,maxQty:l}};var Xt=e=>{let t=Jt(e);return jsxRuntime.jsx(Ht,{...t})};var Zt=e=>{let{state:t}=e,{editAlgoOrder:r,editOrder:n}=J(),{order:o,position:i}=V(),a=react.useCallback(()=>{e.state.type==="tp_sl"?ui$1.modal.sheet({title:"TP/SL",content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:true,order:e.state.item,position:i,symbolInfo:e.state.origin})}).catch(s=>{}):ui$1.modal.sheet({title:"Edit order",classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(Xt,{position:i,state:t,editAlgoOrder:r,editOrder:n})}).catch(s=>{});},[t]);return {...t,onShowEditSheet:a}};var jt=e=>{let t=Zt(e);return jsxRuntime.jsx(Wt,{...t})};var tr=e=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui$1.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:t=>e.setOpen(true),children:"Cancel"}),e.open&&jsxRuntime.jsx(ui$1.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:"Cancel order",actions:{primary:{label:"Confirm",loading:e.isLoading,fullWidth:true,size:"md",onClick:t=>{e.onCancel(t);}},secondary:{label:"Cancel",fullWidth:true,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui$1.Text,{size:"2xs",intensity:54,children:"Are you sure you want to cancel your pending order."})})]});var rr=e=>{let{state:t}=e,[r,n]=react.useState(false),{onCancelOrder:o}=J(),[i,a]=react.useState(false);return {...t,open:r,setOpen:n,onCancel:l=>o?(l?.preventDefault(),l?.stopPropagation(),a(true),o(t.item).then(P=>{n(false);},P=>{ui$1.toast.error(P.message);}).finally(()=>{a(false);})):Promise.resolve(),onClose:()=>{n(false);},isLoading:i}};var or=e=>{let t=rr(e);return jsxRuntime.jsx(tr,{...t})};var ar=e=>!e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(lt,{classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},content:jsxRuntime.jsxs(ui$1.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof e.pnl?.tpPnL<"u"&&jsxRuntime.jsx(ui$1.Text.numeral,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:true,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui$1.Text.numeral,{prefix:jsxRuntime.jsx(ui$1.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui$1.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"sell",children:e.pnl?.slPnL})]}),children:jsxRuntime.jsx("button",{onClick:()=>{e.setOpen(!e.open);},children:jsxRuntime.jsxs(ui$1.Flex,{gap:1,width:"1",children:[e.tp_trigger_price&&jsxRuntime.jsx(Ao,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Ao,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})}),Ao=e=>{let{type:t,value:r,quote_dp:n}=e;return r?jsxRuntime.jsx(ui$1.Text.numeral,{size:"2xs",className:ui$1.cn("oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:n,padding:false,rm:utils.Decimal.ROUND_DOWN,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-36",children:[`${t} `,":\xA0\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var sr=e=>{let{item:t,quote_dp:r,base_dp:n}=e,[o,i]=react.useState(false),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:d,roi:l}=et(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:d,roi:l,quote_dp:r,open:o,setOpen:i}};var lr=e=>{let t=sr(e);return jsxRuntime.jsx(ar,{...t})};var dr=e=>jsxRuntime.jsxs(ui$1.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(Ea,{...e}),jsxRuntime.jsx(ui$1.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(va,{...e}),e.type==="pending"&&jsxRuntime.jsx(lr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(Aa,{...e})]}),Ea=e=>jsxRuntime.jsxs(ui$1.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui$1.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(so,{...e}),jsxRuntime.jsx(uo,{...e})]}),jsxRuntime.jsxs(ui$1.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(lo,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(co,{...e})]})]}),va=e=>jsxRuntime.jsx(ui$1.Grid,{cols:3,rows:2,width:"100%",gap:1,children:Da(e)}),Aa=e=>jsxRuntime.jsxs(ui$1.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(jt,{state:e}),jsxRuntime.jsx(or,{state:e})]});function Da(e){switch(e.type){case "all":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "pending":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Rt,{...e}),jsxRuntime.jsx(Bt,{...e}),jsxRuntime.jsx(mo,{...e}),jsxRuntime.jsx(Mt,{...e}),jsxRuntime.jsx(po,{...e}),jsxRuntime.jsx(fo,{...e})]});case "tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(go,{...e}),jsxRuntime.jsx(bo,{...e}),jsxRuntime.jsx(So,{...e}),jsxRuntime.jsx(yo,{...e}),jsxRuntime.jsx(Po,{...e})]});case "filled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "cancelled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "rejected":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "orderHistory":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Rt,{...e}),jsxRuntime.jsx(Bt,{...e}),jsxRuntime.jsx(Mt,{...e,align:"end"}),jsxRuntime.jsx(xo,{...e}),jsxRuntime.jsx(_o,{...e}),jsxRuntime.jsx(Oo,{...e})]})}}var ur=e=>{let t=M();return {...e,...t}};var cr=e=>{let{className:t,...r}=e,n=ur(r);return jsxRuntime.jsx(dr,{...n,className:t})};var mr=e=>{let{sharePnLConfig:t,...r}=e,n=ro({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:t,symbolsInfo:e.symbolsInfo});return jsxRuntime.jsx(xt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui$1.Flex,{direction:"column",width:"100%",height:"100%",itemAlign:"start",children:[e.filterItems.length>0&&jsxRuntime.jsx(ui$1.DataFilter,{items:e.filterItems,onFilter:o=>{e.onFilter(o);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx($a,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:n,loading:e.isLoading,dataSource:e.dataSource,bordered:true,ignoreLoadingCheck:true,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(o,i)=>({className:ui$1.cn("oui-h-[48px]",ee(o)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(o,i)=>`${e.type}${i}${o.order_id||o.algo_order_id}_index${i}`,renderRowContainer:(o,i,a)=>((e.type==="tp_sl"||e.type==="pending")&&(a=jsxRuntime.jsx(Ot,{order:o,children:a})),jsxRuntime.jsx(Pt,{symbol:o.symbol,children:a})),pagination:e.pagination,manualPagination:e.manualPagination,features:[ui$1.TableFeatures.DownloadFeature],getTableInstance:o=>{e.tableInstance.current=o;}})]})})},fr=e=>jsxRuntime.jsx(xt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui$1.Grid,{cols:1,rows:2,className:"oui-grid-rows-[auto,1fr] oui-w-full",gap:2,children:[e.showFilter?jsxRuntime.jsx(ui$1.Flex,{gap:2,p:2,className:"oui-bg-base-9 oui-rounded-b-xl",children:e.filterItems.map(t=>t.type!=="select"?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ui$1.Picker,{options:t.options,size:"sm",value:t.value,className:"oui-text-2xs oui-text-base-contrast-54 ",placeholder:t.name==="side"?"All sides":t.name==="status"?"All status":"",onValueChange:r=>{e.onFilter?.({name:t.name,value:r});}}))}):jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ui$1.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(t,r)=>{let n=jsxRuntime.jsx(cr,{item:t,index:r,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange,sharePnLConfig:e.sharePnLConfig});return ["tp_sl","pending"].includes(e.type)&&(n=jsxRuntime.jsx(Ot,{order:t,children:n})),jsxRuntime.jsx(Pt,{symbol:t.symbol,children:n})}})]})}),$a=e=>jsxRuntime.jsx(ui$1.Button,{variant:"outlined",color:"secondary",size:"xs",disabled:(e.dataSource?.length??0)==0,className:"disabled:oui-bg-transport",onClick:t=>e.onCancelAll(),"data-testid":`oui-testid-dataList-${e.type.toLowerCase()}-cancelAll-button`,children:"Cancel all"});var Ro=e=>react.useMemo(()=>{let r=[];for(let n=0;n<e.length;n++){let o=e[n];if(o.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||o.algo_type===types.AlgoOrderRootType.TP_SL)if(o.algo_status!==types.OrderStatus.FILLED&&o.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let i=0;i<o.child_orders.length;i++){let a=o.child_orders[i];!a.is_activated||!a.trigger_price||(a.parent_algo_type=o.algo_type,r.push(a));}else for(let i=0;i<o.child_orders.length;i++){let a=o.child_orders[i];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=o.algo_type,r.push(a));}else r.push(o);}return r},[e]);var ft=e=>{let{ordersStatus:t,type:r,enableLoadMore:n=false,onSymbolChange:o,filterConfig:i,pnlNotionalDecimalPrecision:a,sharePnLConfig:s}=e,d=hooks.useSymbolsInfo(),l=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),P=50,{page:u,pageSize:x,setPage:L,pagination:_,parsePagination:I}=ui$1.usePagination({pageSize:P});react.useEffect(()=>{L(1);},[e.symbol]);let{orderStatus:S,ordersSide:N,dateRange:v,filterItems:k,onFilter:m}=ns(r,{ordersStatus:t,setPage:L,filterConfig:i}),F=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),A=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),U=react.useRef();react.useImperativeHandle(e.ref,()=>({download:()=>{let yt=`orders_${dateFns.format(new Date,"yyyyMMdd_HHmmss")}`;U.current?.download(yt);}}));let[p,{isLoading:h,loadMore:D,cancelOrder:ce,updateOrder:w,cancelAlgoOrder:O,updateAlgoOrder:E,cancelAllOrders:G,cancelAllTPSLOrders:ie,meta:Te,refresh:f}]=hooks.useOrderStream({symbol:e.symbol,status:S,side:N,page:n||!l?void 0:u,size:l?x:500,dateRange:v,includes:F,excludes:A}),q=`orderly_${r}_pageSize`,[g,$]=hooks.useLocalStorage(q,P);react.useEffect(()=>{g!==x&&$(x);},[x,g]);let pt=react.useCallback(()=>{let yt=e.type==="pending"?"Cancel all pending orders":e.type==="tp_sl"?"Cancel all TP/SL orders":"",Qo="Are you sure you want to cancel all of your pending orders?";ui$1.modal.confirm({title:yt,content:jsxRuntime.jsx(ui$1.Text,{size:"sm",children:Qo}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await ie():await G(),f(),Promise.resolve(!0)}catch(gr){return gr?.message!==void 0&&toast.error(gr.message),Promise.resolve(false)}finally{Promise.resolve();}}});},[r]),Le=Ro(p??[]),gt=reactApp.useDataTap(r!=="tp_sl"?Le:p,{fallbackData:[]})??void 0,$o=react.useMemo(()=>l?I(Te):_,[Te,l,I,_]);return {type:r,dataSource:gt,isLoading:h,loadMore:D,cancelOrder:ce,updateOrder:w,cancelAlgoOrder:O,updateAlgoOrder:E,pagination:$o,manualPagination:l,pnlNotionalDecimalPrecision:a,onFilter:m,filterItems:k,onCancelAll:pt,onSymbolChange:o,sharePnLConfig:s,tableInstance:U,symbolsInfo:d}},ns=(e,t)=>{let[r,n]=react.useState(t.ordersStatus??"all"),[o,i]=react.useState(t.filterConfig?.side??"all"),a=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Mo({to:new Date,from:Wo(dateFns.subDays(new Date,7))}):{}),[s,d]=react.useState(a),l=u=>{u.name==="side"&&(i(u.value),t.setPage(1)),u.name==="status"&&(n(u.value),t.setPage(1)),u.name==="dateRange"&&(d(Mo(u.value)),t.setPage(1));};return {filterItems:react.useMemo(()=>{let u={type:"select",name:"side",options:[{label:"All sides",value:"all"},{label:"Buy",value:"BUY"},{label:"Sell",value:"SELL"}],value:o},x={type:"range",name:"dateRange",value:s},L={type:"select",name:"status",options:[{label:"All status",value:"all"},{label:"Pending",value:types.OrderStatus.INCOMPLETE},{label:"Filled",value:types.OrderStatus.FILLED},{label:"Partial filled",value:types.OrderStatus.PARTIAL_FILLED},{label:"Canceled",value:types.OrderStatus.CANCELLED},{label:"Rejected",value:types.OrderStatus.REJECTED}],value:r};switch(e){case "all":return [u,L,x];case "pending":return [u];case "tp_sl":return [u];case "filled":return [u];case "cancelled":return [u];case "rejected":return [u];case "orderHistory":return [u,L,x]}},[e,o,r,s]),onFilter:l,ordersSide:o==="all"?void 0:o,dateRange:s,orderStatus:r==="all"?void 0:r}};function is(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Wo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Mo=e=>({from:is(e.from),to:Wo(e.to??e.from)});var Pe=react.forwardRef((e,t)=>{let{testIds:r,...n}=e,o=ft({...n,ref:t});return jsxRuntime.jsx(mr,{...o,testIds:r})}),ls=e=>{let t=ft({...e,enableLoadMore:true});return jsxRuntime.jsx(fr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Uo=e=>{let t={pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision};return jsxRuntime.jsxs(ui$1.Tabs,{defaultValue:e.current||"all",variant:"contained",className:"oui-h-full",classNames:{tabsContent:"oui-h-[calc(100%_-_28px)]"},children:[jsxRuntime.jsx(ui$1.TabPanel,{value:"all",title:"All",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...t})}),jsxRuntime.jsx(ui$1.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,...t})}),jsxRuntime.jsx(ui$1.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,...t})}),jsxRuntime.jsx(ui$1.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...t})}),jsxRuntime.jsx(ui$1.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,...t})}),jsxRuntime.jsx(ui$1.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(Pe,{ref:e.orderListRef,type:"rejected",ordersStatus:types.OrderStatus.REJECTED,...t})})]})};var pe=(s=>(s.all="all",s.pending="pending",s.tp_sl="tp_sl",s.filled="filled",s.cancelled="cancelled",s.rejected="rejected",s.orderHistory="orderHistory",s))(pe||{}),ms=react.forwardRef((e,t)=>{let r=bt({...e,ref:t});return jsxRuntime.jsx(Uo,{...r})});
16
+ var Ct=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:o}=e,n=react.useRef(null);return react.useImperativeHandle(e.ref,()=>({download:()=>{n.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:n,sharePnLConfig:o}};var Te=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ue(e){let t=e.type,r=e.algo_type;if(typeof t<"u"){let o=[];if(e.parent_algo_type){if(r===types.AlgoOrderType.STOP_LOSS){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.sl")]:[i18n.i18n.t("tpsl.sl")];o.push(...i);}if(r===types.AlgoOrderType.TAKE_PROFIT){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.tp")]:[i18n.i18n.t("tpsl.tp")];o.push(...i);}return o}let n=typeof t=="string"?t.replace("_ORDER",""):"";if([types.OrderType.ASK,types.OrderType.BID].includes(t))return [i18n.i18n.t("orderEntry.orderType.limit")];if(e.algo_order_id===void 0||e.algo_order_id&&r==="BRACKET")return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.limit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.market"),[types.OrderType.POST_ONLY]:i18n.i18n.t("orderEntry.orderType.postOnly"),[types.OrderType.IOC]:i18n.i18n.t("orderEntry.orderType.ioc"),[types.OrderType.FOK]:i18n.i18n.t("orderEntry.orderType.fok")}[n]||Te(n)];if(n)return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.stopLimit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.stopMarket")}[n]||n]}if(typeof r<"u"){let o=[];r===types.AlgoOrderRootType.POSITIONAL_TP_SL&&o.push(i18n.i18n.t("common.position"));let n=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!a.trigger_price),i=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.STOP_LOSS&&!!a.trigger_price);return (n||i)&&o.push(n&&i?i18n.i18n.t("common.tpsl"):n?i18n.i18n.t("tpsl.tp"):i18n.i18n.t("tpsl.sl")),o}}function ne(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function ln(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function lt(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=ln(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let n=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=i?hooks.utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:d}}}var Cr=react.createContext({}),W=()=>react.useContext(Cr),Tt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(Cr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var Lr=react.createContext({}),X=()=>react.useContext(Lr),Nt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:n}=e,{t:i}=i18n.useTranslation(),a=hooks.useSymbolsInfo(),s=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),d=react.useCallback(async(l,b)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:false;await ui.modal.sheet({title:i("orders.editOrder"),classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[i]),u=react.useCallback((l,b,m)=>{let{min_notional:O}=a[l](),_=hooks.getMinNotional({price:b,qty:m,min_notional:O});if(_!==void 0)return i("orderEntry.total.error.min",{value:_})},[a,i]);return jsxRuntime.jsx(Lr.Provider,{value:{onCancelOrder:s,onEditOrder:d,editOrder:r,editAlgoOrder:n,checkMinNotional:u},children:e.children})};var Ir=react.createContext({}),G=()=>react.useContext(Ir),It=e=>{let{quote_dp:t}=W(),[r,o]=react.useState(),[n]=hooks.useMutation("/v1/algo/order","DELETE"),[i]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),u=async h=>n(null,{order_id:h.algo_order_id,symbol:h.symbol}),l=async(h,F)=>i({order_id:h.algo_order_id,child_orders:h.child_orders.map(T=>({order_id:T.algo_order_id,quantity:F.order_quantity}))}),b=h=>a.cache.get(d)?.data.rows.find(T=>T.symbol===h),{sl_trigger_price:m,tp_trigger_price:O,tpPnL:_,slPnL:I}=wn({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??false)){let h=b(e.order.symbol);h&&o(h);}},[e.order.symbol]),jsxRuntime.jsx(Ir.Provider,{value:{order:e.order,sl_trigger_price:m,tp_trigger_price:O,tpPnL:_,slPnL:I,onCancelOrder:u,onUpdateOrder:l,getRelatedPosition:b,position:r},children:e.children})};function wn(e){let{order:t,position:r,quote_dp:o}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:n,tp_trigger_price:i}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,u=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:n,tp_trigger_price:i,slPnL:u,tpPnL:d}}var qe=e=>{let{type:t,base:r,value:o,cancelPopover:n,isSubmitting:i,onConfirm:a}=e,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsx("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:(()=>{let u={values:{base:r,value:utils.commify(o)},components:[jsxRuntime.jsx("span",{className:"oui-text-warning-darken"})]};switch(t){case 0:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.quantity",...u});case 1:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.price",...u});case 2:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.triggerPrice",...u})}})()}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:n,disabled:i,children:s("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:i,onClick:a,children:s("common.confirm")})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:n,children:jsxRuntime.jsx(ui.CloseIcon,{size:16,color:"white",opacity:1})})]})};var Re=e=>{let{inputRef:t,dp:r,value:o,setValue:n,setEditing:i,error:a,handleKeyDown:s,onClick:d,onClose:u,onFocus:l,onBlur:b,hintInfo:m}=e;react.useEffect(()=>{let _=t.current;if(_){let I=_.value.length;_.setSelectionRange(I,I);}i(true);},[]);let O=(m?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:m,open:O,children:jsxRuntime.jsx(ui.Input,{ref:t,type:"text",size:"sm",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(r),ui.inputFormatter.currencyFormatter],value:o,onValueChange:_=>n(_),helpText:a,onClick:_=>{_.stopPropagation(),_.preventDefault();},autoComplete:"off",onFocus:l,onBlur:b,onKeyDown:s,autoFocus:true,color:O?"danger":void 0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsxRuntime.jsx("button",{onClick:d,children:jsxRuntime.jsx(ui.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Ft=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[n,i]=react.useState(t.quantity.toString()),[a,s]=react.useState(false),{t:d}=i18n.useTranslation();react.useEffect(()=>{w(t.quantity.toString());},[e.order.quantity]);let[u,l]=react.useState(false),[b,m]=react.useState(),{editOrder:O,editAlgoOrder:_,checkMinNotional:I}=X(),{onUpdateOrder:h,position:F}=G(),{base_dp:T,base:V,base_tick:f}=W(),w=async(g,y)=>{i(g);let k=Math.abs(F?.position_qty||0);if(F&&o&&Number(g)>k)m(d("orders.quantity.lessThanPosition",{quantity:k}));else {let Ce=Number(g);y&&Ce>y?m(d("orders.quantity.lessThan",{quantity:utils.commifyOptional(y,{fix:T})})):m(void 0);}return Promise.resolve()},M=()=>{l(false),s(false);},R=()=>{l(false),w(t.quantity.toString()),s(false);},[x,C]=react.useState(false),D=react.useRef(null),te=()=>{if(b)return;if(Number(n)===Number(t.quantity)){s(false);return}let g=t.algo_order_id!==void 0?t.trigger_price:t.price;if(g!==null&&t.reduce_only!==true){let y=I(t.symbol,g,n);if(y){ui.toast.error(y),C(false),R();return}}l(true);},E=g=>{g?.stopPropagation(),g?.preventDefault(),te();},Y=g=>{g.key==="Enter"&&(g?.stopPropagation(),g?.preventDefault(),te());},v=react.useCallback(()=>{C(true);let g={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:n,algo_order_id:t.algo_order_id};if(typeof g.algo_order_id<"u"&&g.order_type==="MARKET"){let{order_price:k,...Ce}=g;g=Ce;}typeof t.reduce_only<"u"&&(g.reduce_only=t.reduce_only),t.order_tag!==void 0&&(g={...g,order_tag:t.order_tag}),t?.visible_quantity===0&&(g.visible_quantity=0),t?.tag!==void 0&&(g.order_tag=t.tag);let y;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?y=h(t,g):t.algo_order_id!==void 0?y=_(t.algo_order_id.toString(),g):y=O(t.order_id.toString(),g),y.then(k=>{M(),w(n.toString());},k=>{ui.toast.error(k.message),w(t.quantity.toString()),R();}).finally(()=>C(false));},[n]),A=react.useRef(null),re=react.useRef(null),de=g=>{A.current&&re.current&&!A.current.contains(g.target)&&!re.current.contains(g.target)&&!u&&R();};react.useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[u,t.quantity]);let De=()=>!a||e.disableEdit?jsxRuntime.jsx(Gn,{order:t,quantity:n,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(Jn,{inputRef:D,quantitySliderRef:re,base_dp:T,base_tick:f,quantity:n,setQuantity:w,editing:a,setEditing:s,handleKeyDown:Y,onClick:E,onClose:R,symbol:t.symbol,reduce_only:o,positionQty:F?.position_qty,error:b,confirmOpen:u,side:t.side,order:t,setError:m});return jsxRuntime.jsx(ui.Popover,{open:u,onOpenChange:l,content:jsxRuntime.jsx(qe,{type:0,base:V,value:n,cancelPopover:R,isSubmitting:x,onConfirm:v}),contentProps:{onOpenAutoFocus:g=>{}},children:jsxRuntime.jsx("div",{onClick:g=>{g.stopPropagation(),g.preventDefault();},ref:A,children:De()})})},Gn=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",ne(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})},Jn=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:n,quantity:i,setQuantity:a,editing:s,setEditing:d,handleKeyDown:u,onClick:l,onClose:b,error:m,symbol:O,reduce_only:_,positionQty:I,confirmOpen:h,side:F,order:T}=e,V=hooks.useMaxQty(O,T.side,T.reduce_only),f=react.useMemo(()=>_?Math.abs(I??0):T.quantity+Math.abs(V),[T.quantity,V,_,I]),[w,M]=react.useState(void 0);react.useEffect(()=>{if(w===void 0){let x=new utils.Decimal(i).div(f).abs().mul(100).toNumber();M(x);}},[w,f,i]);let R=async x=>(n>0&&(x=hooks.utils.formatNumber(x,n)??x),a(`${x}`,f));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!h,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(Re,{inputRef:t,dp:o,value:i,setValue:x=>{let C=Math.abs(Math.min(Number(x),f)).toString();if(a(x,f),x.endsWith("."))return;if(Number(C)===0){M(0);return}let D=new utils.Decimal(x).div(f).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();M(Math.min(100,D));},setEditing:d,handleKeyDown:u,onClick:l,onClose:b,onBlur:x=>{R(x.target.value);},hintInfo:m})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:x=>{x.preventDefault();},children:jsxRuntime.jsxs(ui.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${w}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[w??0],onValueChange:x=>{let C=Array.from(x.values());M(C[0]);let D=new utils.Decimal(C[0]).div(100).mul(f).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(D,f);},onValueCommit:x=>{let C=new utils.Decimal(x[0]).div(100).mul(f).abs().toFixed(o,utils.Decimal.ROUND_DOWN);R(C).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Xn,{onClick:x=>{M(x*100);let C=new utils.Decimal(x).mul(f).abs().toFixed(o,utils.Decimal.ROUND_DOWN);C=hooks.utils.formatNumber(C,n)??C,a(C,f),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(C.length,C.length);},100);}})]})]})})]})},Xn=e=>{let{t}=i18n.useTranslation(),r=[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:t("common.max"),value:1}];return jsxRuntime.jsx(ui.Flex,{gap:2,width:"100%",children:r.map((o,n)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(o.value);},className:"oui-w-1/5",children:o.label},n))})};var Ur=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),[o,n]=react.useState(()=>t.type===types.OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[i,a]=react.useState(false),[s,d]=react.useState(false),u=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&u,[b,m]=react.useState(false),{editOrder:O,editAlgoOrder:_,checkMinNotional:I}=X(),{base:h,quote_dp:F}=W(),T=hooks.useSymbolPriceRange(t.symbol,t.side,u?t.trigger_price:void 0),V=()=>{a(false),d(false);},f=()=>{a(false),n(t.price?.toString()??"Market"),d(false);},w=react.useMemo(()=>!T||l||!s?"":Number(o)>T.max?r("orders.price.greaterThan",{max:T.max}):Number(o)<T.min?r("orders.price.lessThan",{min:T.min}):"",[l,s,T,o,r]),M=v=>{if(v?.stopPropagation(),v?.preventDefault(),!(w.length>0)){if(o===`${t.price}`){d(false);return}if(t.reduce_only!==true){let A=I(t.symbol,o,t.quantity);if(A){ui.toast.error(A),m(false),f();return}}a(true);}},R=v=>{v.key==="Enter"&&M(v);},x=()=>{m(true);let v=t.order_id,A={order_price:o,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(A.reduce_only=t.reduce_only),t.order_tag!==void 0&&(A={...A,order_tag:t.order_tag}),u&&(v=t.algo_order_id,A={...A,order_id:v,price:o,algo_order_id:v}),t?.visible_quantity===0&&(A.visible_quantity=0),t.tag!==void 0&&(A.order_tag=t.tag);let re;t.algo_order_id!==void 0?re=_(t.algo_order_id.toString(),A):re=O(t.order_id.toString(),A),re.then(de=>{V(),n(o);},de=>{ui.toast.error(de.message),f();}).finally(()=>m(false));},C=react.useRef(null);react.useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let D=react.useRef(null),te=v=>{D.current&&!D.current.contains(v.target)&&!i&&f();};if(react.useEffect(()=>(document.addEventListener("mousedown",te),()=>{document.removeEventListener("mousedown",te);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||o==="Market")return jsxRuntime.jsx("span",{children:r("common.marketPrice")});let Y=()=>!s||e.disableEdit?jsxRuntime.jsx(si,{order:t,price:o,setEditing:d,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:C,dp:F,value:o,setValue:n,setEditing:d,handleKeyDown:R,onClick:M,onClose:f,hintInfo:w});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(qe,{type:1,base:h,value:o,cancelPopover:f,isSubmitting:b,onConfirm:x}),children:jsxRuntime.jsx("div",{onClick:v=>{v.stopPropagation(),v.preventDefault();},ref:D,children:Y()})})},si=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var Gr=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let n=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=react.useState(false),[d,u]=react.useState(false),[l,b]=react.useState(false),{editAlgoOrder:m,checkMinNotional:O}=X(),{base:_,quote_dp:I,quote_max:h,quote_min:F}=W(),T=react.useMemo(()=>{if(!((!n||i)&&!d)){if(Number(r)>h)return `Trigger price must be less than ${h}`;if(Number(r)<F)return `Trigger price must be greater than ${F}`}},[d,r,n,i]),V=()=>{s(false),u(false);},f=()=>{o(t.trigger_price?.toString()??"0"),s(false),u(false);},w=react.useRef(null),M=E=>{w.current&&!w.current.contains(E.target)&&!a&&f();};react.useEffect(()=>(document.addEventListener("mousedown",M),()=>{document.removeEventListener("mousedown",M);}),[a,t.trigger_price]);let R=E=>{if(E?.stopPropagation(),E?.preventDefault(),u(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let Y=O(t.symbol,t.price,t.quantity);if(Y){ui.toast.error(Y),b(false),f();return}}s(true);}},x=E=>{E.key==="Enter"&&R(E);},C=()=>{if((T??"").length>0)return;b(true);let E={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),m(`${t.algo_order_id}`,E).then(Y=>{V(),o(r);},Y=>{ui.toast.error(Y.message),o(t.trigger_price?.toString()??"--"),f();}).finally(()=>b(false));},D=react.useRef(null);if(!n||i)return jsxRuntime.jsx(ui.Text,{children:"--"});let te=()=>!d||e.disableEdit?jsxRuntime.jsx(ci,{order:t,price:r,setEditing:u,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:D,dp:I,value:r,setValue:o,setEditing:u,handleKeyDown:x,onClick:R,onClose:f,hintInfo:T});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(qe,{type:2,base:_,value:r,cancelPopover:f,isSubmitting:l,onConfirm:C}),children:jsxRuntime.jsx("div",{onClick:E=>{E.stopPropagation(),E.preventDefault();},ref:w,children:te()})})},ci=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var mt=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),{onCancelOrder:o}=X(),[n,i]=react.useState(false);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{o&&(a.preventDefault(),a.stopPropagation(),i(true),o(t).then(s=>s,s=>{ui.toast.error(s.message);}).finally(()=>{i(false);}));},loading:n,children:r("common.cancel")})};var Jr=e=>{let{record:t}=e,[r,o]=react.useState(false),[n,{data:i,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),{t:u}=i18n.useTranslation(),l=hooks.useConfig("brokerId"),b=react.useCallback(()=>{o(false);let m={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(m.visible_quantity=0),typeof t.reduce_only<"u"&&(m.reduce_only=t.reduce_only),n(m);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:m=>{d||(m.preventDefault(),m.stopPropagation(),b());},children:u("orders.history.renew")})};var eo=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=G();return jsxRuntime.jsx(Ni,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:true})},Ni=e=>{let{direction:t="row",order:r,position:o}=e,n=hooks.useSymbolsInfo(),{t:i}=i18n.useTranslation(),a=react.useMemo(()=>{let u=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&u.push(jsxRuntime.jsx(Zr,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:n[r.symbol]()},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(Zr,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:n[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:u})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),s=react.useMemo(()=>{let u=[];return r?.symbol?(e.takeProfitPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.tp")} -`,"\xA0"]}):""},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}):""},"sl")),u.length===0?jsxRuntime.jsx("span",{children:"-"}):(u.length===2&&t==="row"&&u.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),u)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol,i]),d=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:s});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:d}):d},Zr=e=>{let{qty:t,price:r,entryPrice:o,orderSide:n,orderType:i,symbolInfo:a}=e,{t:s}=i18n.useTranslation(),d=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:n,orderType:i},{symbol:a}),l=(i===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL")==="TP"?`${s("tpsl.tpPnl")}:`:`${s("tpsl.slPnl")}:`;return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:l}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:d===0?"oui-text-base-contrast-36":d>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:d===0?"":d>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(d)}`})]})};var no=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=W(),{t:n}=i18n.useTranslation(),{sl_trigger_price:i,tp_trigger_price:a}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:s,roi:d}=lt(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof s.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:s.tpPnL}),typeof s.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:s.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(ro,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(ro,{type:"SL",value:i,quote_dp:r})]})})},ro=e=>{let{type:t,value:r,quote_dp:o}=e,{t:n}=i18n.useTranslation();return r?jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[t==="TP"?`${n("tpsl.tp")} -`:`${n("tpsl.sl")} -`,"\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var io=e=>{let{position:t,order:r}=G(),{quote_dp:o,base_dp:n}=W(),{t:i}=i18n.useTranslation();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:n,position:t,order:r,label:i("common.edit"),isEditing:true})};var so=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=G(),{t:r}=i18n.useTranslation();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${r("tpsl.tp")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${r("tpsl.sl")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null]})};function lo(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:hooks.utils.findTPSLFromOrder(e),o=r?`${i18n.i18n.t("tpsl.tp")} - ${i18n.i18n.t("common.marketPrice")}`:void 0,n=t?`${i18n.i18n.t("tpsl.sl")} - ${i18n.i18n.t("common.marketPrice")}`:void 0;return {tpTriggerPrice:o,slTriggerPrice:n}}var Wt=e=>{let{t}=i18n.useTranslation();return e.sharePnLConfig==null?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),ui.modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?t("share.pnl.share.long"):t("share.pnl.share.short"),openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsxRuntime.jsx(ui.ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})})};var uo=e=>{let{sharePnLConfig:t,order:r,modalId:o,iconSize:n}=e,{getFirstRefCode:i}=hooks.useReferralInfo(),a=react.useMemo(()=>i()?.code,[i]),s=hooks.useSymbolLeverage(e.order.symbol);return {iconSize:n,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:o}};var Ze=e=>{let t=uo(e);return jsxRuntime.jsx(Wt,{...t})};var fo=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o,sharePnLConfig:n}=e,{t:i}=i18n.useTranslation();return react.useMemo(()=>{switch(t){case "all":return [Ne({width:130,showType:true,onSymbolChange:r,enableSort:false}),Me({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:130,title:i("orders.column.orderPrice"),disableEdit:true,enableSort:false}),ft({width:130,enableSort:false}),co({width:130,symbolsInfo:e.symbolsInfo}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:130,enableSort:false}),et({width:130}),tt({width:130}),we({width:130}),$e({width:130}),mo({width:130}),Ue({width:160,enableSort:false})];case "pending":return [Ne({width:172,showType:true,onSymbolChange:r,enableSort:false}),Me({width:162,className:"oui-pr-0",enableSort:false}),We({width:162,className:"oui-pr-0",enableSort:false}),je({width:162,className:"oui-pr-0"}),oa({width:130}),ze({width:162,isPending:true}),we({width:162}),$e({width:162}),Ue({width:162,enableSort:false}),ia({width:162})];case "tp_sl":return [Ne({width:176,showType:true,onSymbolChange:r,enableSort:false}),ea({width:176}),co({width:176,symbolsInfo:e.symbolsInfo}),ta({width:176}),na({width:176}),we({width:176}),Ue({width:176,enableSort:false}),aa({width:176})];case "filled":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,title:i("orders.column.orderPrice"),disableEdit:true}),ra({width:124}),je({width:124,disableEdit:true}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo,hideShare:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:176})];case "cancelled":return [Ne({showType:true,width:154,onSymbolChange:r,enableSort:false}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:124,disableEdit:true,enableSort:false}),ft({width:124,enableSort:false}),je({width:124,disableEdit:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124})];case "rejected":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,disableEdit:true}),ft({width:124}),je({width:124,disableEdit:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:176})];case "orderHistory":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),We({width:124,disableEdit:true}),ft({width:124}),je({width:124,disableEdit:true}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:150}),mo({width:80})]}},[t,o,n,i])};function Ne(e){return {title:i18n.i18n.t("common.symbol"),dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let o=ue(r)?.join(","),n=o?.length?` (${o})`:"";return `${t.split("_")[1]}-PERP${n}`},render:(t,r)=>{let o=ne(r);return jsxRuntime.jsxs(ui.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:n=>{e?.onSymbolChange?.({symbol:t}),n.stopPropagation(),n.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ue(r)?.map((n,i)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",className:"oui-break-normal oui-whitespace-nowrap",children:n},i))})]})]})}}}function Me(e){return {title:i18n.i18n.t("orders.column.fill&Quantity"),dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return ot(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o} / `)+`${r.quantity}`},render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(Ft,{order:r,disableEdit:e?.disableEdit})}}function ea(e){return {title:i18n.i18n.t("common.quantity"),className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return ot(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(Ft,{order:r})}}function We(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,o)=>ot(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>utils.commifyOptional(r.price?.toString(),{fallback:i18n.i18n.t("common.marketPrice")}),render:(t,r)=>jsxRuntime.jsx(Ur,{order:r,disableEdit:e?.disableEdit})}}function ta(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:o,slTriggerPrice:n}=lo(r),i=`${o||""}${n?`${o?`
17
+ `:""}${n}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsxRuntime.jsx(so,{})}}function ra(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>utils.commifyOptional(t)}}function je(e){return {title:i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=r?.algo_order_id!==void 0,n=r?.algo_type==="BRACKET";return !o||n?"--":utils.commifyOptional(t)},render:(t,r)=>jsxRuntime.jsx(Gr,{order:r,disableEdit:e?.disableEdit})}}function co(e){return {title:e?.title??i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r),s=(a!=null?`${i18n.i18n.t("tpsl.tp")}: ${utils.commifyOptional(a,{fix:n,padEnd:true})}`:"")+(i!=null?`${a?`
18
+ `:""}${i18n.i18n.t("tpsl.sl")}: ${utils.commifyOptional(i,{fix:n,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsxRuntime.jsx(eo,{})}}function oa(e){return {title:i18n.i18n.t("common.tpsl"),className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:n,tp_trigger_price:i}=o(),a=(i!=null?`${i18n.i18n.t("tpsl.tp")}: ${i}`:"")+(n!=null?`${i?`
19
+ `:""}${i18n.i18n.t("tpsl.sl")}: ${n}`:"");return a.length>0?a:"--"},render:(t,r)=>jsxRuntime.jsx(no,{order:r})}}function ze(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,o)=>{let n=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return ot(n,i)}:void 0,renderPlantText:(t,r)=>$t(r,e?.isPending??false)==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional($t(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let o=$t(r,e?.isPending??false);return o==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:o})}}}function zt(e){return {title:i18n.i18n.t("common.realizedPnl"),dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??n,a=new utils.Decimal(t??0).toDecimalPlaces(i,utils.Decimal.ROUND_DOWN).toNumber(),s=utils.commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:o}=W(),n=e?.pnlNotionalDecimalPrecision??o,i=new utils.Decimal(t??0).toDecimalPlaces(n,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:n,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsxRuntime.jsx(Ze,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:uiShare.SharePnLDialogId})]})}}}function we(e){return {title:i18n.i18n.t("orderEntry.reduceOnly"),dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no"),render:t=>jsxRuntime.jsx(ui.Text,{children:t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no")})}}function $e(e){return {title:i18n.i18n.t("orders.column.hidden"),dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes"),render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes")})}}function Ue(e){return {title:i18n.i18n.t("orders.column.orderTime"),dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let o=new Date(t);return dateFns.format(o,"yyyy-MM-dd HH:mm:ss")},render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function et(e){return {title:i18n.i18n.t("common.fee"),dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function na(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function tt(e){let t={[types.OrderStatus.NEW]:i18n.i18n.t("orders.status.pending"),[types.OrderStatus.FILLED]:i18n.i18n.t("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:i18n.i18n.t("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:i18n.i18n.t("orders.status.canceled"),[types.OrderStatus.REJECTED]:i18n.i18n.t("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:i18n.i18n.t("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:i18n.i18n.t("orders.status.completed")};return {title:i18n.i18n.t("common.status"),dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(r,o)=>{let n=r||o.algo_status;return t[n]||Te(n)},render:(r,o)=>{let n=r||o.algo_status;return t[n]||Te(n)}}}function ft(e){return {title:i18n.i18n.t("common.avgOpen"),dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>ot(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===types.OrderType.MARKET&&!t?"--":jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>utils.commifyOptional(t,{fix:2})}}function mo(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===types.OrderStatus.CANCELLED?jsxRuntime.jsx(Jr,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(mt,{order:r}):null}}function ia(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(mt,{order:r})}}function aa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(io,{order:r}),jsxRuntime.jsx(mt,{order:r})]})}}function ot(e,t){return e>t?1:e<t?-1:0}function $t(e,t){return t?e.price&&e.quantity?new utils.Decimal(e.price).mul(e.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--":e.type===types.OrderType.CLOSE_POSITION&&e.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var Po=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui.Badge,{color:r?"success":"danger",size:"xs",children:o(r?"common.buy":"common.sell")}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},xo=e=>{let {item:t}=e;react.useCallback(()=>{let o=typeof t.type=="string"?t.type.replace("_ORDER","").toLowerCase():t.type;return t.algo_order_id&&t.algo_type!==types.AlgoOrderRootType.BRACKET?`Stop ${o}`:Te(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ue(e.item)?.map((o,n)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},n))})},So=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:"yyyy-MM-dd hh:mm:ss",intensity:36,size:"2xs",children:t.updated_time})},_o=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.status||t.algo_status,n=react.useMemo(()=>({[types.OrderStatus.NEW]:r("orders.status.pending"),[types.OrderStatus.FILLED]:r("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:r("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:r("orders.status.canceled"),[types.OrderStatus.REJECTED]:r("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:r("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:r("orders.status.completed")}),[r]);return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,size:"2xs",children:n[o]||Te(o)})},Kt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:r("common.qty"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:r("tpsl.entirePosition"),intensity:80,children:o?r("tpsl.entirePosition"):t.quantity})})},Qt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:r("orders.status.filled")}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var Oo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:[r("common.notional"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o})})},Ht=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("orders.column.triggerPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},ho=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("common.markPrice"),align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},Co=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&o;return jsxRuntime.jsx(ui.Statistic,{label:r("common.limitPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsxRuntime.jsx(ui.Text,{children:r("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},To=e=>{let{tp_trigger_price:t,tpPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.tpTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(yt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.tpPnl")}:`,"\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Lo=e=>{let{sl_trigger_price:t,slPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.slTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(yt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.slPnl")}:`,"\xA0\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},No=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.tpPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},wo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.slPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},Io=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:r("tpsl.entirePosition")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t,r]);return jsxRuntime.jsx(ui.Statistic,{label:r("common.quantity"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:o})},Eo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.avgPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:e.item?.average_executed_price??"--"})})},vo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("orders.column.orderPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,placeholder:t("common.marketPrice"),children:e.item?.price??"--"})})},Ao=e=>{let t=e?.item?.realized_pnl,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[r("common.realizedPnl"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"}),jsxRuntime.jsx(Ze,{order:e.item,sharePnLConfig:e.sharePnLConfig,modalId:uiShare.SharePnLBottomSheetId,iconSize:12})]})})},yt=e=>{let{classNames:t,content:r}=e,[o,n]=react.useState(false);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:n,arrow:{className:t?.arrow},children:jsxRuntime.jsx("div",{onClick:()=>n(i=>!i),children:e.children})})};var Vt=e=>{let {t}=i18n.useTranslation(),{item:r}=e;r.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:t("common.edit")})})};var ko=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:n,isAlgoOrder:i}=e,a=t===types.OrderSide.BUY,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-2",children:[jsxRuntime.jsx(ui.Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxRuntime.jsxs(ui.Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ue(e.item)?.map((d,u)=>jsxRuntime.jsx(ui.Badge,{color:d.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:d},u)),a&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:s("common.buy")}),!a&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:s("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{}),jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[i&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("orders.column.triggerPrice")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:n??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.price")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?s("common.marketPrice"):"--",children:e.isStopMarket?s("common.marketPrice"):r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.qty")}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o??"--"})]})]}),jsxRuntime.jsxs(ui.Flex,{className:"oui-gap-[2px]",children:[jsxRuntime.jsx(ui.Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:d=>{e.setOrderConfirm(!d);}}),jsxRuntime.jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:s("orderEntry.disableOrderConfirm")})]})]})};var jt=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation(),{parseErrorMsg:n}=reactApp.useOrderEntryFormErrorMsg(e.errors),i=n("order_quantity"),a=n("order_price"),s=n("trigger_price"),d=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,u=l=>{let b=e.baseTick;if(b&&b>0){let m=hooks.utils.formatNumber(l,b)??l;e.setQuantity(m);}};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:3,width:"100%",itemAlign:"start",className:"oui-text-sm",children:[jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",showIcon:true,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ue(e.item)?.map((l,b)=>jsxRuntime.jsx(ui.Badge,{color:l.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:l},b)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:o("common.buy")}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:o("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{intensity:8,className:"oui-w-full"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:o("common.lastPrice")}),jsxRuntime.jsx(ui.Text.numeral,{dp:e.item?.symbolInfo?.duote_dp,children:e.curMarkPrice??"--"})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",direction:"column",itemAlign:"stretch",gap:2,children:[e.isAlgoOrder&&jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("orders.column.triggerPrice")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:s?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:l=>e.setTriggerPrice(l),tooltip:s,tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98 oui-w-full",root:ui.cn("oui-outline-line-12",s&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.price")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:a?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?o("orderEntry.orderType.market"):e.price,onValueChange:l=>e.setPrice(l),tooltip:a,tooltipProps:{content:{className:"oui-bg-base-5"},arrow:{className:"oui-fill-base-5"}},classNames:{input:"oui-text-base-contrast-98",root:ui.cn("oui-outline-line-12",a&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.quantity")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:i?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:l=>{e.setQuantity(l);},onBlur:l=>u(l.target.value),tooltip:i,tooltipProps:{content:{className:"oui-bg-base-6"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98",root:ui.cn("oui-outline-line-12",i&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:l=>{e.setSliderValue(l[0]);},color:"primary"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:false,rule:"percentages",children:`${d??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primary",children:o("common.max")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:54,size:"2xs",dp:e.base_dp,children:e.maxQty})]})]})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",gap:3,mt:2,children:[jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"secondary",onClick:l=>{e.onClose();},children:o("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:true,onClick:l=>{l.stopPropagation(),l.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:o("common.confirm")})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:o("orders.editOrder"),size:"xs",actions:{primary:{label:o("common.confirm"),onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:true},secondary:{label:o("common.cancel"),onClick:e.onCloseDialog,fullWidth:true}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(ko,{...e})})]})};var or=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:n=true,position:i}=e,{item:a}=t,{hide:s}=ui.useModal(),[d,u]=react.useState(false),l=a?.algo_order_id!==void 0&&a.algo_type!==types.AlgoOrderRootType.BRACKET,b=a?.type==="MARKET"&&l;b||a?.type==="MARKET";let [O,_]=react.useState(false),I=react.useMemo(()=>l&&a.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${a.type}`:a.type,[a,l]),[h,F]=hooks.useLocalStorage("orderly_order_confirm",true),{base_dp:T,base_tick:V}=e.state,{formattedOrder:f,setValue:w,markPrice:R,errors:x,validate:C,maxQty:D}=ka({order:a,orderType:I,position:i}),te=()=>{C().then(y=>{h?u(true):A(f);},y=>{y?.total?.message&&ui.toast.error(y?.total.message);}).catch(y=>{});},E=react.useCallback(()=>{u(false);},[]),Y=()=>f?A(f):Promise.reject(),v=react.useCallback(()=>{s();},[]),A=react.useCallback(async y=>{let k,Ce=a.visible_quantity!==void 0?a.visible_quantity===0:a.visible!==void 0?a.visible===0:false;if(a.algo_order_id!==void 0){if(b&&"order_price"in y){let{order_price:Fe,...Ot}=y;y=Ot;}k=r(a.algo_order_id.toString(),{...y});}else k=o(a.order_id.toString(),{...y,...Ce?{visible_quantity:0}:{}});try{_(!0);let Fe=await k;v();}catch(Fe){ui.toast.error(Fe?.message??`${Fe}`);}finally{_(false);}},[r,o]),re=react.useMemo(()=>{let y=f.order_quantity;return y&&Number(y)!==0&&D!==0?new utils.Decimal(y).div(D).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[f.order_quantity,D]),de=a.price!=f.order_price||a.quantity!=f.order_quantity||a.trigger_price!=f.trigger_price,De=hooks.useThrottledCallback(y=>{let k=new utils.Decimal(y).div(100).mul(D).toDecimalPlaces(T,utils.Decimal.ROUND_DOWN).toNumber();w("order_quantity",hooks.utils.formatNumber(k,V));},50,{}),g=(y,k)=>{w(y,k);};return {...t,curMarkPrice:R,isAlgoOrder:l,isStopMarket:b,price:f.order_price,setPrice:y=>g("order_price",y),priceEdit:!b,triggerPrice:f.trigger_price,setTriggerPrice:y=>g("trigger_price",y),quantity:f.order_quantity,setQuantity:y=>{g("order_quantity",y);},maxQty:D,sliderValue:re,setSliderValue:De,onClose:v,onSheetConfirm:te,errors:x,orderType:I,isChanged:de,baseTick:V,dialogOpen:d,setDialogOpen:u,onDialogConfirm:Y,onCloseDialog:E,submitting:O,orderConfirm:h,setOrderConfirm:F}},ka=e=>{let{order:t,orderType:r,position:o}=e,[n,i]=react.useState({side:t.side,order_type:r,order_price:t.price,order_quantity:t.quantity,trigger_price:t.trigger_price,reduce_only:t.reduce_only,symbol:t.symbol}),{reduce_only:a}=t,s=o?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),u=react.useMemo(()=>a?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,a,s]),{symbolInfo:l,markPrice:b,errors:m,validate:O}=hooks.useOrderEntity({...n,symbol:t.symbol},{maxQty:u});return {symbolInfo:l,markPrice:b,errors:m,validate:O,setValue:(I,h)=>{i(F=>({...F,[I]:h}));},formattedOrder:n,maxQty:u}};var nr=e=>{let t=or(e);return jsxRuntime.jsx(jt,{...t})};var ir=e=>{let{state:t}=e,{t:r}=i18n.useTranslation(),{editAlgoOrder:o,editOrder:n}=X(),{order:i,position:a}=G(),s=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({title:r("common.tpsl"),content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:true,order:e.state.item,position:a,symbolInfo:e.state.origin})}).catch(d=>{}):ui.modal.sheet({title:r("orders.editOrder"),classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(nr,{position:a,state:t,editAlgoOrder:o,editOrder:n})}).catch(d=>{});},[t]);return {...t,onShowEditSheet:s}};var ar=e=>{let t=ir(e);return jsxRuntime.jsx(Vt,{...t})};var lr=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:r=>e.setOpen(true),children:t("common.cancel")}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:t("orders.cancelOrder"),actions:{primary:{label:t("common.confirm"),loading:e.isLoading,fullWidth:true,size:"md",onClick:r=>{e.onCancel(r);}},secondary:{label:t("common.cancel"),fullWidth:true,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:t("orders.cancelOrder.description")})})]})};var dr=e=>{let{state:t}=e,[r,o]=react.useState(false),{onCancelOrder:n}=X(),[i,a]=react.useState(false);return {...t,open:r,setOpen:o,onCancel:u=>n?(u?.preventDefault(),u?.stopPropagation(),a(true),n(t.item).then(l=>{o(false);},l=>{ui.toast.error(l.message);}).finally(()=>{a(false);})):Promise.resolve(),onClose:()=>{o(false);},isLoading:i}};var ur=e=>{let t=dr(e);return jsxRuntime.jsx(lr,{...t})};var mr=e=>{let{t}=i18n.useTranslation();return !e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(yt,{classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof e.pnl?.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:true,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"sell",children:e.pnl?.slPnL})]}),children:jsxRuntime.jsx("button",{onClick:()=>{e.setOpen(!e.open);},children:jsxRuntime.jsxs(ui.Flex,{gap:1,width:"1",children:[e.tp_trigger_price&&jsxRuntime.jsx($o,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx($o,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})})},$o=e=>{let{type:t,value:r,quote_dp:o}=e;return r?jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",className:ui.cn("oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,padding:false,rm:utils.Decimal.ROUND_DOWN,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-36",children:[`${t} `,":\xA0\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var pr=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[n,i]=react.useState(false),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:d,roi:u}=lt(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:d,roi:u,quote_dp:r,open:n,setOpen:i}};var fr=e=>{let t=pr(e);return jsxRuntime.jsx(mr,{...t})};var gr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(os,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(ns,{...e}),e.type==="pending"&&jsxRuntime.jsx(fr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(is,{...e})]}),os=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(Po,{...e}),jsxRuntime.jsx(So,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(xo,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(_o,{...e})]})]}),ns=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:as(e)}),is=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ar,{state:e}),jsxRuntime.jsx(ur,{state:e})]});function as(e){switch(e.type){case "all":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "pending":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Kt,{...e}),jsxRuntime.jsx(Qt,{...e}),jsxRuntime.jsx(Oo,{...e}),jsxRuntime.jsx(Ht,{...e}),jsxRuntime.jsx(Co,{...e}),jsxRuntime.jsx(ho,{...e})]});case "tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(To,{...e}),jsxRuntime.jsx(No,{...e}),jsxRuntime.jsx(Io,{...e}),jsxRuntime.jsx(Lo,{...e}),jsxRuntime.jsx(wo,{...e})]});case "filled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "cancelled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "rejected":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "orderHistory":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Kt,{...e}),jsxRuntime.jsx(Qt,{...e}),jsxRuntime.jsx(Ht,{...e,align:"end"}),jsxRuntime.jsx(Eo,{...e}),jsxRuntime.jsx(vo,{...e}),jsxRuntime.jsx(Ao,{...e})]})}}var yr=e=>{let t=W();return {...e,...t}};var br=e=>{let{className:t,...r}=e,o=yr(r);return jsxRuntime.jsx(gr,{...o,className:t})};var Pr=e=>{let{sharePnLConfig:t,...r}=e,o=fo({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:t,symbolsInfo:e.symbolsInfo});return jsxRuntime.jsx(Nt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",height:"100%",itemAlign:"start",children:[e.filterItems.length>0&&jsxRuntime.jsx(ui.DataFilter,{items:e.filterItems,onFilter:n=>{e.onFilter(n);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(ys,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:o,loading:e.isLoading,dataSource:e.dataSource,bordered:true,ignoreLoadingCheck:true,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(n,i)=>({className:ui.cn("oui-h-[48px]",ne(n)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(n,i)=>`${e.type}${i}${n.order_id||n.algo_order_id}_index${i}`,renderRowContainer:(n,i,a)=>((e.type==="tp_sl"||e.type==="pending")&&(a=jsxRuntime.jsx(It,{order:n,children:a})),jsxRuntime.jsx(Tt,{symbol:n.symbol,children:a})),pagination:e.pagination,manualPagination:e.manualPagination,features:[ui.TableFeatures.DownloadFeature],getTableInstance:n=>{e.tableInstance.current=n;}})]})})},xr=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(Nt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Grid,{cols:1,rows:2,className:"oui-grid-rows-[auto,1fr] oui-w-full",gap:2,children:[e.showFilter?jsxRuntime.jsx(ui.Flex,{gap:2,p:2,className:"oui-bg-base-9 oui-rounded-b-xl",children:e.filterItems.map(r=>r.type!=="select"?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ui.Picker,{options:r.options,size:"sm",value:r.value,className:"oui-text-2xs oui-text-base-contrast-54 ",placeholder:r.name==="side"?t("common.side.all"):r.name==="status"?t("common.status.all"):"",onValueChange:o=>{e.onFilter?.({name:r.name,value:o});}}))}):jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ui.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(r,o)=>{let n=jsxRuntime.jsx(br,{item:r,index:o,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange,sharePnLConfig:e.sharePnLConfig});return ["tp_sl","pending"].includes(e.type)&&(n=jsxRuntime.jsx(It,{order:r,children:n})),jsxRuntime.jsx(Tt,{symbol:r.symbol,children:n})}})]})})},ys=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",disabled:(e.dataSource?.length??0)==0,className:"disabled:oui-bg-transport",onClick:r=>e.onCancelAll(),"data-testid":`oui-testid-dataList-${e.type.toLowerCase()}-cancelAll-button`,children:t("orders.cancelAll")})};var Yo=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let n=e[o];if(n.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||n.algo_type===types.AlgoOrderRootType.TP_SL)if(n.algo_status!==types.OrderStatus.FILLED&&n.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];!a.is_activated||!a.trigger_price||(a.parent_algo_type=n.algo_type,r.push(a));}else for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=n.algo_type,r.push(a));}else r.push(n);}return r},[e]);var _t=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=false,onSymbolChange:n,filterConfig:i,pnlNotionalDecimalPrecision:a,sharePnLConfig:s}=e,{t:d}=i18n.useTranslation(),u=hooks.useSymbolsInfo(),l=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),b=50,{page:m,pageSize:O,setPage:_,pagination:I,parsePagination:h}=ui.usePagination({pageSize:b});react.useEffect(()=>{_(1);},[e.symbol]);let{orderStatus:F,ordersSide:T,dateRange:V,filterItems:f,onFilter:w}=vs(r,{ordersStatus:t,setPage:_,filterConfig:i}),M=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),R=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),x=react.useRef();react.useImperativeHandle(e.ref,()=>({download:()=>{let ht=`orders_${dateFns.format(new Date,"yyyyMMdd_HHmmss")}`;x.current?.download(ht);}}));let[C,{isLoading:D,loadMore:te,cancelOrder:E,updateOrder:Y,cancelAlgoOrder:v,updateAlgoOrder:A,cancelAllOrders:re,cancelAllTPSLOrders:de,meta:De,refresh:g}]=hooks.useOrderStream({symbol:e.symbol,status:F,side:T,page:o||!l?void 0:m,size:l?O:500,dateRange:V,includes:M,excludes:R}),y=`orderly_${r}_pageSize`,[k,Ce]=hooks.useLocalStorage(y,b);react.useEffect(()=>{k!==O&&Ce(O);},[O,k]);let Fe=react.useCallback(()=>{let ht=e.type==="pending"?d("orders.pending.cancelAll"):e.type==="tp_sl"?d("orders.tpsl.cancelAll"):"",on=d("orders.pending.cancelAll.description");ui.modal.confirm({title:ht,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:on}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await de():await re(),g(),Promise.resolve(!0)}catch(_r){return _r?.message!==void 0&&toast.error(_r.message),Promise.resolve(false)}finally{Promise.resolve();}}});},[r,d]),Ot=Yo(C??[]),tn=reactApp.useDataTap(r!=="tp_sl"?Ot:C,{fallbackData:[]})??void 0,rn=react.useMemo(()=>l?h(De):I,[De,l,h,I]);return {type:r,dataSource:tn,isLoading:D,loadMore:te,cancelOrder:E,updateOrder:Y,cancelAlgoOrder:v,updateAlgoOrder:A,pagination:rn,manualPagination:l,pnlNotionalDecimalPrecision:a,onFilter:w,filterItems:f,onCancelAll:Fe,onSymbolChange:n,sharePnLConfig:s,tableInstance:x,symbolsInfo:u}},vs=(e,t)=>{let{t:r}=i18n.useTranslation(),[o,n]=react.useState(t.ordersStatus??"all"),[i,a]=react.useState(t.filterConfig?.side??"all"),s=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Jo({to:new Date,from:Zo(dateFns.subDays(new Date,7))}):{}),[d,u]=react.useState(s),l=m=>{m.name==="side"&&(a(m.value),t.setPage(1)),m.name==="status"&&(n(m.value),t.setPage(1)),m.name==="dateRange"&&(u(Jo(m.value)),t.setPage(1));};return {filterItems:react.useMemo(()=>{let m={type:"select",name:"side",options:[{label:r("common.side.all"),value:"all"},{label:r("common.buy"),value:"BUY"},{label:r("common.sell"),value:"SELL"}],value:i},O={type:"range",name:"dateRange",value:d},_={type:"select",name:"status",options:[{label:r("common.status.all"),value:"all"},{label:r("orders.status.pending"),value:types.OrderStatus.INCOMPLETE},{label:r("orders.status.filled"),value:types.OrderStatus.FILLED},{label:r("orders.status.partialFilled"),value:types.OrderStatus.PARTIAL_FILLED},{label:r("orders.status.canceled"),value:types.OrderStatus.CANCELLED},{label:r("orders.status.rejected"),value:types.OrderStatus.REJECTED}],value:o};switch(e){case "all":return [m,_,O];case "pending":return [m];case "tp_sl":return [m];case "filled":return [m];case "cancelled":return [m];case "rejected":return [m];case "orderHistory":return [m,_,O]}},[e,i,o,d,r]),onFilter:l,ordersSide:i==="all"?void 0:i,dateRange:d,orderStatus:o==="all"?void 0:o}};function As(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Zo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Jo=e=>({from:As(e.from),to:Zo(e.to??e.from)});var he=react.forwardRef((e,t)=>{let{testIds:r,...o}=e,n=_t({...o,ref:t});return jsxRuntime.jsx(Pr,{...n,testIds:r})}),ks=e=>{let t=_t({...e,enableLoadMore:true});return jsxRuntime.jsx(xr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var en=e=>{let{t}=i18n.useTranslation(),r={pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision};return jsxRuntime.jsxs(ui.Tabs,{defaultValue:e.current||"all",variant:"contained",className:"oui-h-full",classNames:{tabsContent:"oui-h-[calc(100%_-_28px)]"},children:[jsxRuntime.jsx(ui.TabPanel,{value:"all",title:t("common.all"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:t("orders.status.pending"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:t("common.tpsl"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:t("orders.status.filled"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:t("orders.status.canceled"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:t("orders.status.rejected"),children:jsxRuntime.jsx(he,{ref:e.orderListRef,type:"rejected",ordersStatus:types.OrderStatus.REJECTED,...r})})]})};var Pe=(s=>(s.all="all",s.pending="pending",s.tp_sl="tp_sl",s.filled="filled",s.cancelled="cancelled",s.rejected="rejected",s.orderHistory="orderHistory",s))(Pe||{}),Ws=react.forwardRef((e,t)=>{let r=Ct({...e,ref:t});return jsxRuntime.jsx(en,{...r})});
19
20
 
20
- exports.DesktopOrderList = mr;
21
- exports.DesktopOrderListWidget = Pe;
22
- exports.MobileOrderList = fr;
23
- exports.MobileOrderListWidget = ls;
24
- exports.OrdersWidget = ms;
25
- exports.TabType = pe;
26
- exports.useOrderListScript = ft;
27
- exports.useOrdersScript = bt;
21
+ exports.DesktopOrderList = Pr;
22
+ exports.DesktopOrderListWidget = he;
23
+ exports.MobileOrderList = xr;
24
+ exports.MobileOrderListWidget = ks;
25
+ exports.OrdersWidget = Ws;
26
+ exports.TabType = Pe;
27
+ exports.useOrderListScript = _t;
28
+ exports.useOrdersScript = Ct;
28
29
  //# sourceMappingURL=out.js.map
29
30
  //# sourceMappingURL=index.js.map