@orderly.network/ui-orders 2.0.1-alpha.2 → 2.0.1-alpha.4

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,15 +11,15 @@ 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 ct=e=>{let{current:t,pnlNotionalDecimalPrecision:r}=e;return {current:t,pnlNotionalDecimalPrecision:r}};var Z=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=>Z(i));let o=typeof e.type=="string"?e.type.replace("_ORDER","").toLowerCase():Z(e.type);return e.algo_order_id===void 0||e.algo_order_id&&e.algo_type==="BRACKET"?[Z(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 j(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function Do(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 Ge(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=Do(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,n=r?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=n?hooks.utils.calcTPSL_ROI({pnl:n,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:n,slPnL:a},roi:{tpRoi:s,slRoi:d}}}var cr=react.createContext({}),B=()=>react.useContext(cr),mt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(cr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var pr=react.createContext({}),H=()=>react.useContext(pr),gt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:i}=e,n=hooks.useSymbolsInfo(),a=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?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,g)=>{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,g,u)=>{let{min_notional:O}=n[l]();return hooks.checkNotional(g,u,O)},[n]);return jsxRuntime.jsx(pr.Provider,{value:{onCancelOrder:a,onEditOrder:s,editOrder:r,editAlgoOrder:i,checkMinNotional:d},children:e.children})};var yr=react.createContext({}),z=()=>react.useContext(yr),yt=e=>{let{quote_dp:t}=B(),[r,o]=react.useState(),[i]=hooks.useMutation("/v1/algo/order","DELETE"),[n]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),l=async _=>i(null,{order_id:_.algo_order_id,symbol:_.symbol}),g=async(_,v)=>n({order_id:_.algo_order_id,child_orders:_.child_orders.map(A=>({order_id:A.algo_order_id,quantity:v.order_quantity}))}),u=_=>a.cache.get(d)?.data.rows.find(A=>A.symbol===_),{sl_trigger_price:O,tp_trigger_price:w,tpPnL:h,slPnL:I}=Zo({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??!1)){let _=u(e.order.symbol);_&&o(_);}},[e.order.symbol]),jsxRuntime.jsx(yr.Provider,{value:{order:e.order,sl_trigger_price:O,tp_trigger_price:w,tpPnL:h,slPnL:I,onCancelOrder:l,onUpdateOrder:g,getRelatedPosition:u,position:r},children:e.children})};function Zo(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:n}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,l=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:i,tp_trigger_price:n,slPnL:l,tpPnL:d}}var Ne=e=>{let{type:t,base:r,value:o,cancelPopover:i,isSubmitting:n,onConfirm:a}=e,s=react.useMemo(()=>{switch(t){case 0:return `You agree changing the quantity of ${r}-PERP order to `;case 1:return `You agree changing the price of ${r}-PERP order to `;case 2:return `You agree changing the trigger price of ${r}-PERP order to `}},[t]);return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:[s,jsxRuntime.jsx("span",{className:"oui-text-warning-darken",children:utils.commify(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:n,children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:n,onClick:a,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:n,error:a,handleKeyDown:s,onClick:d,onClose:l,onFocus:g,onBlur:u,hintInfo:O}=e;react.useEffect(()=>{let h=t.current;if(h){let I=h.value.length;h.setSelectionRange(I,I);}n(!0);},[]);let w=(O?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:O,open:w,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:h=>i(h),helpText:a,onClick:h=>{h.stopPropagation(),h.preventDefault();},autoComplete:"off",onFocus:g,onBlur:u,onKeyDown:s,autoFocus:!0,color:w?"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 Pt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[i,n]=react.useState(t.quantity.toString()),[a,s]=react.useState(!1);react.useEffect(()=>{x(t.quantity.toString());},[e.order.quantity]);let[d,l]=react.useState(!1),[g,u]=react.useState(),{editOrder:O,editAlgoOrder:w,checkMinNotional:h}=H(),{onUpdateOrder:I,position:_}=z(),{base_dp:v,base:A,base_tick:C}=B(),x=async(m,p)=>{n(m);let k=Math.abs(_?.position_qty||0);if(_&&o&&Number(m)>k)u(`Quantity should be less than position quantity : ${k}`);else {let ie=Number(m);p&&ie>p?u(`Quantity should be less than ${utils.commifyOptional(p,{fix:v})}`):u(void 0);}return Promise.resolve()},F=()=>{l(!1),s(!1);},D=()=>{l(!1),x(t.quantity.toString()),s(!1);},[K,f]=react.useState(!1),S=react.useRef(null),U=()=>{if(g)return;if(Number(i)===Number(t.quantity)){s(!1);return}let m=t.algo_order_id!==void 0?t.trigger_price:t.price;if(m!==null&&t.reduce_only!==!0){let p=h(t.symbol,m,i);if(p){ui.toast.error(p),f(!1),D();return}}l(!0);},le=m=>{m?.stopPropagation(),m?.preventDefault(),U();},E=m=>{m.key==="Enter"&&(m?.stopPropagation(),m?.preventDefault(),U());},P=react.useCallback(()=>{f(!0);let m={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 m.algo_order_id<"u"&&m.order_type==="MARKET"){let{order_price:k,...ie}=m;m=ie;}typeof t.reduce_only<"u"&&(m.reduce_only=t.reduce_only),t.order_tag!==void 0&&(m={...m,order_tag:t.order_tag}),t?.visible_quantity===0&&(m.visible_quantity=0),t?.tag!==void 0&&(m.order_tag=t.tag);let p;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?p=I(t,m):t.algo_order_id!==void 0?p=w(t.algo_order_id.toString(),m):p=O(t.order_id.toString(),m),p.then(k=>{F(),x(i.toString());},k=>{ui.toast.error(k.message),x(t.quantity.toString()),D();}).finally(()=>f(!1));},[i]),L=react.useRef(null),J=react.useRef(null),oe=m=>{L.current&&J.current&&!L.current.contains(m.target)&&!J.current.contains(m.target)&&!d&&D();};react.useEffect(()=>(document.addEventListener("mousedown",oe),()=>{document.removeEventListener("mousedown",oe);}),[d,t.quantity]);let Ce=()=>!a||e.disableEdit?jsxRuntime.jsx(Si,{order:t,quantity:i,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(_i,{inputRef:S,quantitySliderRef:J,base_dp:v,base_tick:C,quantity:i,setQuantity:x,editing:a,setEditing:s,handleKeyDown:E,onClick:le,onClose:D,symbol:t.symbol,reduce_only:o,positionQty:_?.position_qty,error:g,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:A,value:i,cancelPopover:D,isSubmitting:K,onConfirm:P}),contentProps:{onOpenAutoFocus:m=>{}},children:jsxRuntime.jsx("div",{onClick:m=>{m.stopPropagation(),m.preventDefault();},ref:L,children:Ce()})})},Si=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",j(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:n,setQuantity:a,editing:s,setEditing:d,handleKeyDown:l,onClick:g,onClose:u,error:O,symbol:w,reduce_only:h,positionQty:I,confirmOpen:_,side:v,order:A}=e,C=hooks.useMaxQty(w,A.side,A.reduce_only),x=react.useMemo(()=>h?Math.abs(I??0):A.quantity+Math.abs(C),[A.quantity,C,h,I]),[F,D]=react.useState(void 0);react.useEffect(()=>{if(F===void 0){let f=new utils.Decimal(n).div(x).abs().mul(100).toNumber();D(f);}},[F,x,n]);let K=async f=>(i>0&&(f=hooks.utils.formatNumber(f,i)??f),a(`${f}`,x));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!_,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(we,{inputRef:t,dp:o,value:n,setValue:f=>{let S=Math.abs(Math.min(Number(f),x)).toString();if(a(f,x),f.endsWith("."))return;if(Number(S)===0){D(0);return}let U=new utils.Decimal(f).div(x).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();D(Math.min(100,U));},setEditing:d,handleKeyDown:l,onClick:g,onClose:u,onBlur:f=>{K(f.target.value);},hintInfo:O})}),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:`${F}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[F??0],onValueChange:f=>{let S=Array.from(f.values());D(S[0]);let U=new utils.Decimal(S[0]).div(100).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(U,x);},onValueCommit:f=>{let S=new utils.Decimal(f[0]).div(100).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);K(S).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Pi,{onClick:f=>{D(f*100);let S=new utils.Decimal(f).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);S=hooks.utils.formatNumber(S,i)??S,a(S,x),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(S.length,S.length);},100);}})]})]})})]})},Pi=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 Lr=e=>{let{order:t}=e,[r,o]=react.useState(t.price?.toString()??"Market"),[i,n]=react.useState(!1),[a,s]=react.useState(!1),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[g,u]=react.useState(!1),{editOrder:O,editAlgoOrder:w,checkMinNotional:h}=H(),{base:I,quote_dp:_}=B(),v=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),A=()=>{n(!1),s(!1);},C=()=>{n(!1),o(t.price?.toString()??"Market"),s(!1);},x=react.useMemo(()=>!v||l||!a?"":Number(r)>v.max?`Price can not be greater than ${v.max} USDC.`:Number(r)<v.min?`Price can not be less than ${v.min} USDC.`:"",[l,a,v,r]),F=P=>{if(P?.stopPropagation(),P?.preventDefault(),!(x.length>0)){if(r===`${t.price}`){s(!1);return}if(t.reduce_only!==!0){let L=h(t.symbol,r,t.quantity);if(L){ui.toast.error(L),u(!1),C();return}}n(!0);}},D=P=>{P.key==="Enter"&&F(P);},K=()=>{u(!0);let P=t.order_id,L={order_price:r,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(L.reduce_only=t.reduce_only),t.order_tag!==void 0&&(L={...L,order_tag:t.order_tag}),d&&(P=t.algo_order_id,L={...L,order_id:P,price:r,algo_order_id:P}),t?.visible_quantity===0&&(L.visible_quantity=0),t.tag!==void 0&&(L.order_tag=t.tag);let J;t.algo_order_id!==void 0?J=w(t.algo_order_id.toString(),L):J=O(t.order_id.toString(),L),J.then(oe=>{A(),o(r);},oe=>{ui.toast.error(oe.message),C();}).finally(()=>u(!1));},f=react.useRef(null);react.useEffect(()=>{e.order.price&&o(`${e.order.price}`);},[e.order.price]);let S=react.useRef(null),U=P=>{S.current&&!S.current.contains(P.target)&&!i&&C();};if(react.useEffect(()=>(document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let E=()=>!a||e.disableEdit?jsxRuntime.jsx(vi,{order:t,price:r,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:f,dp:_,value:r,setValue:o,setEditing:s,handleKeyDown:D,onClick:F,onClose:C,hintInfo:x});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:n,content:jsxRuntime.jsx(Ne,{type:1,base:I,value:r,cancelPopover:C,isSubmitting:g,onConfirm:K}),children:jsxRuntime.jsx("div",{onClick:P=>{P.stopPropagation(),P.preventDefault();},ref:S,children:E()})})},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",j(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 Fr=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,n=t?.algo_type==="BRACKET",[a,s]=react.useState(!1),[d,l]=react.useState(!1),[g,u]=react.useState(!1),{editAlgoOrder:O,checkMinNotional:w}=H(),{base:h,quote_dp:I,quote_max:_,quote_min:v}=B(),A=react.useMemo(()=>{if(!((!i||n)&&!d)){if(Number(r)>_)return `Trigger price must be less than ${_}`;if(Number(r)<v)return `Trigger price must be greater than ${v}`}},[d,r,i,n]),C=()=>{s(!1),l(!1);},x=()=>{o(t.trigger_price?.toString()??"0"),s(!1),l(!1);},F=react.useRef(null),D=E=>{F.current&&!F.current.contains(E.target)&&!a&&x();};react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[a,t.trigger_price]);let K=E=>{if(E?.stopPropagation(),E?.preventDefault(),l(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let P=w(t.symbol,t.price,t.quantity);if(P){ui.toast.error(P),u(!1),x();return}}s(!0);}},f=E=>{E.key==="Enter"&&K(E);},S=()=>{if((A??"").length>0)return;u(!0);let E={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),O(`${t.algo_order_id}`,E).then(P=>{C(),o(r);},P=>{ui.toast.error(P.message),o(t.trigger_price?.toString()??"--"),x();}).finally(()=>u(!1));},U=react.useRef(null);if(!i||n)return jsxRuntime.jsx(ui.Text,{children:"--"});let le=()=>!d||e.disableEdit?jsxRuntime.jsx(Di,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:U,dp:I,value:r,setValue:o,setEditing:l,handleKeyDown:f,onClick:K,onClose:x,hintInfo:A});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(Ne,{type:2,base:h,value:r,cancelPopover:x,isSubmitting:g,onConfirm:S}),children:jsxRuntime.jsx("div",{onClick:E=>{E.stopPropagation(),E.preventDefault();},ref:F,children:le()})})},Di=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",j(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 je=e=>{let{order:t}=e,{onCancelOrder:r}=H(),[o,i]=react.useState(!1);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:n=>{r&&(n.preventDefault(),n.stopPropagation(),i(!0),r(t).then(a=>a,a=>{ui.toast.error(a.message);}).finally(()=>{i(!1);}));},loading:o,children:"Cancel"})};var kr=e=>{let{record:t}=e,[r,o]=react.useState(!1),[i,{data:n,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),g=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(),g());},children:"Renew"})};var Br=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=z();return jsxRuntime.jsx(Hi,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},Hi=e=>{let{direction:t="row",order:r,position:o}=e,i=hooks.useSymbolsInfo(),n=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(Rr,{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(Rr,{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]),a=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:a});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:n,className:"oui-bg-base-5",tooltipProps:{arrow:{className:"oui-fill-base-5"}},children:s}):s},Rr=e=>{let{qty:t,price:r,entryPrice:o,orderSide:i,orderType:n,symbolInfo:a}=e,s=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:i,orderType:n},{symbol:a}),d=n===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:a.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 Ur=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=B(),{sl_trigger_price:i,tp_trigger_price:n}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:a,roi:s}=Ge(t);return !n&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof a.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:a.tpPnL}),typeof a.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:a.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Wr,{type:"TP",value:n,quote_dp:r}),jsxRuntime.jsx(Wr,{type:"SL",value:i,quote_dp:r})]})})},Wr=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 zr=e=>{let{position:t,order:r}=z(),{quote_dp:o,base_dp:i}=B();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:i,position:t,order:r,label:"Edit",isEditing:!0})};var Qr=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=z();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 Vr=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}),ve({width:130,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),Ee({width:130,title:"Order price",disableEdit:!0,enableSort:!1}),tt({width:130,enableSort:!1}),$r({width:130}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:130,enableSort:!1}),Qe({width:130}),$e({width:130}),xe({width:130}),Ae({width:130}),Kr({width:130})];case"pending":return [be({width:172,showType:!0,onSymbolChange:r,enableSort:!1}),ve({width:162,className:"oui-pr-0",enableSort:!1}),Ee({width:162,className:"oui-pr-0",enableSort:!1}),Ue({width:162,className:"oui-pr-0"}),cn({width:130}),Ie({width:162,isPending:!0}),xe({width:162}),Ae({width:162}),ze({width:162,enableSort:!1}),pn({width:162})];case"tp_sl":return [be({width:176,showType:!0,onSymbolChange:r,enableSort:!1}),ln({width:176}),$r({width:176}),dn({width:176,disableEdit:!0}),mn({width:176}),xe({width:176}),ze({width:176,enableSort:!1}),gn({width:176})];case"filled":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),Ee({width:124,title:"Order price",disableEdit:!0}),un({width:124}),Ue({width:124,disableEdit:!0}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:124})];case"cancelled":return [be({showType:!0,width:154,onSymbolChange:r,enableSort:!1}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),Ee({width:124,disableEdit:!0,enableSort:!1}),tt({width:124,enableSort:!1}),Ue({width:124,disableEdit:!0}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124})];case"rejected":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),Ee({width:124,disableEdit:!0}),tt({width:124}),Ue({width:124,disableEdit:!0}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:124})];case"orderHistory":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:150,disableEdit:!0,className:"oui-pl-6 oui-pr-0"}),Ee({width:124,disableEdit:!0}),tt({width:124}),Ue({width:124,disableEdit:!0}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:150}),Kr({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=j(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,n)=>jsxRuntime.jsx(ui.Badge,{color:i.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",children:i},n))})]})]})}}}function ve(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 Ke(o,i)}:void 0,render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(Pt,{order:r,disableEdit:e?.disableEdit})}}function ln(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 Ke(o,i)}:void 0,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Pt,{order:r})}}function Ee(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r,o)=>Ke(t.price??0,r.price??0):void 0,render:(t,r)=>jsxRuntime.jsx(Lr,{order:r,disableEdit:e?.disableEdit})}}function dn(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Qr,{})}}function un(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 Ue(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Fr,{order:r,disableEdit:e?.disableEdit})}}function $r(e){return {title:e?.title??"Trigger",className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Br,{})}}function cn(e){return {title:"TP/SL",className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Ur,{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,n=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 Ke(i,n)}: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 wt(e){return {title:"Real. PnL",dataIndex:"realized_pnl",width:e?.width,className:e?.className,render:t=>{let{quote_dp:r}=B(),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 ze(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 Qe(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function mn(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 $e(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"?Z("pending"):Z(o)}}}function tt(e){return {title:"Avg. open",dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>Ke(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 Kr(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(kr,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(je,{order:r}):null}}function pn(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(je,{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(zr,{order:r}),jsxRuntime.jsx(je,{order:r})]})}}function Ke(e,t){return e>t?1:e<t?-1:0}var Jr=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})},Xr=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}`:Z(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"?"primaryLight":"neutral",size:"xs",children:o},i))})},Zr=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})},jr=e=>{let{item:t}=e,r=t.status||t.algo_status,o=()=>r==="NEW"?Z("pending"):Z(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})})},Et=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 eo=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})})},It=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??"--"})})},to=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})})},ro=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??"--"})})},oo=e=>{let{tp_trigger_price:t,tpPnL:r}=z();return jsxRuntime.jsx(ui.Statistic,{label:"TP trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(it,{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??"--"})})})},io=e=>{let{sl_trigger_price:t,slPnL:r}=z();return jsxRuntime.jsx(ui.Statistic,{label:"SL trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(it,{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??"--"})})})},no=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"})}),ao=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"})}),so=e=>{let{item:t}=e,r=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:"Entire position"}):jsxRuntime.jsx(ui.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})},lo=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??"--"})}),uo=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??"--"})}),co=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??"--"})})},it=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(n=>!n),children:e.children})})};var At=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:n}=e,a=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"?"primaryLight":"neutral",size:"xs",children:s},d)),a&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!a&&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:[n&&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 Bt=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=n=>{let a=e.baseTick;if(a&&a>0){let s=hooks.utils.formatNumber(n,a)??n;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((n,a)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?"primaryLight":"neutral",size:"xs",children:n},a)),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:n=>e.setTriggerPrice(n),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:n=>e.setPrice(n),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:n=>{e.setQuantity(n);},onBlur:n=>i(n.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:n=>{e.setSliderValue(n[0]);},color:"primaryLight"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primaryLight",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:"primaryLight",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:n=>{e.onClose();},children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,onClick:n=>{n.stopPropagation(),n.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 zt=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:i=!0}=e,{item:n}=t,{hide:a}=ui.useModal(),[s,d]=react.useState(!1),l=n?.algo_order_id!==void 0&&n.algo_type!==types.AlgoOrderRootType.BRACKET,g=n?.type==="MARKET"&&l;g||n?.type==="MARKET";let [O,w]=react.useState(!1),h=react.useMemo(()=>l&&n.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${n.type}`:n.type,[n,l]),[I,_]=hooks.useLocalStorage("orderly_order_confirm",!0),{base_dp:v,base_tick:A}=e.state,{formattedOrder:C,setValue:x,symbolInfo:F,markPrice:D,errors:K,validate:f,maxQty:S}=Wn({order:n,orderType:h}),U=()=>{f().then(p=>{I?d(!0):L(C);},p=>{p?.total?.message&&ui.toast.error(p?.total.message);}).catch(p=>{});},le=react.useCallback(()=>{d(!1);},[]),E=()=>C?L(C):Promise.reject(),P=react.useCallback(()=>{a();},[]),L=react.useCallback(async p=>{let k,ie=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(g&&"order_price"in p){let{order_price:he,...Re}=p;p=Re;}k=r(n.algo_order_id.toString(),{...p});}else k=o(n.order_id.toString(),{...p,...ie?{visible_quantity:0}:{}});try{w(!0);let he=await k;P();}catch(he){ui.toast.error(he?.message??`${he}`);}finally{w(!1);}},[r,o]),J=react.useMemo(()=>{let p=C.order_quantity;return p&&Number(p)!==0&&S!==0?new utils.Decimal(p).div(S).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[C.order_quantity,S]),oe=n.price!=C.order_price||n.quantity!=C.order_quantity||n.trigger_price!=C.trigger_price,Ce=hooks.useThrottledCallback(p=>{let k=new utils.Decimal(p).div(100).mul(S).toDecimalPlaces(v,utils.Decimal.ROUND_DOWN).toNumber();x("order_quantity",hooks.utils.formatNumber(k,A));},50,{}),m=(p,k)=>{x(p,k);};return {...t,curMarkPrice:D,isAlgoOrder:l,isStopMarket:g,price:C.order_price,setPrice:p=>m("order_price",p),priceEdit:!g,triggerPrice:C.trigger_price,setTriggerPrice:p=>m("trigger_price",p),quantity:C.order_quantity,setQuantity:p=>{m("order_quantity",p);},maxQty:S,sliderValue:J,setSliderValue:Ce,onClose:P,onSheetConfirm:U,errors:K,orderType:h,isChanged:oe,baseTick:A,dialogOpen:s,setDialogOpen:d,onDialogConfirm:E,onCloseDialog:le,submitting:O,orderConfirm:I,setOrderConfirm:_}},Wn=e=>{let{order:t,orderType:r}=e,[o,i]=react.useState({side:t.side,order_type:r,order_price:t.price,order_quantity:t.quantity,trigger_price:t.trigger_price,reduce_only:t.reduce_only,symbol:t.symbol}),{reduce_only:n}=t,{position:a}=z(),s=a?.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:g,markPrice:u,errors:O,validate:w}=hooks.useOrderEntity({...o,symbol:t.symbol},{maxQty:l});return {symbolInfo:g,markPrice:u,errors:O,validate:w,setValue:(I,_)=>{i(v=>({...v,[I]:_}));},formattedOrder:o,maxQty:l}};var Qt=e=>{let t=zt(e);return jsxRuntime.jsx(Bt,{...t})};var $t=e=>{let{state:t}=e,{editAlgoOrder:r,editOrder:o}=H(),{order:i,position:n}=z(),a=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:n,symbolInfo:e.state.origin})}).catch(s=>{}):ui.modal.sheet({title:"Edit order",classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(Qt,{state:t,editAlgoOrder:r,editOrder:o})}).catch(s=>{});},[t]);return {...t,onShowEditSheet:a}};var Kt=e=>{let t=$t(e);return jsxRuntime.jsx(At,{...t})};var Ht=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 Yt=e=>{let{state:t}=e,[r,o]=react.useState(!1),{onCancelOrder:i}=H(),[n,a]=react.useState(!1);return {...t,open:r,setOpen:o,onCancel:l=>i?(l?.preventDefault(),l?.stopPropagation(),a(!0),i(t.item).then(g=>{o(!1);},g=>{ui.toast.error(g.message);}).finally(()=>{a(!1);})):Promise.resolve(),onClose:()=>{o(!1);},isLoading:n}};var Gt=e=>{let t=Yt(e);return jsxRuntime.jsx(Ht,{...t})};var Zt=e=>!e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(it,{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(Po,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Po,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})}),Po=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 jt=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[i,n]=react.useState(!1),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:d,roi:l}=Ge(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:d,roi:l,quote_dp:r,open:i,setOpen:n}};var er=e=>{let t=jt(e);return jsxRuntime.jsx(Zt,{...t})};var tr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(na,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(aa,{...e}),e.type==="pending"&&jsxRuntime.jsx(er,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(sa,{...e})]}),na=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(Jr,{...e}),jsxRuntime.jsx(Zr,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Xr,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(jr,{...e})]})]}),aa=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:la(e)}),sa=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Kt,{state:e}),jsxRuntime.jsx(Gt,{state:e})]});function la(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(Et,{...e}),jsxRuntime.jsx(eo,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(ro,{...e}),jsxRuntime.jsx(to,{...e})]});case"tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(oo,{...e}),jsxRuntime.jsx(no,{...e}),jsxRuntime.jsx(so,{...e}),jsxRuntime.jsx(io,{...e}),jsxRuntime.jsx(ao,{...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(Et,{...e}),jsxRuntime.jsx(It,{...e,align:"end"}),jsxRuntime.jsx(lo,{...e}),jsxRuntime.jsx(uo,{...e}),jsxRuntime.jsx(co,{...e})]})}}var rr=e=>{let t=B();return {...e,...t}};var or=e=>{let{className:t,...r}=e,o=rr(r);return jsxRuntime.jsx(tr,{...o,className:t})};var ir=e=>{let t=Vr({_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(ba,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardTableView,{columns:t,loading:e.isLoading,dataSource:e.dataSource,bordered:!0,ignoreLoadingCheck:!0,classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(r,o)=>({className:ui.cn("oui-h-[48px]",j(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(yt,{order:r,children:i})),jsxRuntime.jsx(mt,{symbol:r.symbol,children:i})),pagination:e.pagination,manualPagination:e.manualPagination})]})})},nr=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(or,{item:t,index:r,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange});return e.type==="tp_sl"&&(o=jsxRuntime.jsx(yt,{order:t,children:o})),jsxRuntime.jsx(mt,{symbol:t.symbol,children:o})}})]})}),ba=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(),children:"Cancel all"});var No=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 n=0;n<i.child_orders.length;n++){let a=i.child_orders[n];!a.is_activated||!a.trigger_price||(a.parent_algo_type=i.algo_type,r.push(a));}else for(let n=0;n<i.child_orders.length;n++){let a=i.child_orders[n];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=i.algo_type,r.push(a));}else r.push(i);}return r},[e]);var ut=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=!1,onSymbolChange:i,filterConfig:n,pnlNotionalDecimalPrecision:a}=e,s=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),d=50,{page:l,pageSize:g,setPage:u,setPageSize:O,parseMeta:w}=ui.usePagination({pageSize:d}),{orderStatus:h,ordersSide:I,dateRange:_,filterItems:v,onFilter:A}=va(r,{ordersStatus:t,setPage:u,filterConfig:n}),C=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),x=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),[F,{isLoading:D,loadMore:K,cancelOrder:f,updateOrder:S,cancelAlgoOrder:U,updateAlgoOrder:le,cancelAllOrders:E,cancelAllTPSLOrders:P,meta:L,refresh:J}]=hooks.useOrderStream({symbol:e.symbol,status:h,side:I,page:o||!s?void 0:l,size:s?g:500,dateRange:_,includes:C,excludes:x}),oe=`orderly_${r}_pageSize`,[Ce,m]=hooks.useLocalStorage(oe,d);react.useEffect(()=>{Ce!==g&&m(g);},[g,Ce]);let p=react.useCallback(()=>{let Re=e.type==="pending"?"Cancel all pending orders":e.type==="tp_sl"?"Cancel all TP/SL orders":"",Io="Are you sure you want to cancel all of your pending orders?";ui.modal.confirm({title:Re,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:Io}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await P():await E(),J(),Promise.resolve(!0)}catch(sr){return sr?.message!==void 0&&toast.error(sr.message),Promise.resolve(!1)}finally{Promise.resolve();}}});},[r]),k=No(F??[]),ie=reactApp.useDataTap(r!=="tp_sl"?k:F)??void 0,he=react.useMemo(()=>{let Re=s?L:{total:ie?.length,current_page:l,records_per_page:g};return {...w(Re),onPageChange:u,onPageSizeChange:O}},[L,u,O,s,l,g,ie]);return {type:r,dataSource:ie,isLoading:D,loadMore:K,cancelOrder:f,updateOrder:S,cancelAlgoOrder:U,updateAlgoOrder:le,page:l,pageSize:g,setPage:u,setPageSize:O,meta:w(L),pagination:he,manualPagination:s,pnlNotionalDecimalPrecision:a,onFilter:A,filterItems:v,onCancelAll:p,onSymbolChange:i}},va=(e,t)=>{let[r,o]=react.useState(t.ordersStatus??"all"),[i,n]=react.useState(t.filterConfig?.side??"all"),a=t.filterConfig?.range??(e==="all"||e==="orderHistory"?wo({to:new Date,from:Lo(dateFns.subDays(new Date,7))}):{}),[s,d]=react.useState(a),l=u=>{u.name==="side"&&(n(u.value),t.setPage(1)),u.name==="status"&&(o(u.value),t.setPage(1)),u.name==="dateRange"&&(d(wo(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},O={type:"range",name:"dateRange",value:s},w={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,w,O];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,w,O]}},[e,i,r,s]),onFilter:l,ordersSide:i==="all"?void 0:i,dateRange:s,orderStatus:r==="all"?void 0:r}};function Ea(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Lo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var wo=e=>({from:Ea(e.from),to:Lo(e.to)});var fe=e=>{let t=ut(e);return jsxRuntime.jsx(ir,{...t})},Aa=e=>{let t=ut({...e,enableLoadMore:!0});return jsxRuntime.jsx(nr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Eo=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(fe,{type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(fe,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(fe,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(fe,{type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(fe,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(fe,{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=ct(e);return jsxRuntime.jsx(Eo,{...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 ue(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 Do(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}=Do(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({}),W=()=>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 gr=react.createContext({}),G=()=>react.useContext(gr),ft=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,g)=>{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,g,u)=>{let{min_notional:_}=a[l]();return hooks.checkNotional(g,u,_)},[a]);return jsxRuntime.jsx(gr.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}=W(),[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}),g=async(S,L)=>a({order_id:S.algo_order_id,child_orders:S.child_orders.map(I=>({order_id:I.algo_order_id,quantity:L.order_quantity}))}),u=S=>n.cache.get(d)?.data.rows.find(I=>I.symbol===S),{sl_trigger_price:_,tp_trigger_price:w,tpPnL:O,slPnL:v}=Zo({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:_,tp_trigger_price:w,tpPnL:O,slPnL:v,onCancelOrder:l,onUpdateOrder:g,getRelatedPosition:u,position:r},children:e.children})};function Zo(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:g,onBlur:u,hintInfo:_}=e;react.useEffect(()=>{let O=t.current;if(O){let v=O.value.length;O.setSelectionRange(v,v);}a(!0);},[]);let w=(_?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:_,open:w,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:O=>i(O),helpText:n,onClick:O=>{O.stopPropagation(),O.preventDefault();},autoComplete:"off",onFocus:g,onBlur:u,onKeyDown:s,autoFocus:!0,color:w?"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),[g,u]=react.useState(),{editOrder:_,editAlgoOrder:w,checkMinNotional:O}=G(),{onUpdateOrder:v,position:S}=V(),{base_dp:L,base:I,base_tick:k}=W(),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 M=Number(p);q&&M>q?u(`Quantity should be less than ${utils.commifyOptional(q,{fix:L})}`):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),C=react.useRef(null),F=()=>{if(g)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=O(t.symbol,p,i);if(q){ui.toast.error(q),f(!1),D();return}}l(!0);},le=p=>{p?.stopPropagation(),p?.preventDefault(),F();},E=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,...M}=p;p=M;}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=w(t.algo_order_id.toString(),p):q=_(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]),N=react.useRef(null),Y=react.useRef(null),ie=p=>{N.current&&Y.current&&!N.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 he=()=>!n||e.disableEdit?jsxRuntime.jsx(Si,{order:t,quantity:i,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(Pi,{inputRef:C,quantitySliderRef:Y,base_dp:L,base_tick:k,quantity:i,setQuantity:m,editing:n,setEditing:s,handleKeyDown:E,onClick:le,onClose:D,symbol:t.symbol,reduce_only:o,positionQty:S?.position_qty,error:g,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:N,children:he()})})},Si=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})})]})},Pi=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:i,quantity:a,setQuantity:n,editing:s,setEditing:d,handleKeyDown:l,onClick:g,onClose:u,error:_,symbol:w,reduce_only:O,positionQty:v,confirmOpen:S,side:L,order:I}=e,k=hooks.useMaxQty(w,I.side,I.reduce_only),m=react.useMemo(()=>O?Math.abs(v??0):I.quantity+Math.abs(k),[I.quantity,k,O,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 C=Math.abs(Math.min(Number(f),m)).toString();if(n(f,m),f.endsWith("."))return;if(Number(C)===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:g,onClose:u,onBlur:f=>{K(f.target.value);},hintInfo:_})}),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 C=Array.from(f.values());D(C[0]);let F=new utils.Decimal(C[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);n(F,m);},onValueCommit:f=>{let C=new utils.Decimal(f[0]).div(100).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);K(C).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(_i,{onClick:f=>{D(f*100);let C=new utils.Decimal(f).mul(m).abs().toFixed(o,utils.Decimal.ROUND_DOWN);C=hooks.utils.formatNumber(C,i)??C,n(C,m),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(C.length,C.length);},100);}})]})]})})]})},_i=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,[g,u]=react.useState(!1),{editOrder:_,editAlgoOrder:w,checkMinNotional:O}=G(),{base:v,quote_dp:S}=W(),L=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(()=>!L||l||!n?"":Number(r)>L.max?`Price can not be greater than ${L.max} USDC.`:Number(r)<L.min?`Price can not be less than ${L.min} USDC.`:"",[l,n,L,r]),A=P=>{if(P?.stopPropagation(),P?.preventDefault(),!(m.length>0)){if(r===`${t.price}`){s(!1);return}if(t.reduce_only!==!0){let N=O(t.symbol,r,t.quantity);if(N){ui.toast.error(N),u(!1),k();return}}a(!0);}},D=P=>{P.key==="Enter"&&A(P);},K=()=>{u(!0);let P=t.order_id,N={order_price:r,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(N.reduce_only=t.reduce_only),t.order_tag!==void 0&&(N={...N,order_tag:t.order_tag}),d&&(P=t.algo_order_id,N={...N,order_id:P,price:r,algo_order_id:P}),t?.visible_quantity===0&&(N.visible_quantity=0),t.tag!==void 0&&(N.order_tag=t.tag);let Y;t.algo_order_id!==void 0?Y=w(t.algo_order_id.toString(),N):Y=_(t.order_id.toString(),N),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 C=react.useRef(null),F=P=>{C.current&&!C.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 E=()=>!n||e.disableEdit?jsxRuntime.jsx(Ei,{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:g,onConfirm:K}),children:jsxRuntime.jsx("div",{onClick:P=>{P.stopPropagation(),P.preventDefault();},ref:C,children:E()})})},Ei=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),[g,u]=react.useState(!1),{editAlgoOrder:_,checkMinNotional:w}=G(),{base:O,quote_dp:v,quote_max:S,quote_min:L}=W(),I=react.useMemo(()=>{if(!((!i||a)&&!d)){if(Number(r)>S)return `Trigger price must be less than ${S}`;if(Number(r)<L)return `Trigger price must be greater than ${L}`}},[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=E=>{A.current&&!A.current.contains(E.target)&&!n&&m();};react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[n,t.trigger_price]);let K=E=>{if(E?.stopPropagation(),E?.preventDefault(),l(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let P=w(t.symbol,t.price,t.quantity);if(P){ui.toast.error(P),u(!1),m();return}}s(!0);}},f=E=>{E.key==="Enter"&&K(E);},C=()=>{if((I??"").length>0)return;u(!0);let E={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),_(`${t.algo_order_id}`,E).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(Di,{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:O,value:r,cancelPopover:m,isSubmitting:g,onConfirm:C}),children:jsxRuntime.jsx("div",{onClick:E=>{E.stopPropagation(),E.preventDefault();},ref:A,children:le()})})},Di=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"),g=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(),g());},children:"Renew"})};var Mr=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=V();return jsxRuntime.jsx(Hi,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},Hi=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}=W(),{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}=W();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 [xe({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}),Se({width:130}),Ae({width:130}),Vr({width:130})];case"pending":return [xe({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"}),cn({width:130}),Ie({width:162,isPending:!0}),Se({width:162}),Ae({width:162}),Ue({width:162,enableSort:!1}),pn({width:162})];case"tp_sl":return [xe({width:176,showType:!0,onSymbolChange:r,enableSort:!1}),ln({width:176}),Kr({width:176}),dn({width:176,disableEdit:!0}),mn({width:176}),Se({width:176}),Ue({width:176,enableSort:!1}),gn({width:176})];case"filled":return [xe({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}),un({width:124}),We({width:124,disableEdit:!0}),Lt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),ze({width:124}),Qe({width:124}),Se({width:124}),Ae({width:124}),Ue({width:124})];case"cancelled":return [xe({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}),Se({width:124}),Ae({width:124})];case"rejected":return [xe({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}),Se({width:124}),Ae({width:124}),Ue({width:124})];case"orderHistory":return [xe({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}),Se({width:124}),Ae({width:124}),Ue({width:150}),Vr({width:80})]}},[t,o])};function xe(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:ue(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 ln(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 dn(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx($r,{})}}function un(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 cn(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}=W(),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 Se(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 mn(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 pn(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:ue(e.item)?.map((o,i)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primaryLight":"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 fo=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:[ue(e.item)?.map((s,d)=>jsxRuntime.jsx(ui.Badge,{color:s.toLocaleLowerCase()==="position"?"primaryLight":"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:[ue(e.item)?.map((a,n)=>jsxRuntime.jsx(ui.Badge,{color:a.toLocaleLowerCase()==="position"?"primaryLight":"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:"primaryLight"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primaryLight",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:"primaryLight",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(fo,{...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),g=n?.algo_order_id!==void 0&&n.algo_type!==types.AlgoOrderRootType.BRACKET,u=n?.type==="MARKET"&&g;u||n?.type==="MARKET";let [w,O]=react.useState(!1),v=react.useMemo(()=>g&&n.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${n.type}`:n.type,[n,g]),[S,L]=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:C,maxQty:F}=Wn({order:n,orderType:v,position:a}),le=()=>{C().then(b=>{S?l(!0):Y(m);},b=>{b?.total?.message&&ui.toast.error(b?.total.message);}).catch(b=>{});},E=react.useCallback(()=>{l(!1);},[]),P=()=>m?Y(m):Promise.reject(),N=react.useCallback(()=>{s();},[]),Y=react.useCallback(async b=>{let M,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:de,...ct}=b;b=ct;}M=r(n.algo_order_id.toString(),{...b});}else M=o(n.order_id.toString(),{...b,...ut?{visible_quantity:0}:{}});try{O(!0);let de=await M;N();}catch(de){ui.toast.error(de?.message??`${de}`);}finally{O(!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]),he=n.price!=m.order_price||n.quantity!=m.order_quantity||n.trigger_price!=m.trigger_price,p=hooks.useThrottledCallback(b=>{let M=new utils.Decimal(b).div(100).mul(F).toDecimalPlaces(I,utils.Decimal.ROUND_DOWN).toNumber();A("order_quantity",hooks.utils.formatNumber(M,k));},50,{}),q=(b,M)=>{A(b,M);};return {...t,curMarkPrice:K,isAlgoOrder:g,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:N,onSheetConfirm:le,errors:f,orderType:v,isChanged:he,baseTick:k,dialogOpen:d,setDialogOpen:l,onDialogConfirm:P,onCloseDialog:E,submitting:w,orderConfirm:S,setOrderConfirm:L}},Wn=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:g,markPrice:u,errors:_,validate:w}=hooks.useOrderEntity({...i,symbol:t.symbol},{maxQty:l});return {symbolInfo:g,markPrice:u,errors:_,validate:w,setValue:(v,S)=>{a(L=>({...L,[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(g=>{o(!1);},g=>{ui.toast.error(g.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(na,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(aa,{...e}),e.type==="pending"&&jsxRuntime.jsx(tr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(sa,{...e})]}),na=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})]})]}),aa=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:la(e)}),sa=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 la(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=W();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(ft,{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(ba,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardTableView,{columns:t,loading:e.isLoading,dataSource:e.dataSource,bordered:!0,ignoreLoadingCheck:!0,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(ft,{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})}})]})}),ba=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(),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:g,setPage:u,setPageSize:_,parseMeta:w}=ui.usePagination({pageSize:d}),{orderStatus:O,ordersSide:v,dateRange:S,filterItems:L,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:C,cancelAlgoOrder:F,updateAlgoOrder:le,cancelAllOrders:E,cancelAllTPSLOrders:P,meta:N,refresh:Y}]=hooks.useOrderStream({symbol:e.symbol,status:O,side:v,page:o||!s?void 0:l,size:s?g:500,dateRange:S,includes:k,excludes:m}),ie=`orderly_${r}_pageSize`,[he,p]=hooks.useLocalStorage(ie,d);react.useEffect(()=>{he!==g&&p(g);},[g,he]);let q=react.useCallback(()=>{let de=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:de,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:ct}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await P():await E(),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??[]),M=reactApp.useDataTap(r!=="tp_sl"?b:A)??void 0,ut=react.useMemo(()=>{let de=s?N:{total:M?.length,current_page:l,records_per_page:g};return {...w(de),onPageChange:u,onPageSizeChange:_}},[N,u,_,s,l,g,M]);return {type:r,dataSource:M,isLoading:D,loadMore:K,cancelOrder:f,updateOrder:C,cancelAlgoOrder:F,updateAlgoOrder:le,page:l,pageSize:g,setPage:u,setPageSize:_,meta:w(N),pagination:ut,manualPagination:s,pnlNotionalDecimalPrecision:n,onFilter:I,filterItems:L,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"?Lo({to:new Date,from:Eo(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(Lo(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},_={type:"range",name:"dateRange",value:s},w={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,w,_];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,w,_]}},[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 Eo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Lo=e=>({from:va(e.from),to:Eo(e.to)});var ye=e=>{let t=dt(e);return jsxRuntime.jsx(nr,{...t})},Aa=e=>{let t=dt({...e,enableLoadMore:!0});return jsxRuntime.jsx(ar,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Io=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(ye,{type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(ye,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(ye,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(ye,{type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(ye,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(ye,{type:"rejected",ordersStatus:types.OrderStatus.REJECTED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})})]});var me=(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))(me||{}),ka=e=>{let t=mt(e);return jsxRuntime.jsx(Io,{...t})};
15
15
 
16
- exports.DesktopOrderList = ir;
17
- exports.DesktopOrderListWidget = fe;
18
- exports.MobileOrderList = nr;
16
+ exports.DesktopOrderList = nr;
17
+ exports.DesktopOrderListWidget = ye;
18
+ exports.MobileOrderList = ar;
19
19
  exports.MobileOrderListWidget = Aa;
20
20
  exports.OrdersWidget = ka;
21
- exports.TabType = ce;
22
- exports.useOrderListScript = ut;
23
- exports.useOrdersScript = ct;
21
+ exports.TabType = me;
22
+ exports.useOrderListScript = dt;
23
+ exports.useOrdersScript = mt;
24
24
  //# sourceMappingURL=out.js.map
25
25
  //# sourceMappingURL=index.js.map