@orderly.network/ui-orders 2.0.1-preview.0 → 2.0.1-preview.2

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
@@ -11,7 +11,7 @@ var uiTpsl = require('@orderly.network/ui-tpsl');
11
11
  var reactApp = require('@orderly.network/react-app');
12
12
  var dateFns = require('date-fns');
13
13
 
14
- var mt=e=>{let{current:t,pnlNotionalDecimalPrecision:r}=e;return {current:t,pnlNotionalDecimalPrecision:r}};var j=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function de(e){if(typeof e.type<"u"){let t=new Array;if(e.parent_algo_type){if(e.algo_type===types.AlgoOrderType.STOP_LOSS){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","SL"]:["SL"];t.push(...i);}if(e.algo_type===types.AlgoOrderType.TAKE_PROFIT){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","TP"]:["TP"];t.push(...i);}return t}(typeof e.type=="string"?[e.type.replace("_ORDER","").toLowerCase()]:[e.type]).map(i=>j(i));let o=typeof e.type=="string"?e.type.replace("_ORDER","").toLowerCase():j(e.type);return e.algo_order_id===void 0||e.algo_order_id&&e.algo_type==="BRACKET"?[j(o)]:[`Stop ${o}`]}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(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!i.trigger_price),o=e?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS&&!!i.trigger_price);return (r||o)&&t.push(r&&o?"TP/SL":r?"TP":"SL"),t}}function ee(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function Fo(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(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function Ye(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=Fo(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let i=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,a=r?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),n=o?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0,d=n?hooks.utils.calcTPSL_ROI({pnl:n,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:a,slPnL:n},roi:{tpRoi:s,slRoi:d}}}var mr=react.createContext({}),M=()=>react.useContext(mr),pt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(mr.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 fr=react.createContext({}),G=()=>react.useContext(fr),gt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:i}=e,a=hooks.useSymbolsInfo(),n=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(()=>{}),[]),s=react.useCallback(async(l,y)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:!1;await ui.modal.sheet({title:"Edit Order",classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[]),d=react.useCallback((l,y,u)=>{let{min_notional:h}=a[l]();return hooks.checkNotional(y,u,h)},[a]);return jsxRuntime.jsx(fr.Provider,{value:{onCancelOrder:n,onEditOrder:s,editOrder:r,editAlgoOrder:i,checkMinNotional:d},children:e.children})};var br=react.createContext({}),V=()=>react.useContext(br),bt=e=>{let{quote_dp:t}=M(),[r,o]=react.useState(),[i]=hooks.useMutation("/v1/algo/order","DELETE"),[a]=hooks.useMutation("/v1/algo/order","PUT"),n=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),l=async S=>i(null,{order_id:S.algo_order_id,symbol:S.symbol}),y=async(S,w)=>a({order_id:S.algo_order_id,child_orders:S.child_orders.map(I=>({order_id:I.algo_order_id,quantity:w.order_quantity}))}),u=S=>n.cache.get(d)?.data.rows.find(I=>I.symbol===S),{sl_trigger_price:h,tp_trigger_price:N,tpPnL:_,slPnL:v}=jo({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??!1)){let S=u(e.order.symbol);S&&o(S);}},[e.order.symbol]),jsxRuntime.jsx(br.Provider,{value:{order:e.order,sl_trigger_price:h,tp_trigger_price:N,tpPnL:_,slPnL:v,onCancelOrder:l,onUpdateOrder:y,getRelatedPosition:u,position:r},children:e.children})};function jo(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:i,tp_trigger_price:a}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),n=t.quantity;n===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(n=r.position_qty);let s=r.average_open_price,d=typeof n=="number"&&typeof a=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:n,price:a,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,l=typeof n=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:n,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:i,tp_trigger_price:a,slPnL:l,tpPnL:d}}var Ne=e=>{let{type:t,base:r,value:o,cancelPopover:i,isSubmitting:a,onConfirm:n}=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(o)}),"."]}),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:i,disabled:a,children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:a,onClick:n,children:"Confirm"})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:i,children:jsxRuntime.jsx(ui.CloseIcon,{size:18})})]})};var we=e=>{let{inputRef:t,dp:r,value:o,setValue:i,setEditing:a,error:n,handleKeyDown:s,onClick:d,onClose:l,onFocus:y,onBlur:u,hintInfo:h}=e;react.useEffect(()=>{let _=t.current;if(_){let v=_.value.length;_.setSelectionRange(v,v);}a(!0);},[]);let N=(h?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:h,open:N,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:_=>i(_),helpText:n,onClick:_=>{_.stopPropagation(),_.preventDefault();},autoComplete:"off",onFocus:y,onBlur:u,onKeyDown:s,autoFocus:!0,color:N?"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 Ot=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[i,a]=react.useState(t.quantity.toString()),[n,s]=react.useState(!1);react.useEffect(()=>{m(t.quantity.toString());},[e.order.quantity]);let[d,l]=react.useState(!1),[y,u]=react.useState(),{editOrder:h,editAlgoOrder:N,checkMinNotional:_}=G(),{onUpdateOrder:v,position:S}=V(),{base_dp:w,base:I,base_tick:k}=M(),m=async(p,q)=>{a(p);let b=Math.abs(S?.position_qty||0);if(S&&o&&Number(p)>b)u(`Quantity should be less than position quantity : ${b}`);else {let z=Number(p);q&&z>q?u(`Quantity should be less than ${utils.commifyOptional(q,{fix:w})}`):u(void 0);}return Promise.resolve()},A=()=>{l(!1),s(!1);},D=()=>{l(!1),m(t.quantity.toString()),s(!1);},[K,f]=react.useState(!1),O=react.useRef(null),F=()=>{if(y)return;if(Number(i)===Number(t.quantity)){s(!1);return}let p=t.algo_order_id!==void 0?t.trigger_price:t.price;if(p!==null&&t.reduce_only!==!0){let q=_(t.symbol,p,i);if(q){ui.toast.error(q),f(!1),D();return}}l(!0);},le=p=>{p?.stopPropagation(),p?.preventDefault(),F();},L=p=>{p.key==="Enter"&&(p?.stopPropagation(),p?.preventDefault(),F());},P=react.useCallback(()=>{f(!0);let p={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:i,algo_order_id:t.algo_order_id};if(typeof p.algo_order_id<"u"&&p.order_type==="MARKET"){let{order_price:b,...z}=p;p=z;}typeof t.reduce_only<"u"&&(p.reduce_only=t.reduce_only),t.order_tag!==void 0&&(p={...p,order_tag:t.order_tag}),t?.visible_quantity===0&&(p.visible_quantity=0),t?.tag!==void 0&&(p.order_tag=t.tag);let q;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?q=v(t,p):t.algo_order_id!==void 0?q=N(t.algo_order_id.toString(),p):q=h(t.order_id.toString(),p),q.then(b=>{A(),m(i.toString());},b=>{ui.toast.error(b.message),m(t.quantity.toString()),D();}).finally(()=>f(!1));},[i]),E=react.useRef(null),Y=react.useRef(null),ie=p=>{E.current&&Y.current&&!E.current.contains(p.target)&&!Y.current.contains(p.target)&&!d&&D();};react.useEffect(()=>(document.addEventListener("mousedown",ie),()=>{document.removeEventListener("mousedown",ie);}),[d,t.quantity]);let Ce=()=>!n||e.disableEdit?jsxRuntime.jsx(Pi,{order:t,quantity:i,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(_i,{inputRef:O,quantitySliderRef:Y,base_dp:w,base_tick:k,quantity:i,setQuantity:m,editing:n,setEditing:s,handleKeyDown:L,onClick:le,onClose:D,symbol:t.symbol,reduce_only:o,positionQty:S?.position_qty,error:y,confirmOpen:d,side:t.side,order:t,setError:u});return jsxRuntime.jsx(ui.Popover,{open:d,onOpenChange:l,content:jsxRuntime.jsx(Ne,{type:0,base:I,value:i,cancelPopover:D,isSubmitting:K,onConfirm:P}),contentProps:{onOpenAutoFocus:p=>{}},children:jsxRuntime.jsx("div",{onClick:p=>{p.stopPropagation(),p.preventDefault();},ref:E,children:Ce()})})},Pi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:i=>{i.stopPropagation(),i.preventDefault(),e.setEditing(!0);},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})})]})},_i=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:i,quantity:a,setQuantity:n,editing:s,setEditing:d,handleKeyDown:l,onClick:y,onClose:u,error:h,symbol:N,reduce_only:_,positionQty:v,confirmOpen:S,side:w,order:I}=e,k=hooks.useMaxQty(N,I.side,I.reduce_only),m=react.useMemo(()=>_?Math.abs(v??0):I.quantity+Math.abs(k),[I.quantity,k,_,v]),[A,D]=react.useState(void 0);react.useEffect(()=>{if(A===void 0){let f=new utils.Decimal(a).div(m).abs().mul(100).toNumber();D(f);}},[A,m,a]);let K=async f=>(i>0&&(f=hooks.utils.formatNumber(f,i)??f),n(`${f}`,m));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!S,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(we,{inputRef:t,dp:o,value:a,setValue:f=>{let O=Math.abs(Math.min(Number(f),m)).toString();if(n(f,m),f.endsWith("."))return;if(Number(O)===0){D(0);return}let F=new utils.Decimal(f).div(m).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();D(Math.min(100,F));},setEditing:d,handleKeyDown:l,onClick:y,onClose:u,onBlur:f=>{K(f.target.value);},hintInfo:h})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:f=>{f.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:!1,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${A}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[A??0],onValueChange:f=>{let O=Array.from(f.values());D(O[0]);let F=new utils.Decimal(O[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);n(F,m);},onValueCommit:f=>{let O=new utils.Decimal(f[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);K(O).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Oi,{onClick:f=>{D(f*100);let O=new utils.Decimal(f).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);O=hooks.utils.formatNumber(O,i)??O,n(O,m),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(O.length,O.length);},100);}})]})]})})]})},Oi=e=>jsxRuntime.jsx(ui.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,o)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(r.value);},className:"oui-w-1/5",children:r.label},o))});var Er=e=>{let{order:t}=e,[r,o]=react.useState(t.price?.toString()??"Market"),[i,a]=react.useState(!1),[n,s]=react.useState(!1),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[y,u]=react.useState(!1),{editOrder:h,editAlgoOrder:N,checkMinNotional:_}=G(),{base:v,quote_dp:S}=M(),w=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),I=()=>{a(!1),s(!1);},k=()=>{a(!1),o(t.price?.toString()??"Market"),s(!1);},m=react.useMemo(()=>!w||l||!n?"":Number(r)>w.max?`Price can not be greater than ${w.max} USDC.`:Number(r)<w.min?`Price can not be less than ${w.min} USDC.`:"",[l,n,w,r]),A=P=>{if(P?.stopPropagation(),P?.preventDefault(),!(m.length>0)){if(r===`${t.price}`){s(!1);return}if(t.reduce_only!==!0){let E=_(t.symbol,r,t.quantity);if(E){ui.toast.error(E),u(!1),k();return}}a(!0);}},D=P=>{P.key==="Enter"&&A(P);},K=()=>{u(!0);let P=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&&(P=t.algo_order_id,E={...E,order_id:P,price:r,algo_order_id:P}),t?.visible_quantity===0&&(E.visible_quantity=0),t.tag!==void 0&&(E.order_tag=t.tag);let Y;t.algo_order_id!==void 0?Y=N(t.algo_order_id.toString(),E):Y=h(t.order_id.toString(),E),Y.then(ie=>{I(),o(r);},ie=>{ui.toast.error(ie.message),k();}).finally(()=>u(!1));},f=react.useRef(null);react.useEffect(()=>{e.order.price&&o(`${e.order.price}`);},[e.order.price]);let O=react.useRef(null),F=P=>{O.current&&!O.current.contains(P.target)&&!i&&k();};if(react.useEffect(()=>(document.addEventListener("mousedown",F),()=>{document.removeEventListener("mousedown",F);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let L=()=>!n||e.disableEdit?jsxRuntime.jsx(vi,{order:t,price:r,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:f,dp:S,value:r,setValue:o,setEditing:s,handleKeyDown:D,onClick:A,onClose:k,hintInfo:m});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(Ne,{type:1,base:v,value:r,cancelPopover:k,isSubmitting:y,onConfirm:K}),children:jsxRuntime.jsx("div",{onClick:P=>{P.stopPropagation(),P.preventDefault();},ref:O,children:L()})})},vi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},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 kr=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let i=t?.algo_order_id!==void 0,a=t?.algo_type==="BRACKET",[n,s]=react.useState(!1),[d,l]=react.useState(!1),[y,u]=react.useState(!1),{editAlgoOrder:h,checkMinNotional:N}=G(),{base:_,quote_dp:v,quote_max:S,quote_min:w}=M(),I=react.useMemo(()=>{if(!((!i||a)&&!d)){if(Number(r)>S)return `Trigger price must be less than ${S}`;if(Number(r)<w)return `Trigger price must be greater than ${w}`}},[d,r,i,a]),k=()=>{s(!1),l(!1);},m=()=>{o(t.trigger_price?.toString()??"0"),s(!1),l(!1);},A=react.useRef(null),D=L=>{A.current&&!A.current.contains(L.target)&&!n&&m();};react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[n,t.trigger_price]);let K=L=>{if(L?.stopPropagation(),L?.preventDefault(),l(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let P=N(t.symbol,t.price,t.quantity);if(P){ui.toast.error(P),u(!1),m();return}}s(!0);}},f=L=>{L.key==="Enter"&&K(L);},O=()=>{if((I??"").length>0)return;u(!0);let L={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(L={...L,order_tag:t.order_tag}),h(`${t.algo_order_id}`,L).then(P=>{k(),o(r);},P=>{ui.toast.error(P.message),o(t.trigger_price?.toString()??"--"),m();}).finally(()=>u(!1));},F=react.useRef(null);if(!i||a)return jsxRuntime.jsx(ui.Text,{children:"--"});let le=()=>!d||e.disableEdit?jsxRuntime.jsx(Fi,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:F,dp:v,value:r,setValue:o,setEditing:l,handleKeyDown:f,onClick:K,onClose:m,hintInfo:I});return jsxRuntime.jsx(ui.Popover,{open:n,onOpenChange:s,content:jsxRuntime.jsx(Ne,{type:2,base:_,value:r,cancelPopover:m,isSubmitting:y,onConfirm:O}),children:jsxRuntime.jsx("div",{onClick:L=>{L.stopPropagation(),L.preventDefault();},ref:A,children:le()})})},Fi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},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 Ze=e=>{let{order:t}=e,{onCancelOrder:r}=G(),[o,i]=react.useState(!1);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{r&&(a.preventDefault(),a.stopPropagation(),i(!0),r(t).then(n=>n,n=>{ui.toast.error(n.message);}).finally(()=>{i(!1);}));},loading:o,children:"Cancel"})};var qr=e=>{let{record:t}=e,[r,o]=react.useState(!1),[i,{data:a,error:n,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),y=react.useCallback(()=>{o(!1);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),i(u);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:u=>{d||(u.preventDefault(),u.stopPropagation(),y());},children:"Renew"})};var Mr=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=V();return jsxRuntime.jsx(Yi,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},Yi=e=>{let{direction:t="row",order:r,position:o}=e,i=hooks.useSymbolsInfo(),a=react.useMemo(()=>{let d=[];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&&d.push(jsxRuntime.jsx(Br,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:i[r.symbol]()},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(Br,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:i[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:d})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),n=react.useMemo(()=>{let d=[];return r?.symbol?(e.takeProfitPrice&&d.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:i[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.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:i[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.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:n});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",tooltipProps:{arrow:{className:"oui-fill-base-5"}},children:s}):s},Br=e=>{let{qty:t,price:r,entryPrice:o,orderSide:i,orderType:a,symbolInfo:n}=e,s=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:i,orderType:a},{symbol:n}),d=a===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.Text.numeral,{rule:"price",dp:n.quote_dp,padding:!1,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 zr=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=M(),{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:n,roi:s}=Ye(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof n.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:!0,children:n.tpPnL}),typeof n.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:n.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Ur,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(Ur,{type:"SL",value:i,quote_dp:r})]})})},Ur=e=>{let{type:t,value:r,quote_dp:o}=e;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}`,"\xA0-\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Qr=e=>{let{position:t,order:r}=V(),{quote_dp:o,base_dp:i}=M();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:i,position:t,order:r,label:"Edit",isEditing:!0})};var $r=()=>{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]})};var Hr=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o}=e;return react.useMemo(()=>{switch(t){case"all":return [be({width:130,showType:!0,onSymbolChange:r,enableSort:!1}),Ee({width:130,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),ve({width:130,title:"Order price",disableEdit:!0,enableSort:!1}),et({width:130,enableSort:!1}),Kr({width:130}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:130,enableSort:!1}),ze({width:130}),Qe({width:130}),xe({width:130}),Ae({width:130}),Vr({width:130})];case"pending":return [be({width:172,showType:!0,onSymbolChange:r,enableSort:!1}),Ee({width:162,className:"oui-pr-0",enableSort:!1}),ve({width:162,className:"oui-pr-0",enableSort:!1}),We({width:162,className:"oui-pr-0"}),mn({width:130}),Ie({width:162,isPending:!0}),xe({width:162}),Ae({width:162}),Ue({width:162,enableSort:!1}),fn({width:162})];case"tp_sl":return [be({width:176,showType:!0,onSymbolChange:r,enableSort:!1}),dn({width:176}),Kr({width:176}),un({width:176,disableEdit:!0}),pn({width:176}),xe({width:176}),Ue({width:176,enableSort:!1}),gn({width:176})];case"filled":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),ve({width:124,title:"Order price",disableEdit:!0}),cn({width:124}),We({width:124,disableEdit:!0}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:124})];case"cancelled":return [be({showType:!0,width:154,onSymbolChange:r,enableSort:!1}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),ve({width:124,disableEdit:!0,enableSort:!1}),et({width:124,enableSort:!1}),We({width:124,disableEdit:!0}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124})];case"rejected":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),ve({width:124,disableEdit:!0}),et({width:124}),We({width:124,disableEdit:!0}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:124})];case"orderHistory":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:150,disableEdit:!0,className:"oui-pl-6 oui-pr-0"}),ve({width:124,disableEdit:!0}),et({width:124}),We({width:124,disableEdit:!0}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:150}),Vr({width:80})]}},[t,o])};function be(e){return {title:"Instrument",dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,render:(t,r)=>{let o=ee(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:i=>{e?.onSymbolChange?.({symbol:t}),i.stopPropagation(),i.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(r)?.map((i,a)=>jsxRuntime.jsx(ui.Badge,{color:i.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",children:i},a))})]})]})}}}function Ee(e){return {title:"Filled / Quantity",dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return $e(o,i)}:void 0,render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(Ot,{order:r,disableEdit:e?.disableEdit})}}function dn(e){return {title:"Quantity",className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return $e(o,i)}:void 0,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Ot,{order:r})}}function ve(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r,o)=>$e(t.price??0,r.price??0):void 0,render:(t,r)=>jsxRuntime.jsx(Er,{order:r,disableEdit:e?.disableEdit})}}function un(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx($r,{})}}function cn(e){return {title:"Avg. price",dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:utils.commifyOptional(t)})}}function We(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(kr,{order:r,disableEdit:e?.disableEdit})}}function Kr(e){return {title:e?.title??"Trigger",className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Mr,{})}}function mn(e){return {title:"TP/SL",className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(zr,{order:r})}}function Ie(e){return {title:"Notional",dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??!1?(t,r,o)=>{let i=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,a=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 $e(i,a)}:void 0,render:(t,r)=>{if(e?.isPending){let o=()=>r.price&&r.quantity?new utils.Decimal(r.price).mul(r.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--";return jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,children:o()})}return r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?"--":`${r.total_executed_quantity*r.average_executed_price}`})}}}function Lt(e){return {title:"Real. PnL",dataIndex:"realized_pnl",width:e?.width,className:e?.className,render:t=>{let{quote_dp:r}=M(),o=e?.pnlNotionalDecimalPrecision??r,i=new utils.Decimal(t??0).toDecimalPlaces(o,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsx(ui.Text.numeral,{dp:o,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"})}}}function xe(e){return {title:"Reduce only",dataIndex:"reduce_only",width:e?.width,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text,{children:t?"Yes":"No"})}}function Ae(e){return {title:"Hidden",dataIndex:"visible",width:e?.width,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?"No":"Yes"})}}function Ue(e){return {title:"Order time",dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,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 ze(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function pn(e){return {title:"Notional",dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":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 Qe(e){return {title:"Status",dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>{let o=t||r.algo_status;return o==="NEW"?j("pending"):j(o)}}}function et(e){return {title:"Avg. open",dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>$e(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.average_executed_price})}}function Vr(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(qr,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(Ze,{order:r}):null}}function fn(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(Ze,{order:r})}}function gn(e){return {title:"",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(Qr,{order:r}),jsxRuntime.jsx(Ze,{order:r})]})}}function $e(e,t){return e>t?1:e<t?-1:0}var Xr=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY;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:r?"Buy":"Sell"}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Zr=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}`:j(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(e.item)?.map((o,i)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},i))})},jr=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})},eo=e=>{let{item:t}=e,r=t.status||t.algo_status,o=()=>r==="NEW"?j("pending"):j(r);return jsxRuntime.jsx(ui.Text.formatted,{intensity:36,size:"2xs",children:o()})},vt=e=>{let{item:t}=e,r=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:"Qty.",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:!1,coloring:!0,placeholder:"Entire position",intensity:80,children:r?"--":t.quantity})})},It=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:"Filled"}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var to=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.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:["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:!0,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:r})})},At=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Trigger price",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:!1,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},ro=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Mark price",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:!1,children:t.mark_price})})},oo=e=>{let{item:t}=e,r=t?.algo_order_id!==void 0,o=t?.type==="MARKET"&&r;return jsxRuntime.jsx(ui.Statistic,{label:"Limit price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:o?jsxRuntime.jsx(ui.Text,{children:"Market"}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.price??"--"})})},io=e=>{let{tp_trigger_price:t,tpPnL:r}=V();return jsxRuntime.jsx(ui.Statistic,{label:"TP trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ot,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:!0,prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"TP PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,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:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},no=e=>{let{sl_trigger_price:t,slPnL:r}=V();return jsxRuntime.jsx(ui.Statistic,{label:"SL trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ot,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"SL PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,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:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},ao=e=>jsxRuntime.jsx(ui.Statistic,{label:"TP price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),so=e=>jsxRuntime.jsx(ui.Statistic,{label:"SL price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),lo=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.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.quantity}),[t]);return jsxRuntime.jsx(ui.Statistic,{label:"Quantity",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:r})},uo=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Avg price",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:!1,children:e.item?.average_executed_price??"--"})}),co=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Order price",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:!1,placeholder:"Market",children:e.item?.price??"--"})}),mo=e=>{let t=e?.item?.realized_pnl;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Real. PnL",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"})})},ot=e=>{let{classNames:t,content:r}=e,[o,i]=react.useState(!1);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:i,tooltipProps:{arrow:{className:t?.arrow}},children:jsxRuntime.jsx("div",{onClick:()=>i(a=>!a),children:e.children})})};var Dt=e=>{let {item:t}=e;t.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:"Edit"})})};var go=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:i,isAlgoOrder:a}=e,n=t===types.OrderSide.BUY;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:!0,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((s,d)=>jsxRuntime.jsx(ui.Badge,{color:s.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:s},d)),n&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!n&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"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:[a&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Trigger price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:i??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?"Market":"--",children:e.isStopMarket?"Market":r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Qty."}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:!1,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: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 Mt=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,o=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,i=a=>{let n=e.baseTick;if(n&&n>0){let s=hooks.utils.formatNumber(a,n)??a;e.setQuantity(s);}};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:!0,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((a,n)=>jsxRuntime.jsx(ui.Badge,{color:a.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:a},n)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"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:"Last price"}),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:"Trigger price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.trigger_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:a=>e.setTriggerPrice(a),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.cn("oui-outline-line-12",e.errors?.trigger_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.order_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?"Market":e.price,onValueChange:a=>e.setPrice(a),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.cn("oui-outline-line-12",e.errors?.order_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Quantity"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:e.errors?.order_quantity?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:a=>{e.setQuantity(a);},onBlur:a=>i(a.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.cn("oui-outline-line-12",e.errors?.order_quantity?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:a=>{e.setSliderValue(a[0]);},color:"primary"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:!1,rule:"percentages",children:`${o??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primary",children:"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:!0,color:"secondary",onClick:a=>{e.onClose();},children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,onClick:a=>{a.stopPropagation(),a.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:"Confirm"})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:"Edit order",size:"xs",actions:{primary:{label:"Confirm",onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:!0},secondary:{label:"Cancel",onClick:e.onCloseDialog,fullWidth:!0}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(go,{...e})})]})};var Qt=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:i=!0,position:a}=e,{item:n}=t,{hide:s}=ui.useModal(),[d,l]=react.useState(!1),y=n?.algo_order_id!==void 0&&n.algo_type!==types.AlgoOrderRootType.BRACKET,u=n?.type==="MARKET"&&y;u||n?.type==="MARKET";let [N,_]=react.useState(!1),v=react.useMemo(()=>y&&n.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${n.type}`:n.type,[n,y]),[S,w]=hooks.useLocalStorage("orderly_order_confirm",!0),{base_dp:I,base_tick:k}=e.state,{formattedOrder:m,setValue:A,symbolInfo:D,markPrice:K,errors:f,validate:O,maxQty:F}=Un({order:n,orderType:v,position:a}),le=()=>{O().then(b=>{S?l(!0):Y(m);},b=>{b?.total?.message&&ui.toast.error(b?.total.message);}).catch(b=>{});},L=react.useCallback(()=>{l(!1);},[]),P=()=>m?Y(m):Promise.reject(),E=react.useCallback(()=>{s();},[]),Y=react.useCallback(async b=>{let z,ut=n.visible_quantity!==void 0?n.visible_quantity===0:n.visible!==void 0?n.visible===0:!1;if(n.algo_order_id!==void 0){if(u&&"order_price"in b){let{order_price:he,...ct}=b;b=ct;}z=r(n.algo_order_id.toString(),{...b});}else z=o(n.order_id.toString(),{...b,...ut?{visible_quantity:0}:{}});try{_(!0);let he=await z;E();}catch(he){ui.toast.error(he?.message??`${he}`);}finally{_(!1);}},[r,o]),ie=react.useMemo(()=>{let b=m.order_quantity;return b&&Number(b)!==0&&F!==0?new utils.Decimal(b).div(F).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[m.order_quantity,F]),Ce=n.price!=m.order_price||n.quantity!=m.order_quantity||n.trigger_price!=m.trigger_price,p=hooks.useThrottledCallback(b=>{let z=new utils.Decimal(b).div(100).mul(F).toDecimalPlaces(I,utils.Decimal.ROUND_DOWN).toNumber();A("order_quantity",hooks.utils.formatNumber(z,k));},50,{}),q=(b,z)=>{A(b,z);};return {...t,curMarkPrice:K,isAlgoOrder:y,isStopMarket:u,price:m.order_price,setPrice:b=>q("order_price",b),priceEdit:!u,triggerPrice:m.trigger_price,setTriggerPrice:b=>q("trigger_price",b),quantity:m.order_quantity,setQuantity:b=>{q("order_quantity",b);},maxQty:F,sliderValue:ie,setSliderValue:p,onClose:E,onSheetConfirm:le,errors:f,orderType:v,isChanged:Ce,baseTick:k,dialogOpen:d,setDialogOpen:l,onDialogConfirm:P,onCloseDialog:L,submitting:N,orderConfirm:S,setOrderConfirm:w}},Un=e=>{let{order:t,orderType:r,position:o}=e,[i,a]=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:n}=t,s=o?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),l=react.useMemo(()=>n?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,n,s]),{symbolInfo:y,markPrice:u,errors:h,validate:N}=hooks.useOrderEntity({...i,symbol:t.symbol},{maxQty:l});return {symbolInfo:y,markPrice:u,errors:h,validate:N,setValue:(v,S)=>{a(w=>({...w,[v]:S}));},formattedOrder:i,maxQty:l}};var $t=e=>{let t=Qt(e);return jsxRuntime.jsx(Mt,{...t})};var Kt=e=>{let{state:t}=e,{editAlgoOrder:r,editOrder:o}=G(),{order:i,position:a}=V(),n=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({title:"TP/SL",content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:!0,order:e.state.item,position:a,symbolInfo:e.state.origin})}).catch(s=>{}):ui.modal.sheet({title:"Edit order",classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx($t,{position:a,state:t,editAlgoOrder:r,editOrder:o})}).catch(s=>{});},[t]);return {...t,onShowEditSheet:n}};var Vt=e=>{let t=Kt(e);return jsxRuntime.jsx(Dt,{...t})};var Yt=e=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:t=>e.setOpen(!0),children:"Cancel"}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:"Cancel order",actions:{primary:{label:"Confirm",loading:e.isLoading,fullWidth:!0,size:"md",onClick:t=>{e.onCancel(t);}},secondary:{label:"Cancel",fullWidth:!0,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:"Are you sure you want to cancel your pending order."})})]});var Gt=e=>{let{state:t}=e,[r,o]=react.useState(!1),{onCancelOrder:i}=G(),[a,n]=react.useState(!1);return {...t,open:r,setOpen:o,onCancel:l=>i?(l?.preventDefault(),l?.stopPropagation(),n(!0),i(t.item).then(y=>{o(!1);},y=>{ui.toast.error(y.message);}).finally(()=>{n(!1);})):Promise.resolve(),onClose:()=>{o(!1);},isLoading:a}};var Jt=e=>{let t=Gt(e);return jsxRuntime.jsx(Yt,{...t})};var jt=e=>!e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ot,{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.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:!0,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \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(Oo,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Oo,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})}),Oo=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:!1,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 er=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[i,a]=react.useState(!1),{sl_trigger_price:n,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}=Ye(t);return {sl_trigger_price:n,tp_trigger_price:s,pnl:d,roi:l,quote_dp:r,open:i,setOpen:a}};var tr=e=>{let t=er(e);return jsxRuntime.jsx(jt,{...t})};var rr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(aa,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(sa,{...e}),e.type==="pending"&&jsxRuntime.jsx(tr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(la,{...e})]}),aa=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(Xr,{...e}),jsxRuntime.jsx(jr,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Zr,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(eo,{...e})]})]}),sa=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:da(e)}),la=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Vt,{state:e}),jsxRuntime.jsx(Jt,{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(vt,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(to,{...e}),jsxRuntime.jsx(At,{...e}),jsxRuntime.jsx(oo,{...e}),jsxRuntime.jsx(ro,{...e})]});case"tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(io,{...e}),jsxRuntime.jsx(ao,{...e}),jsxRuntime.jsx(lo,{...e}),jsxRuntime.jsx(no,{...e}),jsxRuntime.jsx(so,{...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(vt,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(At,{...e,align:"end"}),jsxRuntime.jsx(uo,{...e}),jsxRuntime.jsx(co,{...e}),jsxRuntime.jsx(mo,{...e})]})}}var or=e=>{let t=M();return {...e,...t}};var ir=e=>{let{className:t,...r}=e,o=or(r);return jsxRuntime.jsx(rr,{...o,className:t})};var nr=e=>{let t=Hr({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision});return jsxRuntime.jsx(gt,{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:r=>{e.onFilter(r);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(xa,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:t,loading:e.isLoading,dataSource:e.dataSource,bordered:!0,ignoreLoadingCheck:!0,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(r,o)=>({className:ui.cn("oui-h-[48px]",ee(r)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(r,o)=>`${e.type}${o}${r.order_id||r.algo_order_id}_index${o}`,renderRowContainer:(r,o,i)=>((e.type==="tp_sl"||e.type==="pending")&&(i=jsxRuntime.jsx(bt,{order:r,children:i})),jsxRuntime.jsx(pt,{symbol:r.symbol,children:i})),pagination:e.pagination,manualPagination:e.manualPagination})]})})},ar=e=>jsxRuntime.jsx(gt,{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(t=>t.type!=="select"?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ui.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.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(t,r)=>{let o=jsxRuntime.jsx(ir,{item:t,index:r,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange});return ["tp_sl","pending"].includes(e.type)&&(o=jsxRuntime.jsx(bt,{order:t,children:o})),jsxRuntime.jsx(pt,{symbol:t.symbol,children:o})}})]})}),xa=e=>jsxRuntime.jsx(ui.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 wo=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let i=e[o];if(i.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||i.algo_type===types.AlgoOrderRootType.TP_SL)if(i.algo_status!==types.OrderStatus.FILLED&&i.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let a=0;a<i.child_orders.length;a++){let n=i.child_orders[a];!n.is_activated||!n.trigger_price||(n.parent_algo_type=i.algo_type,r.push(n));}else for(let a=0;a<i.child_orders.length;a++){let n=i.child_orders[a];n&&(n.algo_status===types.OrderStatus.FILLED||n.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(n.parent_algo_type=i.algo_type,r.push(n));}else r.push(i);}return r},[e]);var dt=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=!1,onSymbolChange:i,filterConfig:a,pnlNotionalDecimalPrecision:n}=e,s=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),d=50,{page:l,pageSize:y,setPage:u,pagination:h,parsePagination:N}=ui.usePagination({pageSize:d});react.useEffect(()=>{u(1);},[e.symbol]);let{orderStatus:_,ordersSide:v,dateRange:S,filterItems:w,onFilter:I}=Ea(r,{ordersStatus:t,setPage:u,filterConfig:a}),k=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),m=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),[A,{isLoading:D,loadMore:K,cancelOrder:f,updateOrder:O,cancelAlgoOrder:F,updateAlgoOrder:le,cancelAllOrders:L,cancelAllTPSLOrders:P,meta:E,refresh:Y}]=hooks.useOrderStream({symbol:e.symbol,status:_,side:v,page:o||!s?void 0:l,size:s?y:500,dateRange:S,includes:k,excludes:m}),ie=`orderly_${r}_pageSize`,[Ce,p]=hooks.useLocalStorage(ie,d);react.useEffect(()=>{Ce!==y&&p(y);},[y,Ce]);let q=react.useCallback(()=>{let he=e.type==="pending"?"Cancel all pending orders":e.type==="tp_sl"?"Cancel all TP/SL orders":"",ct="Are you sure you want to cancel all of your pending orders?";ui.modal.confirm({title:he,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:ct}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await P():await L(),Y(),Promise.resolve(!0)}catch(lr){return lr?.message!==void 0&&toast.error(lr.message),Promise.resolve(!1)}finally{Promise.resolve();}}});},[r]),b=wo(A??[]),z=reactApp.useDataTap(r!=="tp_sl"?b:A)??void 0,ut=react.useMemo(()=>s?N(E):h,[E,s,N,h]);return {type:r,dataSource:z,isLoading:D,loadMore:K,cancelOrder:f,updateOrder:O,cancelAlgoOrder:F,updateAlgoOrder:le,pagination:ut,manualPagination:s,pnlNotionalDecimalPrecision:n,onFilter:I,filterItems:w,onCancelAll:q,onSymbolChange:i}},Ea=(e,t)=>{let[r,o]=react.useState(t.ordersStatus??"all"),[i,a]=react.useState(t.filterConfig?.side??"all"),n=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Eo({to:new Date,from:vo(dateFns.subDays(new Date,7))}):{}),[s,d]=react.useState(n),l=u=>{u.name==="side"&&(a(u.value),t.setPage(1)),u.name==="status"&&(o(u.value),t.setPage(1)),u.name==="dateRange"&&(d(Eo(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:i},h={type:"range",name:"dateRange",value:s},N={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,N,h];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,N,h]}},[e,i,r,s]),onFilter:l,ordersSide:i==="all"?void 0:i,dateRange:s,orderStatus:r==="all"?void 0:r}};function va(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function vo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Eo=e=>({from:va(e.from),to:vo(e.to)});var ge=e=>{let{testIds:t,...r}=e,o=dt(r);return jsxRuntime.jsx(nr,{...o,testIds:t})},Aa=e=>{let t=dt({...e,enableLoadMore:!0});return jsxRuntime.jsx(ar,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Ao=e=>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:"All",children:jsxRuntime.jsx(ge,{type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(ge,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(ge,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(ge,{type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(ge,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(ge,{type:"rejected",ordersStatus:types.OrderStatus.REJECTED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})})]});var ce=(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))(ce||{}),ka=e=>{let t=mt(e);return jsxRuntime.jsx(Ao,{...t})};
14
+ var mt=e=>{let{current:t,pnlNotionalDecimalPrecision:r}=e;return {current:t,pnlNotionalDecimalPrecision:r}};var j=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function de(e){if(typeof e.type<"u"){let t=new Array;if(e.parent_algo_type){if(e.algo_type===types.AlgoOrderType.STOP_LOSS){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","SL"]:["SL"];t.push(...i);}if(e.algo_type===types.AlgoOrderType.TAKE_PROFIT){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","TP"]:["TP"];t.push(...i);}return t}(typeof e.type=="string"?[e.type.replace("_ORDER","").toLowerCase()]:[e.type]).map(i=>j(i));let o=typeof e.type=="string"?e.type.replace("_ORDER","").toLowerCase():j(e.type);return e.algo_order_id===void 0||e.algo_order_id&&e.algo_type==="BRACKET"?[j(o)]:[`Stop ${o}`]}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(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!i.trigger_price),o=e?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS&&!!i.trigger_price);return (r||o)&&t.push(r&&o?"TP/SL":r?"TP":"SL"),t}}function ee(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function Fo(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(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function Ye(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=Fo(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let i=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,a=r?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),n=o?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0,d=n?hooks.utils.calcTPSL_ROI({pnl:n,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:a,slPnL:n},roi:{tpRoi:s,slRoi:d}}}var mr=react.createContext({}),M=()=>react.useContext(mr),pt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(mr.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 fr=react.createContext({}),G=()=>react.useContext(fr),gt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:i}=e,a=hooks.useSymbolsInfo(),n=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(()=>{}),[]),s=react.useCallback(async(l,y)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:!1;await ui.modal.sheet({title:"Edit Order",classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[]),d=react.useCallback((l,y,u)=>{let{min_notional:h}=a[l]();return hooks.checkNotional(y,u,h)},[a]);return jsxRuntime.jsx(fr.Provider,{value:{onCancelOrder:n,onEditOrder:s,editOrder:r,editAlgoOrder:i,checkMinNotional:d},children:e.children})};var br=react.createContext({}),V=()=>react.useContext(br),bt=e=>{let{quote_dp:t}=M(),[r,o]=react.useState(),[i]=hooks.useMutation("/v1/algo/order","DELETE"),[a]=hooks.useMutation("/v1/algo/order","PUT"),n=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),l=async S=>i(null,{order_id:S.algo_order_id,symbol:S.symbol}),y=async(S,w)=>a({order_id:S.algo_order_id,child_orders:S.child_orders.map(I=>({order_id:I.algo_order_id,quantity:w.order_quantity}))}),u=S=>n.cache.get(d)?.data.rows.find(I=>I.symbol===S),{sl_trigger_price:h,tp_trigger_price:N,tpPnL:_,slPnL:v}=jo({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??!1)){let S=u(e.order.symbol);S&&o(S);}},[e.order.symbol]),jsxRuntime.jsx(br.Provider,{value:{order:e.order,sl_trigger_price:h,tp_trigger_price:N,tpPnL:_,slPnL:v,onCancelOrder:l,onUpdateOrder:y,getRelatedPosition:u,position:r},children:e.children})};function jo(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:i,tp_trigger_price:a}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),n=t.quantity;n===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(n=r.position_qty);let s=r.average_open_price,d=typeof n=="number"&&typeof a=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:n,price:a,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,l=typeof n=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:n,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:i,tp_trigger_price:a,slPnL:l,tpPnL:d}}var Ne=e=>{let{type:t,base:r,value:o,cancelPopover:i,isSubmitting:a,onConfirm:n}=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(o)}),"."]}),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:i,disabled:a,children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:a,onClick:n,children:"Confirm"})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:i,children:jsxRuntime.jsx(ui.CloseIcon,{size:18})})]})};var we=e=>{let{inputRef:t,dp:r,value:o,setValue:i,setEditing:a,error:n,handleKeyDown:s,onClick:d,onClose:l,onFocus:y,onBlur:u,hintInfo:h}=e;react.useEffect(()=>{let _=t.current;if(_){let v=_.value.length;_.setSelectionRange(v,v);}a(!0);},[]);let N=(h?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:h,open:N,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:_=>i(_),helpText:n,onClick:_=>{_.stopPropagation(),_.preventDefault();},autoComplete:"off",onFocus:y,onBlur:u,onKeyDown:s,autoFocus:!0,color:N?"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 Ot=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[i,a]=react.useState(t.quantity.toString()),[n,s]=react.useState(!1);react.useEffect(()=>{m(t.quantity.toString());},[e.order.quantity]);let[d,l]=react.useState(!1),[y,u]=react.useState(),{editOrder:h,editAlgoOrder:N,checkMinNotional:_}=G(),{onUpdateOrder:v,position:S}=V(),{base_dp:w,base:I,base_tick:k}=M(),m=async(p,q)=>{a(p);let b=Math.abs(S?.position_qty||0);if(S&&o&&Number(p)>b)u(`Quantity should be less than position quantity : ${b}`);else {let z=Number(p);q&&z>q?u(`Quantity should be less than ${utils.commifyOptional(q,{fix:w})}`):u(void 0);}return Promise.resolve()},A=()=>{l(!1),s(!1);},D=()=>{l(!1),m(t.quantity.toString()),s(!1);},[K,f]=react.useState(!1),O=react.useRef(null),F=()=>{if(y)return;if(Number(i)===Number(t.quantity)){s(!1);return}let p=t.algo_order_id!==void 0?t.trigger_price:t.price;if(p!==null&&t.reduce_only!==!0){let q=_(t.symbol,p,i);if(q){ui.toast.error(q),f(!1),D();return}}l(!0);},le=p=>{p?.stopPropagation(),p?.preventDefault(),F();},L=p=>{p.key==="Enter"&&(p?.stopPropagation(),p?.preventDefault(),F());},P=react.useCallback(()=>{f(!0);let p={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:i,algo_order_id:t.algo_order_id};if(typeof p.algo_order_id<"u"&&p.order_type==="MARKET"){let{order_price:b,...z}=p;p=z;}typeof t.reduce_only<"u"&&(p.reduce_only=t.reduce_only),t.order_tag!==void 0&&(p={...p,order_tag:t.order_tag}),t?.visible_quantity===0&&(p.visible_quantity=0),t?.tag!==void 0&&(p.order_tag=t.tag);let q;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?q=v(t,p):t.algo_order_id!==void 0?q=N(t.algo_order_id.toString(),p):q=h(t.order_id.toString(),p),q.then(b=>{A(),m(i.toString());},b=>{ui.toast.error(b.message),m(t.quantity.toString()),D();}).finally(()=>f(!1));},[i]),E=react.useRef(null),Y=react.useRef(null),ie=p=>{E.current&&Y.current&&!E.current.contains(p.target)&&!Y.current.contains(p.target)&&!d&&D();};react.useEffect(()=>(document.addEventListener("mousedown",ie),()=>{document.removeEventListener("mousedown",ie);}),[d,t.quantity]);let Ce=()=>!n||e.disableEdit?jsxRuntime.jsx(Pi,{order:t,quantity:i,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(_i,{inputRef:O,quantitySliderRef:Y,base_dp:w,base_tick:k,quantity:i,setQuantity:m,editing:n,setEditing:s,handleKeyDown:L,onClick:le,onClose:D,symbol:t.symbol,reduce_only:o,positionQty:S?.position_qty,error:y,confirmOpen:d,side:t.side,order:t,setError:u});return jsxRuntime.jsx(ui.Popover,{open:d,onOpenChange:l,content:jsxRuntime.jsx(Ne,{type:0,base:I,value:i,cancelPopover:D,isSubmitting:K,onConfirm:P}),contentProps:{onOpenAutoFocus:p=>{}},children:jsxRuntime.jsx("div",{onClick:p=>{p.stopPropagation(),p.preventDefault();},ref:E,children:Ce()})})},Pi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:i=>{i.stopPropagation(),i.preventDefault(),e.setEditing(!0);},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})})]})},_i=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:i,quantity:a,setQuantity:n,editing:s,setEditing:d,handleKeyDown:l,onClick:y,onClose:u,error:h,symbol:N,reduce_only:_,positionQty:v,confirmOpen:S,side:w,order:I}=e,k=hooks.useMaxQty(N,I.side,I.reduce_only),m=react.useMemo(()=>_?Math.abs(v??0):I.quantity+Math.abs(k),[I.quantity,k,_,v]),[A,D]=react.useState(void 0);react.useEffect(()=>{if(A===void 0){let f=new utils.Decimal(a).div(m).abs().mul(100).toNumber();D(f);}},[A,m,a]);let K=async f=>(i>0&&(f=hooks.utils.formatNumber(f,i)??f),n(`${f}`,m));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!S,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(we,{inputRef:t,dp:o,value:a,setValue:f=>{let O=Math.abs(Math.min(Number(f),m)).toString();if(n(f,m),f.endsWith("."))return;if(Number(O)===0){D(0);return}let F=new utils.Decimal(f).div(m).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();D(Math.min(100,F));},setEditing:d,handleKeyDown:l,onClick:y,onClose:u,onBlur:f=>{K(f.target.value);},hintInfo:h})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:f=>{f.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:!1,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${A}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[A??0],onValueChange:f=>{let O=Array.from(f.values());D(O[0]);let F=new utils.Decimal(O[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);n(F,m);},onValueCommit:f=>{let O=new utils.Decimal(f[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);K(O).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Oi,{onClick:f=>{D(f*100);let O=new utils.Decimal(f).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);O=hooks.utils.formatNumber(O,i)??O,n(O,m),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(O.length,O.length);},100);}})]})]})})]})},Oi=e=>jsxRuntime.jsx(ui.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,o)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(r.value);},className:"oui-w-1/5",children:r.label},o))});var Er=e=>{let{order:t}=e,[r,o]=react.useState(t.price?.toString()??"Market"),[i,a]=react.useState(!1),[n,s]=react.useState(!1),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[y,u]=react.useState(!1),{editOrder:h,editAlgoOrder:N,checkMinNotional:_}=G(),{base:v,quote_dp:S}=M(),w=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),I=()=>{a(!1),s(!1);},k=()=>{a(!1),o(t.price?.toString()??"Market"),s(!1);},m=react.useMemo(()=>!w||l||!n?"":Number(r)>w.max?`Price can not be greater than ${w.max} USDC.`:Number(r)<w.min?`Price can not be less than ${w.min} USDC.`:"",[l,n,w,r]),A=P=>{if(P?.stopPropagation(),P?.preventDefault(),!(m.length>0)){if(r===`${t.price}`){s(!1);return}if(t.reduce_only!==!0){let E=_(t.symbol,r,t.quantity);if(E){ui.toast.error(E),u(!1),k();return}}a(!0);}},D=P=>{P.key==="Enter"&&A(P);},K=()=>{u(!0);let P=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&&(P=t.algo_order_id,E={...E,order_id:P,price:r,algo_order_id:P}),t?.visible_quantity===0&&(E.visible_quantity=0),t.tag!==void 0&&(E.order_tag=t.tag);let Y;t.algo_order_id!==void 0?Y=N(t.algo_order_id.toString(),E):Y=h(t.order_id.toString(),E),Y.then(ie=>{I(),o(r);},ie=>{ui.toast.error(ie.message),k();}).finally(()=>u(!1));},f=react.useRef(null);react.useEffect(()=>{e.order.price&&o(`${e.order.price}`);},[e.order.price]);let O=react.useRef(null),F=P=>{O.current&&!O.current.contains(P.target)&&!i&&k();};if(react.useEffect(()=>(document.addEventListener("mousedown",F),()=>{document.removeEventListener("mousedown",F);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let L=()=>!n||e.disableEdit?jsxRuntime.jsx(vi,{order:t,price:r,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:f,dp:S,value:r,setValue:o,setEditing:s,handleKeyDown:D,onClick:A,onClose:k,hintInfo:m});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(Ne,{type:1,base:v,value:r,cancelPopover:k,isSubmitting:y,onConfirm:K}),children:jsxRuntime.jsx("div",{onClick:P=>{P.stopPropagation(),P.preventDefault();},ref:O,children:L()})})},vi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},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 kr=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let i=t?.algo_order_id!==void 0,a=t?.algo_type==="BRACKET",[n,s]=react.useState(!1),[d,l]=react.useState(!1),[y,u]=react.useState(!1),{editAlgoOrder:h,checkMinNotional:N}=G(),{base:_,quote_dp:v,quote_max:S,quote_min:w}=M(),I=react.useMemo(()=>{if(!((!i||a)&&!d)){if(Number(r)>S)return `Trigger price must be less than ${S}`;if(Number(r)<w)return `Trigger price must be greater than ${w}`}},[d,r,i,a]),k=()=>{s(!1),l(!1);},m=()=>{o(t.trigger_price?.toString()??"0"),s(!1),l(!1);},A=react.useRef(null),D=L=>{A.current&&!A.current.contains(L.target)&&!n&&m();};react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[n,t.trigger_price]);let K=L=>{if(L?.stopPropagation(),L?.preventDefault(),l(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let P=N(t.symbol,t.price,t.quantity);if(P){ui.toast.error(P),u(!1),m();return}}s(!0);}},f=L=>{L.key==="Enter"&&K(L);},O=()=>{if((I??"").length>0)return;u(!0);let L={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(L={...L,order_tag:t.order_tag}),h(`${t.algo_order_id}`,L).then(P=>{k(),o(r);},P=>{ui.toast.error(P.message),o(t.trigger_price?.toString()??"--"),m();}).finally(()=>u(!1));},F=react.useRef(null);if(!i||a)return jsxRuntime.jsx(ui.Text,{children:"--"});let le=()=>!d||e.disableEdit?jsxRuntime.jsx(Fi,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:F,dp:v,value:r,setValue:o,setEditing:l,handleKeyDown:f,onClick:K,onClose:m,hintInfo:I});return jsxRuntime.jsx(ui.Popover,{open:n,onOpenChange:s,content:jsxRuntime.jsx(Ne,{type:2,base:_,value:r,cancelPopover:m,isSubmitting:y,onConfirm:O}),children:jsxRuntime.jsx("div",{onClick:L=>{L.stopPropagation(),L.preventDefault();},ref:A,children:le()})})},Fi=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",ee(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},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 Ze=e=>{let{order:t}=e,{onCancelOrder:r}=G(),[o,i]=react.useState(!1);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{r&&(a.preventDefault(),a.stopPropagation(),i(!0),r(t).then(n=>n,n=>{ui.toast.error(n.message);}).finally(()=>{i(!1);}));},loading:o,children:"Cancel"})};var qr=e=>{let{record:t}=e,[r,o]=react.useState(!1),[i,{data:a,error:n,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),y=react.useCallback(()=>{o(!1);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),i(u);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:u=>{d||(u.preventDefault(),u.stopPropagation(),y());},children:"Renew"})};var Mr=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=V();return jsxRuntime.jsx(Yi,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},Yi=e=>{let{direction:t="row",order:r,position:o}=e,i=hooks.useSymbolsInfo(),a=react.useMemo(()=>{let d=[];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&&d.push(jsxRuntime.jsx(Br,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:i[r.symbol]()},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(Br,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:i[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:d})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),n=react.useMemo(()=>{let d=[];return r?.symbol?(e.takeProfitPrice&&d.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:i[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.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:i[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.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:n});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",tooltipProps:{arrow:{className:"oui-fill-base-5"}},children:s}):s},Br=e=>{let{qty:t,price:r,entryPrice:o,orderSide:i,orderType:a,symbolInfo:n}=e,s=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:i,orderType:a},{symbol:n}),d=a===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.Text.numeral,{rule:"price",dp:n.quote_dp,padding:!1,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 zr=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=M(),{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:n,roi:s}=Ye(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof n.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:!0,children:n.tpPnL}),typeof n.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:n.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Ur,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(Ur,{type:"SL",value:i,quote_dp:r})]})})},Ur=e=>{let{type:t,value:r,quote_dp:o}=e;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}`,"\xA0-\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Qr=e=>{let{position:t,order:r}=V(),{quote_dp:o,base_dp:i}=M();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:i,position:t,order:r,label:"Edit",isEditing:!0})};var $r=()=>{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]})};var Hr=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o}=e;return react.useMemo(()=>{switch(t){case"all":return [be({width:130,showType:!0,onSymbolChange:r,enableSort:!1}),Ee({width:130,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),ve({width:130,title:"Order price",disableEdit:!0,enableSort:!1}),et({width:130,enableSort:!1}),Kr({width:130}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:130,enableSort:!1}),ze({width:130}),Qe({width:130}),xe({width:130}),Ae({width:130}),Vr({width:130})];case"pending":return [be({width:172,showType:!0,onSymbolChange:r,enableSort:!1}),Ee({width:162,className:"oui-pr-0",enableSort:!1}),ve({width:162,className:"oui-pr-0",enableSort:!1}),We({width:162,className:"oui-pr-0"}),mn({width:130}),Ie({width:162,isPending:!0}),xe({width:162}),Ae({width:162}),Ue({width:162,enableSort:!1}),fn({width:162})];case"tp_sl":return [be({width:176,showType:!0,onSymbolChange:r,enableSort:!1}),dn({width:176}),Kr({width:176}),un({width:176,disableEdit:!0}),pn({width:176}),xe({width:176}),Ue({width:176,enableSort:!1}),gn({width:176})];case"filled":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),ve({width:124,title:"Order price",disableEdit:!0}),cn({width:124}),We({width:124,disableEdit:!0}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:124})];case"cancelled":return [be({showType:!0,width:154,onSymbolChange:r,enableSort:!1}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),ve({width:124,disableEdit:!0,enableSort:!1}),et({width:124,enableSort:!1}),We({width:124,disableEdit:!0}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124})];case"rejected":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),ve({width:124,disableEdit:!0}),et({width:124}),We({width:124,disableEdit:!0}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:124})];case"orderHistory":return [be({showType:!0,width:154,onSymbolChange:r}),Ee({width:150,disableEdit:!0,className:"oui-pl-6 oui-pr-0"}),ve({width:124,disableEdit:!0}),et({width:124}),We({width:124,disableEdit:!0}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),ze({width:124}),Qe({width:124}),xe({width:124}),Ae({width:124}),Ue({width:150}),Vr({width:80})]}},[t,o])};function be(e){return {title:"Instrument",dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,render:(t,r)=>{let o=ee(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:i=>{e?.onSymbolChange?.({symbol:t}),i.stopPropagation(),i.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(r)?.map((i,a)=>jsxRuntime.jsx(ui.Badge,{color:i.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",children:i},a))})]})]})}}}function Ee(e){return {title:"Filled / Quantity",dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return $e(o,i)}:void 0,render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(Ot,{order:r,disableEdit:e?.disableEdit})}}function dn(e){return {title:"Quantity",className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return $e(o,i)}:void 0,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Ot,{order:r})}}function ve(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r,o)=>$e(t.price??0,r.price??0):void 0,render:(t,r)=>jsxRuntime.jsx(Er,{order:r,disableEdit:e?.disableEdit})}}function un(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx($r,{})}}function cn(e){return {title:"Avg. price",dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:utils.commifyOptional(t)})}}function We(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(kr,{order:r,disableEdit:e?.disableEdit})}}function Kr(e){return {title:e?.title??"Trigger",className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Mr,{})}}function mn(e){return {title:"TP/SL",className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(zr,{order:r})}}function Ie(e){return {title:"Notional",dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??!1?(t,r,o)=>{let i=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,a=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 $e(i,a)}:void 0,render:(t,r)=>{if(e?.isPending){let o=()=>r.price&&r.quantity?new utils.Decimal(r.price).mul(r.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--";return jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,children:o()})}return r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?"--":`${r.total_executed_quantity*r.average_executed_price}`})}}}function Lt(e){return {title:"Real. PnL",dataIndex:"realized_pnl",width:e?.width,className:e?.className,render:t=>{let{quote_dp:r}=M(),o=e?.pnlNotionalDecimalPrecision??r,i=new utils.Decimal(t??0).toDecimalPlaces(o,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsx(ui.Text.numeral,{dp:o,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"})}}}function xe(e){return {title:"Reduce only",dataIndex:"reduce_only",width:e?.width,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text,{children:t?"Yes":"No"})}}function Ae(e){return {title:"Hidden",dataIndex:"visible",width:e?.width,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?"No":"Yes"})}}function Ue(e){return {title:"Order time",dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,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 ze(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function pn(e){return {title:"Notional",dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":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 Qe(e){return {title:"Status",dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>{let o=t||r.algo_status;return o==="NEW"?j("pending"):j(o)}}}function et(e){return {title:"Avg. open",dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>$e(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.average_executed_price})}}function Vr(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(qr,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(Ze,{order:r}):null}}function fn(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(Ze,{order:r})}}function gn(e){return {title:"",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(Qr,{order:r}),jsxRuntime.jsx(Ze,{order:r})]})}}function $e(e,t){return e>t?1:e<t?-1:0}var Xr=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY;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:r?"Buy":"Sell"}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Zr=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}`:j(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(e.item)?.map((o,i)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},i))})},jr=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})},eo=e=>{let{item:t}=e,r=t.status||t.algo_status,o=()=>r==="NEW"?j("pending"):j(r);return jsxRuntime.jsx(ui.Text.formatted,{intensity:36,size:"2xs",children:o()})},vt=e=>{let{item:t}=e,r=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:"Qty.",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:!1,coloring:!0,placeholder:"Entire position",intensity:80,children:r?"--":t.quantity})})},It=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:"Filled"}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var to=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.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:["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:!0,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:r})})},At=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Trigger price",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:!1,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},ro=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Mark price",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:!1,children:t.mark_price})})},oo=e=>{let{item:t}=e,r=t?.algo_order_id!==void 0,o=t?.type==="MARKET"&&r;return jsxRuntime.jsx(ui.Statistic,{label:"Limit price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:o?jsxRuntime.jsx(ui.Text,{children:"Market"}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.price??"--"})})},io=e=>{let{tp_trigger_price:t,tpPnL:r}=V();return jsxRuntime.jsx(ui.Statistic,{label:"TP trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ot,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:!0,prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"TP PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,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:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},no=e=>{let{sl_trigger_price:t,slPnL:r}=V();return jsxRuntime.jsx(ui.Statistic,{label:"SL trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ot,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"SL PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,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:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},ao=e=>jsxRuntime.jsx(ui.Statistic,{label:"TP price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),so=e=>jsxRuntime.jsx(ui.Statistic,{label:"SL price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),lo=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.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.quantity}),[t]);return jsxRuntime.jsx(ui.Statistic,{label:"Quantity",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:r})},uo=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Avg price",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:!1,children:e.item?.average_executed_price??"--"})}),co=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Order price",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:!1,placeholder:"Market",children:e.item?.price??"--"})}),mo=e=>{let t=e?.item?.realized_pnl;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Real. PnL",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"})})},ot=e=>{let{classNames:t,content:r}=e,[o,i]=react.useState(!1);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:i,tooltipProps:{arrow:{className:t?.arrow}},children:jsxRuntime.jsx("div",{onClick:()=>i(a=>!a),children:e.children})})};var Dt=e=>{let {item:t}=e;t.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:"Edit"})})};var go=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:i,isAlgoOrder:a}=e,n=t===types.OrderSide.BUY;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:!0,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((s,d)=>jsxRuntime.jsx(ui.Badge,{color:s.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:s},d)),n&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!n&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"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:[a&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Trigger price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:i??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?"Market":"--",children:e.isStopMarket?"Market":r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Qty."}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:!1,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: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 Mt=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,o=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,i=a=>{let n=e.baseTick;if(n&&n>0){let s=hooks.utils.formatNumber(a,n)??a;e.setQuantity(s);}};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:!0,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((a,n)=>jsxRuntime.jsx(ui.Badge,{color:a.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:a},n)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"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:"Last price"}),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:"Trigger price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.trigger_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:a=>e.setTriggerPrice(a),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.cn("oui-outline-line-12",e.errors?.trigger_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.order_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?"Market":e.price,onValueChange:a=>e.setPrice(a),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.cn("oui-outline-line-12",e.errors?.order_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Quantity"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:e.errors?.order_quantity?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:a=>{e.setQuantity(a);},onBlur:a=>i(a.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.cn("oui-outline-line-12",e.errors?.order_quantity?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:a=>{e.setSliderValue(a[0]);},color:"primary"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:!1,rule:"percentages",children:`${o??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primary",children:"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:!0,color:"secondary",onClick:a=>{e.onClose();},children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,onClick:a=>{a.stopPropagation(),a.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:"Confirm"})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:"Edit order",size:"xs",actions:{primary:{label:"Confirm",onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:!0},secondary:{label:"Cancel",onClick:e.onCloseDialog,fullWidth:!0}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(go,{...e})})]})};var Qt=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:i=!0,position:a}=e,{item:n}=t,{hide:s}=ui.useModal(),[d,l]=react.useState(!1),y=n?.algo_order_id!==void 0&&n.algo_type!==types.AlgoOrderRootType.BRACKET,u=n?.type==="MARKET"&&y;u||n?.type==="MARKET";let [N,_]=react.useState(!1),v=react.useMemo(()=>y&&n.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${n.type}`:n.type,[n,y]),[S,w]=hooks.useLocalStorage("orderly_order_confirm",!0),{base_dp:I,base_tick:k}=e.state,{formattedOrder:m,setValue:A,symbolInfo:D,markPrice:K,errors:f,validate:O,maxQty:F}=Un({order:n,orderType:v,position:a}),le=()=>{O().then(b=>{S?l(!0):Y(m);},b=>{b?.total?.message&&ui.toast.error(b?.total.message);}).catch(b=>{});},L=react.useCallback(()=>{l(!1);},[]),P=()=>m?Y(m):Promise.reject(),E=react.useCallback(()=>{s();},[]),Y=react.useCallback(async b=>{let z,ut=n.visible_quantity!==void 0?n.visible_quantity===0:n.visible!==void 0?n.visible===0:!1;if(n.algo_order_id!==void 0){if(u&&"order_price"in b){let{order_price:he,...ct}=b;b=ct;}z=r(n.algo_order_id.toString(),{...b});}else z=o(n.order_id.toString(),{...b,...ut?{visible_quantity:0}:{}});try{_(!0);let he=await z;E();}catch(he){ui.toast.error(he?.message??`${he}`);}finally{_(!1);}},[r,o]),ie=react.useMemo(()=>{let b=m.order_quantity;return b&&Number(b)!==0&&F!==0?new utils.Decimal(b).div(F).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[m.order_quantity,F]),Ce=n.price!=m.order_price||n.quantity!=m.order_quantity||n.trigger_price!=m.trigger_price,p=hooks.useThrottledCallback(b=>{let z=new utils.Decimal(b).div(100).mul(F).toDecimalPlaces(I,utils.Decimal.ROUND_DOWN).toNumber();A("order_quantity",hooks.utils.formatNumber(z,k));},50,{}),q=(b,z)=>{A(b,z);};return {...t,curMarkPrice:K,isAlgoOrder:y,isStopMarket:u,price:m.order_price,setPrice:b=>q("order_price",b),priceEdit:!u,triggerPrice:m.trigger_price,setTriggerPrice:b=>q("trigger_price",b),quantity:m.order_quantity,setQuantity:b=>{q("order_quantity",b);},maxQty:F,sliderValue:ie,setSliderValue:p,onClose:E,onSheetConfirm:le,errors:f,orderType:v,isChanged:Ce,baseTick:k,dialogOpen:d,setDialogOpen:l,onDialogConfirm:P,onCloseDialog:L,submitting:N,orderConfirm:S,setOrderConfirm:w}},Un=e=>{let{order:t,orderType:r,position:o}=e,[i,a]=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:n}=t,s=o?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),l=react.useMemo(()=>n?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,n,s]),{symbolInfo:y,markPrice:u,errors:h,validate:N}=hooks.useOrderEntity({...i,symbol:t.symbol},{maxQty:l});return {symbolInfo:y,markPrice:u,errors:h,validate:N,setValue:(v,S)=>{a(w=>({...w,[v]:S}));},formattedOrder:i,maxQty:l}};var $t=e=>{let t=Qt(e);return jsxRuntime.jsx(Mt,{...t})};var Kt=e=>{let{state:t}=e,{editAlgoOrder:r,editOrder:o}=G(),{order:i,position:a}=V(),n=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({title:"TP/SL",content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:!0,order:e.state.item,position:a,symbolInfo:e.state.origin})}).catch(s=>{}):ui.modal.sheet({title:"Edit order",classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx($t,{position:a,state:t,editAlgoOrder:r,editOrder:o})}).catch(s=>{});},[t]);return {...t,onShowEditSheet:n}};var Vt=e=>{let t=Kt(e);return jsxRuntime.jsx(Dt,{...t})};var Yt=e=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:t=>e.setOpen(!0),children:"Cancel"}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:"Cancel order",actions:{primary:{label:"Confirm",loading:e.isLoading,fullWidth:!0,size:"md",onClick:t=>{e.onCancel(t);}},secondary:{label:"Cancel",fullWidth:!0,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:"Are you sure you want to cancel your pending order."})})]});var Gt=e=>{let{state:t}=e,[r,o]=react.useState(!1),{onCancelOrder:i}=G(),[a,n]=react.useState(!1);return {...t,open:r,setOpen:o,onCancel:l=>i?(l?.preventDefault(),l?.stopPropagation(),n(!0),i(t.item).then(y=>{o(!1);},y=>{ui.toast.error(y.message);}).finally(()=>{n(!1);})):Promise.resolve(),onClose:()=>{o(!1);},isLoading:a}};var Jt=e=>{let t=Gt(e);return jsxRuntime.jsx(Yt,{...t})};var jt=e=>!e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ot,{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.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:!0,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \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(Oo,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Oo,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})}),Oo=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:!1,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 er=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[i,a]=react.useState(!1),{sl_trigger_price:n,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}=Ye(t);return {sl_trigger_price:n,tp_trigger_price:s,pnl:d,roi:l,quote_dp:r,open:i,setOpen:a}};var tr=e=>{let t=er(e);return jsxRuntime.jsx(jt,{...t})};var rr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(aa,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(sa,{...e}),e.type==="pending"&&jsxRuntime.jsx(tr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(la,{...e})]}),aa=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(Xr,{...e}),jsxRuntime.jsx(jr,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Zr,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(eo,{...e})]})]}),sa=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:da(e)}),la=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Vt,{state:e}),jsxRuntime.jsx(Jt,{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(vt,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(to,{...e}),jsxRuntime.jsx(At,{...e}),jsxRuntime.jsx(oo,{...e}),jsxRuntime.jsx(ro,{...e})]});case"tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(io,{...e}),jsxRuntime.jsx(ao,{...e}),jsxRuntime.jsx(lo,{...e}),jsxRuntime.jsx(no,{...e}),jsxRuntime.jsx(so,{...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(vt,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(At,{...e,align:"end"}),jsxRuntime.jsx(uo,{...e}),jsxRuntime.jsx(co,{...e}),jsxRuntime.jsx(mo,{...e})]})}}var or=e=>{let t=M();return {...e,...t}};var ir=e=>{let{className:t,...r}=e,o=or(r);return jsxRuntime.jsx(rr,{...o,className:t})};var nr=e=>{let t=Hr({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision});return jsxRuntime.jsx(gt,{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:r=>{e.onFilter(r);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(xa,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:t,loading:e.isLoading,dataSource:e.dataSource,bordered:!0,ignoreLoadingCheck:!0,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(r,o)=>({className:ui.cn("oui-h-[48px]",ee(r)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(r,o)=>`${e.type}${o}${r.order_id||r.algo_order_id}_index${o}`,renderRowContainer:(r,o,i)=>((e.type==="tp_sl"||e.type==="pending")&&(i=jsxRuntime.jsx(bt,{order:r,children:i})),jsxRuntime.jsx(pt,{symbol:r.symbol,children:i})),pagination:e.pagination,manualPagination:e.manualPagination})]})})},ar=e=>jsxRuntime.jsx(gt,{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(t=>t.type!=="select"?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ui.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.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(t,r)=>{let o=jsxRuntime.jsx(ir,{item:t,index:r,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange});return ["tp_sl","pending"].includes(e.type)&&(o=jsxRuntime.jsx(bt,{order:t,children:o})),jsxRuntime.jsx(pt,{symbol:t.symbol,children:o})}})]})}),xa=e=>jsxRuntime.jsx(ui.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 wo=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let i=e[o];if(i.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||i.algo_type===types.AlgoOrderRootType.TP_SL)if(i.algo_status!==types.OrderStatus.FILLED&&i.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let a=0;a<i.child_orders.length;a++){let n=i.child_orders[a];!n.is_activated||!n.trigger_price||(n.parent_algo_type=i.algo_type,r.push(n));}else for(let a=0;a<i.child_orders.length;a++){let n=i.child_orders[a];n&&(n.algo_status===types.OrderStatus.FILLED||n.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(n.parent_algo_type=i.algo_type,r.push(n));}else r.push(i);}return r},[e]);var dt=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=!1,onSymbolChange:i,filterConfig:a,pnlNotionalDecimalPrecision:n}=e,s=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),d=50,{page:l,pageSize:y,setPage:u,pagination:h,parsePagination:N}=ui.usePagination({pageSize:d});react.useEffect(()=>{u(1);},[e.symbol]);let{orderStatus:_,ordersSide:v,dateRange:S,filterItems:w,onFilter:I}=Ea(r,{ordersStatus:t,setPage:u,filterConfig:a}),k=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),m=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),[A,{isLoading:D,loadMore:K,cancelOrder:f,updateOrder:O,cancelAlgoOrder:F,updateAlgoOrder:le,cancelAllOrders:L,cancelAllTPSLOrders:P,meta:E,refresh:Y}]=hooks.useOrderStream({symbol:e.symbol,status:_,side:v,page:o||!s?void 0:l,size:s?y:500,dateRange:S,includes:k,excludes:m}),ie=`orderly_${r}_pageSize`,[Ce,p]=hooks.useLocalStorage(ie,d);react.useEffect(()=>{Ce!==y&&p(y);},[y,Ce]);let q=react.useCallback(()=>{let he=e.type==="pending"?"Cancel all pending orders":e.type==="tp_sl"?"Cancel all TP/SL orders":"",ct="Are you sure you want to cancel all of your pending orders?";ui.modal.confirm({title:he,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:ct}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await P():await L(),Y(),Promise.resolve(!0)}catch(lr){return lr?.message!==void 0&&toast.error(lr.message),Promise.resolve(!1)}finally{Promise.resolve();}}});},[r]),b=wo(A??[]),z=reactApp.useDataTap(r!=="tp_sl"?b:A)??void 0,ut=react.useMemo(()=>s?N(E):h,[E,s,N,h]);return {type:r,dataSource:z,isLoading:D,loadMore:K,cancelOrder:f,updateOrder:O,cancelAlgoOrder:F,updateAlgoOrder:le,pagination:ut,manualPagination:s,pnlNotionalDecimalPrecision:n,onFilter:I,filterItems:w,onCancelAll:q,onSymbolChange:i}},Ea=(e,t)=>{let[r,o]=react.useState(t.ordersStatus??"all"),[i,a]=react.useState(t.filterConfig?.side??"all"),n=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Eo({to:new Date,from:vo(dateFns.subDays(new Date,7))}):{}),[s,d]=react.useState(n),l=u=>{u.name==="side"&&(a(u.value),t.setPage(1)),u.name==="status"&&(o(u.value),t.setPage(1)),u.name==="dateRange"&&(d(Eo(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:i},h={type:"range",name:"dateRange",value:s},N={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,N,h];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,N,h]}},[e,i,r,s]),onFilter:l,ordersSide:i==="all"?void 0:i,dateRange:s,orderStatus:r==="all"?void 0:r}};function va(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function vo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Eo=e=>({from:va(e.from),to:vo(e.to??e.from)});var ge=e=>{let{testIds:t,...r}=e,o=dt(r);return jsxRuntime.jsx(nr,{...o,testIds:t})},Aa=e=>{let t=dt({...e,enableLoadMore:!0});return jsxRuntime.jsx(ar,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Ao=e=>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:"All",children:jsxRuntime.jsx(ge,{type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(ge,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(ge,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(ge,{type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(ge,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(ge,{type:"rejected",ordersStatus:types.OrderStatus.REJECTED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})})]});var ce=(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))(ce||{}),ka=e=>{let t=mt(e);return jsxRuntime.jsx(Ao,{...t})};
15
15
 
16
16
  exports.DesktopOrderList = nr;
17
17
  exports.DesktopOrderListWidget = ge;