@orderly.network/ui-orders 2.5.3 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,25 +6,25 @@ var types = require('@orderly.network/types');
6
6
  var i18n = require('@orderly.network/i18n');
7
7
  var uiConnector = require('@orderly.network/ui-connector');
8
8
  var hooks = require('@orderly.network/hooks');
9
+ var jsxRuntime = require('react/jsx-runtime');
9
10
  var dateFns = require('date-fns');
10
11
  var uiShare = require('@orderly.network/ui-share');
11
12
  var utils = require('@orderly.network/utils');
12
- var jsxRuntime = require('react/jsx-runtime');
13
13
  var uiTpsl = require('@orderly.network/ui-tpsl');
14
14
  var reactApp = require('@orderly.network/react-app');
15
15
 
16
- var wt=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:o}=e,n=react.useRef(null);return react.useImperativeHandle(e.ref,()=>({download:()=>{n.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:n,sharePnLConfig:o}};var ue=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ce(e){let t=e.type,r=e.algo_type;if(typeof t<"u"){let o=[];if(e.parent_algo_type){if(r===types.AlgoOrderType.STOP_LOSS){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.sl")]:[i18n.i18n.t("tpsl.sl")];o.push(...i);}if(r===types.AlgoOrderType.TAKE_PROFIT){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.tp")]:[i18n.i18n.t("tpsl.tp")];o.push(...i);}return o}let n=typeof t=="string"?t.replace("_ORDER",""):"";if([types.OrderType.ASK,types.OrderType.BID].includes(t))return [i18n.i18n.t("orderEntry.orderType.limit")];if(e.algo_order_id===void 0||e.algo_order_id&&r==="BRACKET")return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.limit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.market"),[types.OrderType.POST_ONLY]:i18n.i18n.t("orderEntry.orderType.postOnly"),[types.OrderType.IOC]:i18n.i18n.t("orderEntry.orderType.ioc"),[types.OrderType.FOK]:i18n.i18n.t("orderEntry.orderType.fok")}[n]||ue(n)];if(n)return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.stopLimit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.stopMarket")}[n]||n]}if(typeof r<"u"){let o=[];r===types.AlgoOrderRootType.POSITIONAL_TP_SL&&o.push(i18n.i18n.t("common.position"));let n=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!a.trigger_price),i=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.STOP_LOSS&&!!a.trigger_price);return (n||i)&&o.push(n&&i?i18n.i18n.t("common.tpsl"):n?i18n.i18n.t("tpsl.tp"):i18n.i18n.t("tpsl.sl")),o}}function ne(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function yn(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function ct(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=yn(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let n=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=i?hooks.utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:d}}}function It(e,t){return !e||!t?false:e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}var vt=e=>{let{t}=i18n.useTranslation();return e.sharePnLConfig==null?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),ui.modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?t("share.pnl.share.long"):t("share.pnl.share.short"),openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsxRuntime.jsx(ui.ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})})};var Er=e=>{let{sharePnLConfig:t,order:r,modalId:o,iconSize:n}=e,{getFirstRefCode:i}=hooks.useReferralInfo(),a=react.useMemo(()=>i()?.code,[i]),s=hooks.useSymbolLeverage(e.order.symbol);return {iconSize:n,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:o}};var Je=e=>{let t=Er(e);return jsxRuntime.jsx(vt,{...t})};var vr=react.createContext({}),$=()=>react.useContext(vr),At=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(vr.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 kr=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=$(),{t:n}=i18n.useTranslation(),{sl_trigger_price:i,tp_trigger_price:a}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:s,roi:d}=ct(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof s.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:s.tpPnL}),typeof s.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:s.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Dr,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(Dr,{type:"SL",value:i,quote_dp:r})]})})},Dr=e=>{let{type:t,value:r,quote_dp:o}=e,{t:n}=i18n.useTranslation();return r?jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[t==="TP"?`${n("tpsl.tp")} -`:`${n("tpsl.sl")} -`,"\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Rr=react.createContext({}),Z=()=>react.useContext(Rr),Ft=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:n}=e,{t:i}=i18n.useTranslation(),a=hooks.useSymbolsInfo(),s=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),d=react.useCallback(async(l,f)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:false;await ui.modal.sheet({title:i("orders.editOrder"),classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[i]),u=react.useCallback((l,f,S)=>{let{min_notional:C}=a[l](),h=hooks.getMinNotional({price:f,qty:S,min_notional:C});if(h!==void 0)return i("orderEntry.total.error.min",{value:h})},[a,i]);return jsxRuntime.jsx(Rr.Provider,{value:{onCancelOrder:s,onEditOrder:d,editOrder:r,editAlgoOrder:n,checkMinNotional:u},children:e.children})};var mt=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),{onCancelOrder:o}=Z(),[n,i]=react.useState(false);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{o&&(a.preventDefault(),a.stopPropagation(),i(true),o(t).then(s=>s,s=>{ui.toast.error(s.message);}).finally(()=>{i(false);}));},loading:n,children:r("common.cancel")})};var qe=e=>{let{type:t,base:r,value:o,cancelPopover:n,isSubmitting:i,onConfirm:a}=e,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsx("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:(()=>{let u={values:{base:r,value:utils.commify(o)},components:[jsxRuntime.jsx("span",{className:"oui-text-warning-darken"})]};switch(t){case 0:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.quantity",...u});case 1:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.price",...u});case 2:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.triggerPrice",...u})}})()}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:n,disabled:i,children:s("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:i,onClick:a,children:s("common.confirm")})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:n,children:jsxRuntime.jsx(ui.CloseIcon,{size:16,color:"white",opacity:1})})]})};var Re=e=>{let{inputRef:t,dp:r,value:o,setValue:n,setEditing:i,error:a,handleKeyDown:s,onClick:d,onClose:u,onFocus:l,onBlur:f,hintInfo:S}=e;react.useEffect(()=>{let h=t.current;if(h){let p=h.value.length;h.setSelectionRange(p,p);}i(true);},[]);let C=(S?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:S,open:C,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=>n(h),helpText:a,onClick:h=>{h.stopPropagation(),h.preventDefault();},autoComplete:"off",onFocus:l,onBlur:f,onKeyDown:s,autoFocus:true,color:C?"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 Kr=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),[o,n]=react.useState(()=>t.type===types.OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[i,a]=react.useState(false),[s,d]=react.useState(false),u=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&u,[f,S]=react.useState(false),{editOrder:C,editAlgoOrder:h,checkMinNotional:p}=Z(),{base:P,quote_dp:w}=$(),T=hooks.useSymbolPriceRange(t.symbol,t.side,u?t.trigger_price:void 0),q=()=>{a(false),d(false);},g=()=>{a(false),n(t.price?.toString()??"Market"),d(false);},E=react.useMemo(()=>!T||l||!s?"":Number(o)>T.max?r("orders.price.greaterThan",{max:T.max}):Number(o)<T.min?r("orders.price.lessThan",{min:T.min}):"",[l,s,T,o,r]),z=A=>{if(A?.stopPropagation(),A?.preventDefault(),!(E.length>0)){if(o===`${t.price}`){d(false);return}if(t.reduce_only!==true){let D=p(t.symbol,o,t.quantity);if(D){ui.toast.error(D),S(false),g();return}}a(true);}},R=A=>{A.key==="Enter"&&z(A);},O=()=>{S(true);let A=t.order_id,D={order_price:o,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(D.reduce_only=t.reduce_only),t.order_tag!==void 0&&(D={...D,order_tag:t.order_tag}),u&&(A=t.algo_order_id,D={...D,order_id:A,price:o,algo_order_id:A}),t?.visible_quantity===0&&(D.visible_quantity=0),t.tag!==void 0&&(D.order_tag=t.tag);let re;t.algo_order_id!==void 0?re=h(t.algo_order_id.toString(),D):re=C(t.order_id.toString(),D),re.then(de=>{q(),n(o);},de=>{ui.toast.error(de.message),g();}).finally(()=>S(false));},L=react.useRef(null);react.useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let F=react.useRef(null),X=A=>{F.current&&!F.current.contains(A.target)&&!i&&g();};if(react.useEffect(()=>(document.addEventListener("mousedown",X),()=>{document.removeEventListener("mousedown",X);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||o==="Market")return jsxRuntime.jsx("span",{children:r("common.marketPrice")});let Y=()=>!s||e.disableEdit?jsxRuntime.jsx(di,{order:t,price:o,setEditing:d,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:L,dp:w,value:o,setValue:n,setEditing:d,handleKeyDown:R,onClick:z,onClose:g,hintInfo:E});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(qe,{type:1,base:P,value:o,cancelPopover:g,isSubmitting:f,onConfirm:O}),children:jsxRuntime.jsx("div",{onClick:A=>{A.stopPropagation(),A.preventDefault();},ref:F,children:Y()})})},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",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var Vr=react.createContext({}),G=()=>react.useContext(Vr),Bt=e=>{let{quote_dp:t}=$(),[r,o]=react.useState(),[n]=hooks.useMutation("/v1/algo/order","DELETE"),[i]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),u=async P=>n(null,{order_id:P.algo_order_id,symbol:P.symbol}),l=async(P,w)=>i({order_id:P.algo_order_id,child_orders:P.child_orders.map(T=>({order_id:T.algo_order_id,quantity:w.order_quantity}))}),f=P=>a.cache.get(d)?.data.rows.find(T=>T.symbol===P),{sl_trigger_price:S,tp_trigger_price:C,tpPnL:h,slPnL:p}=Pi({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??false)){let P=f(e.order.symbol);P&&o(P);}},[e.order.symbol]),jsxRuntime.jsx(Vr.Provider,{value:{order:e.order,sl_trigger_price:S,tp_trigger_price:C,tpPnL:h,slPnL:p,onCancelOrder:u,onUpdateOrder:l,getRelatedPosition:f,position:r},children:e.children})};function Pi(e){let{order:t,position:r,quote_dp:o}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:n,tp_trigger_price:i}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,u=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:n,tp_trigger_price:i,slPnL:u,tpPnL:d}}var zt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[n,i]=react.useState(t.quantity.toString()),[a,s]=react.useState(false),{t:d}=i18n.useTranslation();react.useEffect(()=>{E(t.quantity.toString());},[e.order.quantity]);let[u,l]=react.useState(false),[f,S]=react.useState(),{editOrder:C,editAlgoOrder:h,checkMinNotional:p}=Z(),{onUpdateOrder:P,position:w}=G(),{base_dp:T,base:q,base_tick:g}=$(),E=async(y,b)=>{i(y);let B=Math.abs(w?.position_qty||0);if(w&&o&&Number(y)>B)S(d("orders.quantity.lessThanPosition",{quantity:B}));else {let Le=Number(y);b&&Le>b?S(d("orders.quantity.lessThan",{quantity:utils.commifyOptional(b,{fix:T})})):S(void 0);}return Promise.resolve()},z=()=>{l(false),s(false);},R=()=>{l(false),E(t.quantity.toString()),s(false);},[O,L]=react.useState(false),F=react.useRef(null),X=()=>{if(f)return;if(Number(n)===Number(t.quantity)){s(false);return}let y=t.algo_order_id!==void 0?t.trigger_price:t.price;if(y!==null&&t.reduce_only!==true){let b=p(t.symbol,y,n);if(b){ui.toast.error(b),L(false),R();return}}l(true);},v=y=>{y?.stopPropagation(),y?.preventDefault(),X();},Y=y=>{y.key==="Enter"&&(y?.stopPropagation(),y?.preventDefault(),X());},A=react.useCallback(()=>{L(true);let y={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:n,algo_order_id:t.algo_order_id};if(typeof y.algo_order_id<"u"&&y.order_type==="MARKET"){let{order_price:B,...Le}=y;y=Le;}typeof t.reduce_only<"u"&&(y.reduce_only=t.reduce_only),t.order_tag!==void 0&&(y={...y,order_tag:t.order_tag}),t?.visible_quantity===0&&(y.visible_quantity=0),t?.tag!==void 0&&(y.order_tag=t.tag);let b;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?b=P(t,y):t.algo_order_id!==void 0?b=h(t.algo_order_id.toString(),y):b=C(t.order_id.toString(),y),b.then(B=>{z(),E(n.toString());},B=>{ui.toast.error(B.message),E(t.quantity.toString()),R();}).finally(()=>L(false));},[n]),D=react.useRef(null),re=react.useRef(null),de=y=>{D.current&&re.current&&!D.current.contains(y.target)&&!re.current.contains(y.target)&&!u&&R();};react.useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[u,t.quantity]);let Ge=()=>!a||e.disableEdit?jsxRuntime.jsx(Ei,{order:t,quantity:n,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(vi,{inputRef:F,quantitySliderRef:re,base_dp:T,base_tick:g,quantity:n,setQuantity:E,editing:a,setEditing:s,handleKeyDown:Y,onClick:v,onClose:R,symbol:t.symbol,reduce_only:o,positionQty:w?.position_qty,error:f,confirmOpen:u,side:t.side,order:t,setError:S});return jsxRuntime.jsx(ui.Popover,{open:u,onOpenChange:l,content:jsxRuntime.jsx(qe,{type:0,base:q,value:n,cancelPopover:R,isSubmitting:O,onConfirm:A}),contentProps:{onOpenAutoFocus:y=>{}},children:jsxRuntime.jsx("div",{onClick:y=>{y.stopPropagation(),y.preventDefault();},ref:D,children:Ge()})})},Ei=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",ne(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})},vi=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:n,quantity:i,setQuantity:a,editing:s,setEditing:d,handleKeyDown:u,onClick:l,onClose:f,error:S,symbol:C,reduce_only:h,positionQty:p,confirmOpen:P,side:w,order:T}=e,q=hooks.useMaxQty(C,T.side,T.reduce_only),g=react.useMemo(()=>h?Math.abs(p??0):T.quantity+Math.abs(q),[T.quantity,q,h,p]),[E,z]=react.useState(void 0);react.useEffect(()=>{if(E===void 0){let O=new utils.Decimal(i).div(g).abs().mul(100).toNumber();z(O);}},[E,g,i]);let R=async O=>(n>0&&(O=hooks.utils.formatNumber(O,n)??O),a(`${O}`,g));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!P,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(Re,{inputRef:t,dp:o,value:i,setValue:O=>{let L=Math.abs(Math.min(Number(O),g)).toString();if(a(O,g),O.endsWith("."))return;if(Number(L)===0){z(0);return}let F=new utils.Decimal(O).div(g).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();z(Math.min(100,F));},setEditing:d,handleKeyDown:u,onClick:l,onClose:f,onBlur:O=>{R(O.target.value);},hintInfo:S})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:O=>{O.preventDefault();},children:jsxRuntime.jsxs(ui.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${E}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[E??0],onValueChange:O=>{let L=Array.from(O.values());z(L[0]);let F=new utils.Decimal(L[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(F,g);},onValueCommit:O=>{let L=new utils.Decimal(O[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);R(L).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Ai,{onClick:O=>{z(O*100);let L=new utils.Decimal(O).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);L=hooks.utils.formatNumber(L,n)??L,a(L,g),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(L.length,L.length);},100);}})]})]})})]})},Ai=e=>{let{t}=i18n.useTranslation(),r=[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:t("common.max"),value:1}];return jsxRuntime.jsx(ui.Flex,{gap:2,width:"100%",children:r.map((o,n)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(o.value);},className:"oui-w-1/5",children:o.label},n))})};var to=e=>{let{record:t}=e,[r,o]=react.useState(false),[n,{data:i,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),{t:u}=i18n.useTranslation(),l=hooks.useConfig("brokerId"),f=react.useCallback(()=>{o(false);let S={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)&&(S.visible_quantity=0),typeof t.reduce_only<"u"&&(S.reduce_only=t.reduce_only),n(S);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:S=>{d||(S.preventDefault(),S.stopPropagation(),f());},children:u("orders.history.renew")})};var ro=e=>{let{position:t,order:r}=G(),{quote_dp:o,base_dp:n}=$(),{t:i}=i18n.useTranslation();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:n,position:t,order:r,label:i("common.edit"),isEditing:true})};var no=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=G(),{t:r}=i18n.useTranslation();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${r("tpsl.tp")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${r("tpsl.sl")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null]})};function io(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:hooks.utils.findTPSLFromOrder(e),o=r?`${i18n.i18n.t("tpsl.tp")} - ${i18n.i18n.t("common.marketPrice")}`:void 0,n=t?`${i18n.i18n.t("tpsl.sl")} - ${i18n.i18n.t("common.marketPrice")}`:void 0;return {tpTriggerPrice:o,slTriggerPrice:n}}var uo=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=G();return jsxRuntime.jsx(Ji,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:true})},Ji=e=>{let{direction:t="row",order:r,position:o}=e,n=hooks.useSymbolsInfo(),{t:i}=i18n.useTranslation(),a=react.useMemo(()=>{let u=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&u.push(jsxRuntime.jsx(so,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:n[r.symbol]()},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(so,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:n[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:u})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),s=react.useMemo(()=>{let u=[];return r?.symbol?(e.takeProfitPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.tp")} -`,"\xA0"]}):""},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}):""},"sl")),u.length===0?jsxRuntime.jsx("span",{children:"-"}):(u.length===2&&t==="row"&&u.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),u)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol,i]),d=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:s});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:d}):d},so=e=>{let{qty:t,price:r,entryPrice:o,orderSide:n,orderType:i,symbolInfo:a}=e,{t:s}=i18n.useTranslation(),d=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:n,orderType:i},{symbol:a}),l=(i===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL")==="TP"?`${s("tpsl.tpPnl")}:`:`${s("tpsl.slPnl")}:`;return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:l}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:d===0?"oui-text-base-contrast-36":d>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:d===0?"":d>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(d)}`})]})};var yo=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let n=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=react.useState(false),[d,u]=react.useState(false),[l,f]=react.useState(false),{editAlgoOrder:S,checkMinNotional:C}=Z(),{base:h,quote_dp:p,quote_max:P,quote_min:w}=$(),T=react.useMemo(()=>{if(!((!n||i)&&!d)){if(Number(r)>P)return `Trigger price must be less than ${P}`;if(Number(r)<w)return `Trigger price must be greater than ${w}`}},[d,r,n,i]),q=()=>{s(false),u(false);},g=()=>{o(t.trigger_price?.toString()??"0"),s(false),u(false);},E=react.useRef(null),z=v=>{E.current&&!E.current.contains(v.target)&&!a&&g();};react.useEffect(()=>(document.addEventListener("mousedown",z),()=>{document.removeEventListener("mousedown",z);}),[a,t.trigger_price]);let R=v=>{if(v?.stopPropagation(),v?.preventDefault(),u(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let Y=C(t.symbol,t.price,t.quantity);if(Y){ui.toast.error(Y),f(false),g();return}}s(true);}},O=v=>{v.key==="Enter"&&R(v);},L=()=>{if((T??"").length>0)return;f(true);let v={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(v={...v,order_tag:t.order_tag}),S(`${t.algo_order_id}`,v).then(Y=>{q(),o(r);},Y=>{ui.toast.error(Y.message),o(t.trigger_price?.toString()??"--"),g();}).finally(()=>f(false));},F=react.useRef(null);if(!n||i)return jsxRuntime.jsx(ui.Text,{children:"--"});let X=()=>!d||e.disableEdit?jsxRuntime.jsx(ea,{order:t,price:r,setEditing:u,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:F,dp:p,value:r,setValue:o,setEditing:u,handleKeyDown:O,onClick:R,onClose:g,hintInfo:T});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(qe,{type:2,base:h,value:r,cancelPopover:g,isSubmitting:l,onConfirm:L}),children:jsxRuntime.jsx("div",{onClick:v=>{v.stopPropagation(),v.preventDefault();},ref:E,children:X()})})},ea=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var Oo=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o,sharePnLConfig:n}=e,{t:i}=i18n.useTranslation();return react.useMemo(()=>{switch(t){case "all":return [Ie({width:130,showType:true,onSymbolChange:r,enableSort:false}),aa({width:130}),Me({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:130,title:i("common.orderPrice"),disableEdit:true,enableSort:false}),bt({width:130,enableSort:false}),bo({width:130,symbolsInfo:e.symbolsInfo}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:130,enableSort:false}),rt({width:130}),ot({width:130}),Ee({width:130}),$e({width:130}),Po({width:130}),Ue({width:160,enableSort:false})];case "pending":return [Ie({width:172,showType:true,onSymbolChange:r,enableSort:false}),Me({width:162,className:"oui-pr-0",enableSort:false}),We({width:162,className:"oui-pr-0",enableSort:false}),tt({width:162,className:"oui-pr-0"}),ua({width:130}),ze({width:162,isPending:true}),Ee({width:162}),$e({width:162}),Ue({width:162,enableSort:false}),ma({width:162})];case "tp_sl":return [Ie({width:176,showType:true,onSymbolChange:r,enableSort:false}),sa({width:176}),bo({width:176,symbolsInfo:e.symbolsInfo}),la({width:176}),ca({width:176}),Ee({width:176}),Ue({width:176,enableSort:false}),pa({width:176})];case "filled":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,title:i("common.orderPrice"),disableEdit:true}),da({width:124}),tt({width:124,disableEdit:true}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo,hideShare:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "cancelled":return [Ie({showType:true,width:154,onSymbolChange:r,enableSort:false}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:124,disableEdit:true,enableSort:false}),bt({width:124,enableSort:false}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124})];case "rejected":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,disableEdit:true}),bt({width:124}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "orderHistory":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),We({width:124,disableEdit:true}),bt({width:124}),tt({width:124,disableEdit:true}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:150}),Po({width:80})]}},[t,o,n,i])};function Ie(e){return {title:i18n.i18n.t("common.symbol"),dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let o=ce(r)?.join(","),n=o?.length?` (${o})`:"";return `${t.split("_")[1]}-PERP${n}`},render:(t,r)=>{let o=ne(r);return jsxRuntime.jsxs(ui.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:n=>{e?.onSymbolChange?.({symbol:t}),n.stopPropagation(),n.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(r)?.map((n,i)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",className:"oui-break-normal oui-whitespace-nowrap",children:n},i))})]})]})}}}function aa(e){return {title:i18n.i18n.t("common.side"),dataIndex:"side",width:e?.width,onSort:e?.enableSort?(t,r,o)=>r.side.localeCompare(t.side):void 0,renderPlantText:(t,r)=>ue(t),render:(t,r)=>{let o=ne(r)?"oui-text-base-contrast-20":t===types.OrderSide.BUY?"oui-text-trade-profit":"oui-text-trade-loss";return jsxRuntime.jsx("span",{className:ui.cn("oui-font-semibold",o),children:ue(t)})}}}function Me(e){return {title:i18n.i18n.t("orders.column.fill&Quantity"),dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o} / `)+`${r.quantity}`},render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(zt,{order:r,disableEdit:e?.disableEdit})}}function sa(e){return {title:i18n.i18n.t("common.quantity"),className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(zt,{order:r})}}function We(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,o)=>it(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>utils.commifyOptional(r.price?.toString(),{fallback:i18n.i18n.t("common.marketPrice")}),render:(t,r)=>jsxRuntime.jsx(Kr,{order:r,disableEdit:e?.disableEdit})}}function la(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:o,slTriggerPrice:n}=io(r),i=`${o||""}${n?`${o?`
17
- `:""}${n}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsxRuntime.jsx(no,{})}}function da(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>utils.commifyOptional(t)}}function tt(e){return {title:i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=r?.algo_order_id!==void 0,n=r?.algo_type==="BRACKET";return !o||n?"--":utils.commifyOptional(t)},render:(t,r)=>jsxRuntime.jsx(yo,{order:r,disableEdit:e?.disableEdit})}}function bo(e){return {title:e?.title??i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r),s=(a!=null?`${i18n.i18n.t("tpsl.tp")}: ${utils.commifyOptional(a,{fix:n,padEnd:true})}`:"")+(i!=null?`${a?`
18
- `:""}${i18n.i18n.t("tpsl.sl")}: ${utils.commifyOptional(i,{fix:n,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsxRuntime.jsx(uo,{})}}function ua(e){return {title:i18n.i18n.t("common.tpsl"),className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:n,tp_trigger_price:i}=o(),a=(i!=null?`${i18n.i18n.t("tpsl.tp")}: ${i}`:"")+(n!=null?`${i?`
19
- `:""}${i18n.i18n.t("tpsl.sl")}: ${n}`:"");return a.length>0?a:"--"},render:(t,r)=>jsxRuntime.jsx(kr,{order:r})}}function ze(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,o)=>{let n=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return it(n,i)}:void 0,renderPlantText:(t,r)=>Vt(r,e?.isPending??false)==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(Vt(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let o=Vt(r,e?.isPending??false);return o==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:o})}}}function Ht(e){return {title:i18n.i18n.t("common.realizedPnl"),dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??n,a=new utils.Decimal(t??0).toDecimalPlaces(i,utils.Decimal.ROUND_DOWN).toNumber(),s=utils.commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:o}=$(),n=e?.pnlNotionalDecimalPrecision??o,i=new utils.Decimal(t??0).toDecimalPlaces(n,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:n,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsxRuntime.jsx(Je,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:uiShare.SharePnLDialogId})]})}}}function Ee(e){return {title:i18n.i18n.t("orderEntry.reduceOnly"),dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no"),render:t=>jsxRuntime.jsx(ui.Text,{children:t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no")})}}function $e(e){return {title:i18n.i18n.t("orders.column.hidden"),dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes"),render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes")})}}function Ue(e){return {title:i18n.i18n.t("orders.column.orderTime"),dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let o=new Date(t);return dateFns.format(o,"yyyy-MM-dd HH:mm:ss")},render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function rt(e){return {title:i18n.i18n.t("common.fee"),dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function ca(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function ot(e){let t={[types.OrderStatus.NEW]:i18n.i18n.t("orders.status.pending"),[types.OrderStatus.FILLED]:i18n.i18n.t("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:i18n.i18n.t("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:i18n.i18n.t("orders.status.canceled"),[types.OrderStatus.REJECTED]:i18n.i18n.t("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:i18n.i18n.t("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:i18n.i18n.t("orders.status.completed")};return {title:i18n.i18n.t("common.status"),dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)},render:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)}}}function bt(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>it(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===types.OrderType.MARKET&&!t?"--":jsxRuntime.jsx(ui.Text,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>utils.commifyOptional(t,{fix:2})}}function Po(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(to,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(mt,{order:r}):null}}function ma(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(mt,{order:r})}}function pa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(ro,{order:r}),jsxRuntime.jsx(mt,{order:r})]})}}function it(e,t){return e>t?1:e<t?-1:0}function Vt(e,t){return t?e.price&&e.quantity?new utils.Decimal(e.price).mul(e.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--":e.type===types.OrderType.CLOSE_POSITION&&e.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var To=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui.Badge,{color:r?"success":"danger",size:"xs",children:o(r?"common.buy":"common.sell")}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Lo=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}`:ue(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(e.item)?.map((o,n)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},n))})},No=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})},wo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.status||t.algo_status,n=react.useMemo(()=>({[types.OrderStatus.NEW]:r("orders.status.pending"),[types.OrderStatus.FILLED]:r("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:r("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:r("orders.status.canceled"),[types.OrderStatus.REJECTED]:r("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:r("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:r("orders.status.completed")}),[r]);return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,size:"2xs",children:n[o]||ue(o)})},Jt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:r("common.qty"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:r("tpsl.entirePosition"),intensity:80,children:o?r("tpsl.entirePosition"):t.quantity})})},Xt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:r("orders.status.filled")}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var Io=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:[r("common.notional"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o})})},Zt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("orders.column.triggerPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},Eo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("common.markPrice"),align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},vo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&o;return jsxRuntime.jsx(ui.Statistic,{label:r("common.limitPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsxRuntime.jsx(ui.Text,{children:r("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},Ao=e=>{let{tp_trigger_price:t,tpPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.tpTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(xt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.tpPnl")}:`,"\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Do=e=>{let{sl_trigger_price:t,slPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.slTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(xt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.slPnl")}:`,"\xA0\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Fo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.tpPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},ko=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.slPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},qo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:r("tpsl.entirePosition")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t,r]);return jsxRuntime.jsx(ui.Statistic,{label:r("common.quantity"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:o})},Ro=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.avgPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:e.item?.average_executed_price??"--"})})},Bo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.orderPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,placeholder:t("common.marketPrice"),children:e.item?.price??"--"})})},Mo=e=>{let t=e?.item?.realized_pnl,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[r("common.realizedPnl"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"}),jsxRuntime.jsx(Je,{order:e.item,sharePnLConfig:e.sharePnLConfig,modalId:uiShare.SharePnLBottomSheetId,iconSize:12})]})})},xt=e=>{let{classNames:t,content:r}=e,[o,n]=react.useState(false);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:n,arrow:{className:t?.arrow},children:jsxRuntime.jsx("div",{onClick:()=>n(i=>!i),children:e.children})})},Wo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsxs(ui.Flex,{justify:"end",gapX:1,mt:1,children:[jsxRuntime.jsxs(ui.Text,{size:"2xs",intensity:36,children:[t("common.fee"),":"]}),jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:80,children:e.item?.total_fee??"--"})]})};var er=e=>{let{t}=i18n.useTranslation();return !e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(xt,{classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof e.pnl?.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:true,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"sell",children:e.pnl?.slPnL})]}),children:jsxRuntime.jsx("button",{onClick:()=>{e.setOpen(!e.open);},children:jsxRuntime.jsxs(ui.Flex,{gap:1,width:"1",children:[e.tp_trigger_price&&jsxRuntime.jsx($o,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx($o,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})})},$o=e=>{let{type:t,value:r,quote_dp:o}=e;return r?jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",className:ui.cn("oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,padding:false,rm:utils.Decimal.ROUND_DOWN,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-36",children:[`${t} `,":\xA0\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var tr=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[n,i]=react.useState(false),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:d,roi:u}=ct(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:d,roi:u,quote_dp:r,open:n,setOpen:i}};var rr=e=>{let t=tr(e);return jsxRuntime.jsx(er,{...t})};var nr=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:r=>e.setOpen(true),children:t("common.cancel")}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:t("orders.cancelOrder"),actions:{primary:{label:t("common.confirm"),loading:e.isLoading,fullWidth:true,size:"md",onClick:r=>{e.onCancel(r);}},secondary:{label:t("common.cancel"),fullWidth:true,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:t("orders.cancelOrder.description")})})]})};var ir=e=>{let{state:t}=e,[r,o]=react.useState(false),{onCancelOrder:n}=Z(),[i,a]=react.useState(false);return {...t,open:r,setOpen:o,onCancel:u=>n?(u?.preventDefault(),u?.stopPropagation(),a(true),n(t.item).then(l=>{o(false);},l=>{ui.toast.error(l.message);}).finally(()=>{a(false);})):Promise.resolve(),onClose:()=>{o(false);},isLoading:i}};var ar=e=>{let t=ir(e);return jsxRuntime.jsx(nr,{...t})};var sr=e=>{let {t}=i18n.useTranslation(),{item:r}=e;r.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:t("common.edit")})})};var Ho=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:n,isAlgoOrder:i}=e,a=t===types.OrderSide.BUY,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-2",children:[jsxRuntime.jsx(ui.Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxRuntime.jsxs(ui.Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ce(e.item)?.map((d,u)=>jsxRuntime.jsx(ui.Badge,{color:d.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:d},u)),a&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:s("common.buy")}),!a&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:s("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{}),jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[i&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("orders.column.triggerPrice")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:n??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.price")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?s("common.marketPrice"):"--",children:e.isStopMarket?s("common.marketPrice"):r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.qty")}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o??"--"})]})]}),jsxRuntime.jsxs(ui.Flex,{className:"oui-gap-[2px]",children:[jsxRuntime.jsx(ui.Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:d=>{e.setOrderConfirm(!d);}}),jsxRuntime.jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:s("orderEntry.disableOrderConfirm")})]})]})};var pr=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation(),{parseErrorMsg:n}=reactApp.useOrderEntryFormErrorMsg(e.errors),i=n("order_quantity"),a=n("order_price"),s=n("trigger_price"),d=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,u=l=>{let f=e.baseTick;if(f&&f>0){let S=hooks.utils.formatNumber(l,f)??l;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:true,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ce(e.item)?.map((l,f)=>jsxRuntime.jsx(ui.Badge,{color:l.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:l},f)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:o("common.buy")}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:o("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{intensity:8,className:"oui-w-full"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:o("common.lastPrice")}),jsxRuntime.jsx(ui.Text.numeral,{dp:e.item?.symbolInfo?.duote_dp,children:e.curMarkPrice??"--"})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",direction:"column",itemAlign:"stretch",gap:2,children:[e.isAlgoOrder&&jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("orders.column.triggerPrice")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:s?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:l=>e.setTriggerPrice(l),tooltip:s,tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast oui-w-full",root:ui.cn("oui-outline-line-12",s&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.price")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:a?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?o("orderEntry.orderType.market"):e.price,onValueChange:l=>e.setPrice(l),tooltip:a,tooltipProps:{content:{className:"oui-bg-base-5"},arrow:{className:"oui-fill-base-5"}},classNames:{input:"oui-text-base-contrast",root:ui.cn("oui-outline-line-12",a&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.quantity")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:i?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:l=>{e.setQuantity(l);},onBlur:l=>u(l.target.value),tooltip:i,tooltipProps:{content:{className:"oui-bg-base-6"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast",root:ui.cn("oui-outline-line-12",i&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:l=>{e.setSliderValue(l[0]);},color:"primary"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:false,rule:"percentages",children:`${d??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,onClick:()=>{e.setQuantity(e.maxQty.toString());},children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primary",children:o("common.max")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:54,size:"2xs",dp:e.base_dp,children:e.maxQty})]})]})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",gap:3,mt:2,children:[jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"secondary",onClick:l=>{e.onClose();},children:o("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:true,onClick:l=>{l.stopPropagation(),l.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:o("common.confirm")})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:o("orders.editOrder"),size:"xs",actions:{primary:{label:o("common.confirm"),onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:true},secondary:{label:o("common.cancel"),onClick:e.onCloseDialog,fullWidth:true}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(Ho,{...e})})]})};var br=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:n=true,position:i}=e,{item:a}=t,{hide:s}=ui.useModal(),[d,u]=react.useState(false),l=a?.algo_order_id!==void 0&&a.algo_type!==types.AlgoOrderRootType.BRACKET,f=a?.type==="MARKET"&&l;f||a?.type==="MARKET";let [C,h]=react.useState(false),p=react.useMemo(()=>l&&a.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${a.type}`:a.type,[a,l]),[P,w]=hooks.useLocalStorage("orderly_order_confirm",true),{base_dp:T,base_tick:q}=e.state,{formattedOrder:g,setValue:E,markPrice:R,errors:O,validate:L,maxQty:F}=os({order:a,orderType:p,position:i}),X=()=>{L().then(b=>{P?u(true):D(g);},b=>{b?.total?.message&&ui.toast.error(b?.total.message);}).catch(b=>{});},v=react.useCallback(()=>{u(false);},[]),Y=()=>g?D(g):Promise.reject(),A=react.useCallback(()=>{s();},[]),D=react.useCallback(async b=>{let B,Le=a.visible_quantity!==void 0?a.visible_quantity===0:a.visible!==void 0?a.visible===0:false;if(a.algo_order_id!==void 0){if(f&&"order_price"in b){let{order_price:Ne,...Lt}=b;b=Lt;}B=r(a.algo_order_id.toString(),{...b});}else B=o(a.order_id.toString(),{...b,...Le?{visible_quantity:0}:{}});try{h(!0);let Ne=await B;A();}catch(Ne){ui.toast.error(Ne?.message??`${Ne}`);}finally{h(false);}},[r,o]),re=react.useMemo(()=>{let b=g.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},[g.order_quantity,F]),de=a.price!=g.order_price||a.quantity!=g.order_quantity||a.trigger_price!=g.trigger_price,Ge=hooks.useThrottledCallback(b=>{let B=new utils.Decimal(b).div(100).mul(F).toDecimalPlaces(T,utils.Decimal.ROUND_DOWN).toNumber();E("order_quantity",hooks.utils.formatNumber(B,q));},50,{}),y=(b,B)=>{E(b,B);};return {...t,curMarkPrice:R,isAlgoOrder:l,isStopMarket:f,price:g.order_price,setPrice:b=>y("order_price",b),priceEdit:!f,triggerPrice:g.trigger_price,setTriggerPrice:b=>y("trigger_price",b),quantity:g.order_quantity,setQuantity:b=>{y("order_quantity",b);},maxQty:F,sliderValue:re,setSliderValue:Ge,onClose:A,onSheetConfirm:X,errors:O,orderType:p,isChanged:de,baseTick:q,dialogOpen:d,setDialogOpen:u,onDialogConfirm:Y,onCloseDialog:v,submitting:C,orderConfirm:P,setOrderConfirm:w}},os=e=>{let{order:t,orderType:r,position:o}=e,[n,i]=react.useState({side:t.side,order_type:r,order_price:t.price,order_quantity:t.quantity,trigger_price:t.trigger_price,reduce_only:t.reduce_only,symbol:t.symbol}),{reduce_only:a}=t,s=o?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),u=react.useMemo(()=>a?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,a,s]),{symbolInfo:l,markPrice:f,errors:S,validate:C}=hooks.useOrderEntity({...n,symbol:t.symbol},{maxQty:u});return {symbolInfo:l,markPrice:f,errors:S,validate:C,setValue:(p,P)=>{i(w=>({...w,[p]:P}));},formattedOrder:n,maxQty:u}};var Pr=e=>{let t=br(e);return jsxRuntime.jsx(pr,{...t})};var xr=e=>{let{state:t}=e,{t:r}=i18n.useTranslation(),{editAlgoOrder:o,editOrder:n}=Z(),{order:i,position:a}=G(),s=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({title:r("common.tpsl"),content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:true,order:e.state.item,position:a,symbolInfo:e.state.origin})}).catch(d=>{}):ui.modal.sheet({title:r("orders.editOrder"),classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(Pr,{position:a,state:t,editAlgoOrder:o,editOrder:n})}).catch(d=>{});},[t]);return {...t,onShowEditSheet:s}};var Sr=e=>{let t=xr(e);return jsxRuntime.jsx(sr,{...t})};var _r=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(us,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(cs,{...e}),e.type==="pending"&&jsxRuntime.jsx(rr,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(ms,{...e})]}),us=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(To,{...e}),jsxRuntime.jsx(No,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Lo,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(wo,{...e})]})]}),cs=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:ps(e)}),ms=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Sr,{state:e}),jsxRuntime.jsx(ar,{state:e})]});function ps(e){switch(e.type){case "all":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "pending":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Jt,{...e}),jsxRuntime.jsx(Xt,{...e}),jsxRuntime.jsx(Io,{...e}),jsxRuntime.jsx(Zt,{...e}),jsxRuntime.jsx(vo,{...e}),jsxRuntime.jsx(Eo,{...e})]});case "tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Ao,{...e}),jsxRuntime.jsx(Fo,{...e}),jsxRuntime.jsx(qo,{...e}),jsxRuntime.jsx(Do,{...e}),jsxRuntime.jsx(ko,{...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(Jt,{...e}),jsxRuntime.jsx(Xt,{...e}),jsxRuntime.jsx(Zt,{...e,align:"end"}),jsxRuntime.jsx(Ro,{...e}),jsxRuntime.jsx(Bo,{...e}),jsxRuntime.jsx(Mo,{...e}),jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Wo,{...e})]})}}var Or=e=>{let t=$();return {...e,...t}};var hr=e=>{let{className:t,...r}=e,o=Or(r);return jsxRuntime.jsx(_r,{...o,className:t})};var Cr=e=>{let{sharePnLConfig:t,...r}=e,o=Oo({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:t,symbolsInfo:e.symbolsInfo});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:n=>{e.onFilter(n);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(hs,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:o,loading:e.isLoading,dataSource:e.dataSource,bordered:true,ignoreLoadingCheck:true,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(n,i)=>({className:ui.cn("oui-h-[48px]",ne(n)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(n,i)=>`${e.type}${i}${n.order_id||n.algo_order_id}_index${i}`,renderRowContainer:(n,i,a)=>((e.type==="tp_sl"||e.type==="pending")&&(a=jsxRuntime.jsx(Bt,{order:n,children:a})),jsxRuntime.jsx(At,{symbol:n.symbol,children:a})),pagination:e.pagination,manualPagination:e.manualPagination,features:[ui.TableFeatures.DownloadFeature],getTableInstance:n=>{e.tableInstance.current=n;}})]})})},Tr=e=>{let{t}=i18n.useTranslation();return 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-w-full oui-grid-rows-[auto,1fr]",gap:2,children:[e.showFilter?jsxRuntime.jsx(ui.Flex,{gap:2,p:2,className:"oui-rounded-b-xl oui-bg-base-9",children:e.filterItems.map(r=>r.type!=="select"?null:jsxRuntime.jsx(ui.Picker,{options:r.options,size:"sm",value:r.value,className:"oui-text-2xs oui-text-base-contrast-54 ",placeholder:r.name==="side"?t("common.side.all"):r.name==="status"?t("common.status.all"):"",onValueChange:o=>{e.onFilter?.({name:r.name,value:o});}},`item-${r.name}`))}):jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ui.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(r,o)=>{let n=jsxRuntime.jsx(hr,{item:r,index:o,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange,sharePnLConfig:e.sharePnLConfig});return ["tp_sl","pending"].includes(e.type)&&(n=jsxRuntime.jsx(Bt,{order:r,children:n})),jsxRuntime.jsx(At,{symbol:r.symbol,children:n})}})]})})},hs=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",disabled:(e.dataSource?.length??0)==0,className:"disabled:oui-bg-transport",onClick:r=>e.onCancelAll(),"data-testid":`oui-testid-dataList-${e.type.toLowerCase()}-cancelAll-button`,children:t("orders.cancelAll")})};var rn=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let n=e[o];if(n.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||n.algo_type===types.AlgoOrderRootType.TP_SL)if(n.algo_status!==types.OrderStatus.FILLED&&n.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];!a.is_activated||!a.trigger_price||(a.parent_algo_type=n.algo_type,r.push(a));}else for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=n.algo_type,r.push(a));}else r.push(n);}return r},[e]);var Tt=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=false,onSymbolChange:n,filterConfig:i,pnlNotionalDecimalPrecision:a,sharePnLConfig:s}=e,{t:d}=i18n.useTranslation(),u=hooks.useSymbolsInfo(),l=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),f=50,{page:S,pageSize:C,setPage:h,pagination:p,parsePagination:P}=ui.usePagination({pageSize:f});react.useEffect(()=>{h(1);},[e.symbol]);let{orderStatus:w,ordersSide:T,dateRange:q,filterItems:g,onFilter:E,filterDays:z,updateFilterDays:R}=Rs(r,{ordersStatus:t,setPage:h,filterConfig:i}),O=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),L=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),F=react.useRef();react.useImperativeHandle(e.ref,()=>({download:()=>{let Nt=`orders_${dateFns.format(new Date,"yyyyMMdd_HHmmss")}`;F.current?.download(Nt);}}));let[X,{isLoading:v,loadMore:Y,cancelOrder:A,updateOrder:D,cancelAlgoOrder:re,updateAlgoOrder:de,cancelAllOrders:Ge,cancelAllTPSLOrders:y,meta:b,refresh:B}]=hooks.useOrderStream({symbol:e.symbol,status:w,side:T,page:o||!l?void 0:S,size:l?C:500,sourceTypeAll:r==="orderHistory",dateRange:q,includes:O,excludes:L}),Le=`orderly_${r}_pageSize`,[Ne,Lt]=hooks.useLocalStorage(Le,f);react.useEffect(()=>{Ne!==C&&Lt(C);},[C,Ne]);let ln=react.useCallback(()=>{let Nt=e.type==="pending"?d("orders.pending.cancelAll"):e.type==="tp_sl"?d("orders.tpsl.cancelAll"):"",mn=d("orders.pending.cancelAll.description");ui.modal.confirm({title:Nt,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:mn}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await y():await Ge(),B(),Promise.resolve(!0)}catch(Nr){return Nr?.message!==void 0&&toast.error(Nr.message),Promise.resolve(false)}finally{Promise.resolve();}}});},[r,d]),dn=rn(X??[]),un=reactApp.useDataTap(r!=="tp_sl"?dn:X,{fallbackData:[]})??void 0,cn=react.useMemo(()=>l?P(b):p,[b,l,P,p]);return {type:r,dataSource:un,isLoading:v,loadMore:Y,cancelOrder:A,updateOrder:D,cancelAlgoOrder:re,updateAlgoOrder:de,pagination:cn,manualPagination:l,pnlNotionalDecimalPrecision:a,onFilter:E,filterItems:g,onCancelAll:ln,onSymbolChange:n,sharePnLConfig:s,tableInstance:F,symbolsInfo:u,filterDays:z,updateFilterDays:R}},Rs=(e,t)=>{let{t:r}=i18n.useTranslation(),[o,n]=react.useState(t.ordersStatus??"all"),[i,a]=react.useState(t.filterConfig?.side??"all"),[s,d]=react.useState(90),u=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Lr({to:new Date,from:Fe(dateFns.subDays(new Date,89))}):{}),[l,f]=react.useState(u),S=p=>{d(p),f({from:Ve(dateFns.subDays(new Date,p-1)),to:Fe(new Date)}),t.setPage(1);},C=p=>{if(p.name==="side"&&(a(p.value),t.setPage(1)),p.name==="status"&&(n(p.value),t.setPage(1)),p.name==="dateRange"){f(Lr(p.value)),t.setPage(1);let P=Lr(p.value);if(P.from&&P.to){let w=Math.abs(dateFns.differenceInDays(P.from,P.to))+1,q={1:{from:Ve(new Date),to:Fe(new Date)},7:{from:Ve(dateFns.subDays(new Date,6)),to:Fe(new Date)},30:{from:Ve(dateFns.subDays(new Date,29)),to:Fe(new Date)},90:{from:Ve(dateFns.subDays(new Date,89)),to:Fe(new Date)}}[w];q&&It(q.from,P.from)&&It(q.to,P.to)?d(w):d(null);}}};return {filterItems:react.useMemo(()=>{let p={type:"select",name:"side",options:[{label:r("common.side.all"),value:"all"},{label:r("common.buy"),value:"BUY"},{label:r("common.sell"),value:"SELL"}],value:i},P={type:"range",name:"dateRange",value:l},w={type:"select",name:"status",options:[{label:r("common.status.all"),value:"all"},{label:r("orders.status.pending"),value:types.OrderStatus.INCOMPLETE},{label:r("orders.status.filled"),value:types.OrderStatus.FILLED},{label:r("orders.status.partialFilled"),value:types.OrderStatus.PARTIAL_FILLED},{label:r("orders.status.canceled"),value:types.OrderStatus.CANCELLED},{label:r("orders.status.rejected"),value:types.OrderStatus.REJECTED}],value:o};switch(e){case "all":return [p,w,P];case "pending":return [p];case "tp_sl":return [p];case "filled":return [p];case "cancelled":return [p];case "rejected":return [p];case "orderHistory":return [p,w,P]}},[e,i,o,l,r]),onFilter:C,ordersSide:i==="all"?void 0:i,dateRange:l,orderStatus:o==="all"?void 0:o,filterDays:s,updateFilterDays:S}};function Ve(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Fe(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Lr=e=>({from:Ve(e.from),to:Fe(e.to??e.from)});var Te=react.forwardRef((e,t)=>{let{testIds:r,...o}=e,n=Tt({...o,ref:t});return jsxRuntime.jsx(Cr,{...n,testIds:r})}),Ws=e=>{let t=Tt({...e,enableLoadMore:true});return jsxRuntime.jsx(Tr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var sn=e=>{let{t}=i18n.useTranslation(),r={pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision};return jsxRuntime.jsxs(ui.Tabs,{defaultValue:e.current||"all",variant:"contained",className:"oui-h-full",classNames:{tabsContent:"oui-h-[calc(100%_-_28px)]"},children:[jsxRuntime.jsx(ui.TabPanel,{value:"all",title:t("common.all"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:t("orders.status.pending"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:t("common.tpsl"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:t("orders.status.filled"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:t("orders.status.canceled"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:t("orders.status.rejected"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"rejected",ordersStatus:types.OrderStatus.REJECTED,...r})})]})};var Se=(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))(Se||{}),Qs=react.forwardRef((e,t)=>{let r=wt({...e,ref:t});return jsxRuntime.jsx(sn,{...r})});
16
+ var Et=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:o}=e,n=react.useRef(null);return react.useImperativeHandle(e.ref,()=>({download:()=>{n.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:n,sharePnLConfig:o}};var ue=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ce(e){let t=e.type,r=e.algo_type;if(typeof t<"u"){let o=[];if(e.parent_algo_type){if(r===types.AlgoOrderType.STOP_LOSS){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.sl")]:[i18n.i18n.t("tpsl.sl")];o.push(...i);}if(r===types.AlgoOrderType.TAKE_PROFIT){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.tp")]:[i18n.i18n.t("tpsl.tp")];o.push(...i);}return o}let n=typeof t=="string"?t.replace("_ORDER",""):"";if([types.OrderType.ASK,types.OrderType.BID].includes(t))return [i18n.i18n.t("orderEntry.orderType.limit")];if(e.algo_order_id===void 0||e.algo_order_id&&r==="BRACKET")return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.limit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.market"),[types.OrderType.POST_ONLY]:i18n.i18n.t("orderEntry.orderType.postOnly"),[types.OrderType.IOC]:i18n.i18n.t("orderEntry.orderType.ioc"),[types.OrderType.FOK]:i18n.i18n.t("orderEntry.orderType.fok")}[n]||ue(n)];if(n)return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.stopLimit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.stopMarket")}[n]||n]}if(typeof r<"u"){let o=[];r===types.AlgoOrderRootType.POSITIONAL_TP_SL&&o.push(i18n.i18n.t("common.position"));let n=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!a.trigger_price),i=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.STOP_LOSS&&!!a.trigger_price);return (n||i)&&o.push(n&&i?i18n.i18n.t("common.tpsl"):n?i18n.i18n.t("tpsl.tp"):i18n.i18n.t("tpsl.sl")),o}}function ne(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function On(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function mt(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=On(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let n=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=i?hooks.utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,u=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:u}}}function vt(e,t){return !e||!t?false:e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}var At=react.createContext({}),$=()=>react.useContext(At);var Dt=e=>{let{symbol:t,children:r}=e,o=hooks.useSymbolsInfo()[t],n=react.useMemo(()=>({symbol:t,base_dp:o("base_dp"),quote_dp:o("quote_dp"),base_tick:o("base_tick"),quote_tick:o("quote_tick"),base:o("base"),quote:o("quote"),origin:o(),quote_max:o("quote_max"),quote_min:o("quote_min")}),[t,o]);return jsxRuntime.jsx(At.Provider,{value:n,children:r})};var kt=e=>{let{t}=i18n.useTranslation();return e.sharePnLConfig==null?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),ui.modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?t("share.pnl.share.long"):t("share.pnl.share.short"),openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsxRuntime.jsx(ui.ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})})};var Dr=e=>{let{sharePnLConfig:t,order:r,modalId:o,iconSize:n}=e,{getFirstRefCode:i}=hooks.useReferralInfo(),a=react.useMemo(()=>i()?.code,[i]),s=hooks.useSymbolLeverage(e.order.symbol);return {iconSize:n,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:o}};var Je=e=>{let t=Dr(e);return jsxRuntime.jsx(kt,{...t})};var Rr=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=$(),{t:n}=i18n.useTranslation(),{sl_trigger_price:i,tp_trigger_price:a}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:s,roi:u}=mt(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof s.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:s.tpPnL}),typeof s.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:s.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(kr,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(kr,{type:"SL",value:i,quote_dp:r})]})})},kr=e=>{let{type:t,value:r,quote_dp:o}=e,{t:n}=i18n.useTranslation();return r?jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[t==="TP"?`${n("tpsl.tp")} -`:`${n("tpsl.sl")} -`,"\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Mr=react.createContext({}),Z=()=>react.useContext(Mr),Rt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:n}=e,{t:i}=i18n.useTranslation(),a=hooks.useSymbolsInfo(),s=hooks.useMemoizedFn(async c=>c.algo_order_id!==void 0?"root_algo_order_id"in c&&c.root_algo_order_id!==c.algo_order_id?o(c.root_algo_order_id,c.symbol):o(c.algo_order_id,c.symbol).then(()=>{}):t(c.order_id,c.symbol).then(()=>{})),u=hooks.useMemoizedFn(async(c,y)=>{c.visible_quantity!==void 0?c.visible_quantity===0:c.visible!==void 0?c.visible===0:false;await ui.modal.sheet({title:i("orders.editOrder"),classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});}),l=hooks.useMemoizedFn((c,y,T)=>{let{min_notional:h}=a[c](),f=hooks.getMinNotional({price:y,qty:T,min_notional:h});if(f!==void 0)return i("orderEntry.total.error.min",{value:f})}),d=react.useMemo(()=>({onCancelOrder:s,onEditOrder:u,editOrder:r,editAlgoOrder:n,checkMinNotional:l}),[s,u,r,n,l]);return jsxRuntime.jsx(Mr.Provider,{value:d,children:e.children})};var pt=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),{onCancelOrder:o}=Z(),[n,i]=react.useState(false);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{o&&(a.preventDefault(),a.stopPropagation(),i(true),o(t).then(s=>s,s=>{ui.toast.error(s.message);}).finally(()=>{i(false);}));},loading:n,children:r("common.cancel")})};var qe=e=>{let{type:t,base:r,value:o,cancelPopover:n,isSubmitting:i,onConfirm:a}=e,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsx("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:(()=>{let l={values:{base:r,value:utils.commify(o)},components:[jsxRuntime.jsx("span",{className:"oui-text-warning-darken"})]};switch(t){case 0:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.quantity",...l});case 1:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.price",...l});case 2:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.triggerPrice",...l})}})()}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:n,disabled:i,children:s("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:i,onClick:a,children:s("common.confirm")})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:n,children:jsxRuntime.jsx(ui.CloseIcon,{size:16,color:"white",opacity:1})})]})};var Re=e=>{let{inputRef:t,dp:r,value:o,setValue:n,setEditing:i,error:a,handleKeyDown:s,onClick:u,onClose:l,onFocus:d,onBlur:c,hintInfo:y}=e;react.useEffect(()=>{let h=t.current;if(h){let f=h.value.length;h.setSelectionRange(f,f);}i(true);},[]);let T=(y?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:y,open:T,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=>n(h),helpText:a,onClick:h=>{h.stopPropagation(),h.preventDefault();},autoComplete:"off",onFocus:d,onBlur:c,onKeyDown:s,autoFocus:true,color:T?"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:u,children:jsxRuntime.jsx(ui.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Vr=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),[o,n]=react.useState(()=>t.type===types.OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[i,a]=react.useState(false),[s,u]=react.useState(false),l=t?.algo_order_id!==void 0,d=t?.type==="MARKET"&&l,[c,y]=react.useState(false),{editOrder:T,editAlgoOrder:h,checkMinNotional:f}=Z(),{base:C,quote_dp:I}=$(),L=hooks.useSymbolPriceRange(t.symbol,t.side,l?t.trigger_price:void 0),k=()=>{a(false),u(false);},g=()=>{a(false),n(t.price?.toString()??"Market"),u(false);},S=react.useMemo(()=>!L||d||!s?"":Number(o)>L.max?r("orders.price.greaterThan",{max:L.max}):Number(o)<L.min?r("orders.price.lessThan",{min:L.min}):"",[d,s,L,o,r]),R=D=>{if(D?.stopPropagation(),D?.preventDefault(),!(S.length>0)){if(o===`${t.price}`){u(false);return}if(t.reduce_only!==true){let F=f(t.symbol,o,t.quantity);if(F){ui.toast.error(F),y(false),g();return}}a(true);}},v=D=>{D.key==="Enter"&&R(D);},O=()=>{y(true);let D=t.order_id,F={order_price:o,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(F.reduce_only=t.reduce_only),t.order_tag!==void 0&&(F={...F,order_tag:t.order_tag}),l&&(D=t.algo_order_id,F={...F,order_id:D,price:o,algo_order_id:D}),t?.visible_quantity===0&&(F.visible_quantity=0),t.tag!==void 0&&(F.order_tag=t.tag);let re;t.algo_order_id!==void 0?re=h(t.algo_order_id.toString(),F):re=T(t.order_id.toString(),F),re.then(de=>{k(),n(o);},de=>{ui.toast.error(de.message),g();}).finally(()=>y(false));},N=react.useRef(null);react.useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let q=react.useRef(null),X=D=>{q.current&&!q.current.contains(D.target)&&!i&&g();};if(react.useEffect(()=>(document.addEventListener("mousedown",X),()=>{document.removeEventListener("mousedown",X);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||o==="Market")return jsxRuntime.jsx("span",{children:r("common.marketPrice")});let J=()=>!s||e.disableEdit?jsxRuntime.jsx(bi,{order:t,price:o,setEditing:u,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:N,dp:I,value:o,setValue:n,setEditing:u,handleKeyDown:v,onClick:R,onClose:g,hintInfo:S});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(qe,{type:1,base:C,value:o,cancelPopover:g,isSubmitting:c,onConfirm:O}),children:jsxRuntime.jsx("div",{onClick:D=>{D.stopPropagation(),D.preventDefault();},ref:q,children:J()})})},bi=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var Xr=react.createContext({}),K=()=>react.useContext(Xr),zt=e=>{let{order:t,children:r}=e,{quote_dp:o}=$(),[n,i]=react.useState(),[a]=hooks.useMutation("/v1/algo/order","DELETE"),[s]=hooks.useMutation("/v1/algo/order","PUT"),u=hooks.useSWRConfig(),{state:l}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",l.accountId]),[l.accountId]),c=hooks.useMemoizedFn(async S=>a(null,{order_id:S.algo_order_id,symbol:S.symbol})),y=hooks.useMemoizedFn(async(S,R)=>s({order_id:S.algo_order_id,child_orders:S.child_orders.map(v=>({order_id:v.algo_order_id,quantity:R.order_quantity}))})),T=hooks.useMemoizedFn(S=>u.cache.get(d)?.data.rows.find(v=>v.symbol===S)),{sl_trigger_price:h,tp_trigger_price:f,tpPnL:C,slPnL:I,sl_order_price:L,tp_order_price:k}=Ni({order:t,position:n,quote_dp:o});react.useEffect(()=>{if("algo_type"in t||(t?.reduce_only??false)){let S=T(t.symbol);S&&i(S);}},[t.symbol]);let g=react.useMemo(()=>({order:t,sl_trigger_price:h,tp_trigger_price:f,sl_order_price:L,tp_order_price:k,tpPnL:C,slPnL:I,position:n,onCancelOrder:c,onUpdateOrder:y,getRelatedPosition:T}),[t,h,f,L,k,C,I,n,c,y,T]);return jsxRuntime.jsx(Xr.Provider,{value:g,children:r})};function Ni(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 n="algo_type"in t&&Array.isArray(t.child_orders),{sl_trigger_price:i,tp_trigger_price:a}=n?hooks.findTPSLFromOrder(t):{sl_trigger_price:void 0,tp_trigger_price:void 0},{sl_order_price:s,tp_order_price:u}=n?hooks.findTPSLOrderPriceFromOrder(t):{sl_order_price:void 0,tp_order_price:void 0},l=t.quantity;l===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(l=r.position_qty);let d=r.average_open_price,c=typeof l=="number"&&typeof a=="number"&&typeof d=="number"?hooks.utils.priceToPnl({qty:l,price:a,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,y=typeof l=="number"&&typeof i=="number"&&typeof d=="number"?hooks.utils.priceToPnl({qty:l,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,sl_order_price:s,tp_order_price:u,slPnL:y,tpPnL:c}}var Kt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[n,i]=react.useState(t.quantity.toString()),[a,s]=react.useState(false),{t:u}=i18n.useTranslation();react.useEffect(()=>{S(t.quantity.toString());},[e.order.quantity]);let[l,d]=react.useState(false),[c,y]=react.useState(),{editOrder:T,editAlgoOrder:h,checkMinNotional:f}=Z(),{onUpdateOrder:C,position:I}=K(),{base_dp:L,base:k,base_tick:g}=$(),S=async(b,P)=>{i(b);let M=Math.abs(I?.position_qty||0);if(I&&o&&Number(b)>M)y(u("orders.quantity.lessThanPosition",{quantity:M}));else {let Le=Number(b);P&&Le>P?y(u("orders.quantity.lessThan",{quantity:utils.commifyOptional(P,{fix:L})})):y(void 0);}return Promise.resolve()},R=()=>{d(false),s(false);},v=()=>{d(false),S(t.quantity.toString()),s(false);},[O,N]=react.useState(false),q=react.useRef(null),X=()=>{if(c)return;if(Number(n)===Number(t.quantity)){s(false);return}let b=t.algo_order_id!==void 0?t.trigger_price:t.price;if(b!==null&&t.reduce_only!==true){let P=f(t.symbol,b,n);if(P){ui.toast.error(P),N(false),v();return}}d(true);},A=b=>{b?.stopPropagation(),b?.preventDefault(),X();},J=b=>{b.key==="Enter"&&(b?.stopPropagation(),b?.preventDefault(),X());},D=react.useCallback(()=>{N(true);let b={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:n,algo_order_id:t.algo_order_id};if(typeof b.algo_order_id<"u"&&b.order_type==="MARKET"){let{order_price:M,...Le}=b;b=Le;}typeof t.reduce_only<"u"&&(b.reduce_only=t.reduce_only),t.order_tag!==void 0&&(b={...b,order_tag:t.order_tag}),t?.visible_quantity===0&&(b.visible_quantity=0),t?.tag!==void 0&&(b.order_tag=t.tag);let P;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?P=C(t,b):t.algo_order_id!==void 0?P=h(t.algo_order_id.toString(),b):P=T(t.order_id.toString(),b),P.then(M=>{R(),S(n.toString());},M=>{ui.toast.error(M.message),S(t.quantity.toString()),v();}).finally(()=>N(false));},[n]),F=react.useRef(null),re=react.useRef(null),de=b=>{F.current&&re.current&&!F.current.contains(b.target)&&!re.current.contains(b.target)&&!l&&v();};react.useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[l,t.quantity]);let Ge=()=>!a||e.disableEdit?jsxRuntime.jsx(Mi,{order:t,quantity:n,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(Wi,{inputRef:q,quantitySliderRef:re,base_dp:L,base_tick:g,quantity:n,setQuantity:S,editing:a,setEditing:s,handleKeyDown:J,onClick:A,onClose:v,symbol:t.symbol,reduce_only:o,positionQty:I?.position_qty,error:c,confirmOpen:l,side:t.side,order:t,setError:y});return jsxRuntime.jsx(ui.Popover,{open:l,onOpenChange:d,content:jsxRuntime.jsx(qe,{type:0,base:k,value:n,cancelPopover:v,isSubmitting:O,onConfirm:D}),contentProps:{onOpenAutoFocus:b=>{}},children:jsxRuntime.jsx("div",{onClick:b=>{b.stopPropagation(),b.preventDefault();},ref:F,children:Ge()})})},Mi=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",ne(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})},Wi=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:n,quantity:i,setQuantity:a,editing:s,setEditing:u,handleKeyDown:l,onClick:d,onClose:c,error:y,symbol:T,reduce_only:h,positionQty:f,confirmOpen:C,side:I,order:L}=e,k=hooks.useMaxQty(T,L.side,L.reduce_only),g=react.useMemo(()=>h?Math.abs(f??0):L.quantity+Math.abs(k),[L.quantity,k,h,f]),[S,R]=react.useState(void 0);react.useEffect(()=>{if(S===void 0){let O=new utils.Decimal(i).div(g).abs().mul(100).toNumber();R(O);}},[S,g,i]);let v=async O=>(n>0&&(O=hooks.utils.formatNumber(O,n)??O),a(`${O}`,g));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!C,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(Re,{inputRef:t,dp:o,value:i,setValue:O=>{let N=Math.abs(Math.min(Number(O),g)).toString();if(a(O,g),O.endsWith("."))return;if(Number(N)===0){R(0);return}let q=new utils.Decimal(O).div(g).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();R(Math.min(100,q));},setEditing:u,handleKeyDown:l,onClick:d,onClose:c,onBlur:O=>{v(O.target.value);},hintInfo:y})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:O=>{O.preventDefault();},children:jsxRuntime.jsxs(ui.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${S}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[S??0],onValueChange:O=>{let N=Array.from(O.values());R(N[0]);let q=new utils.Decimal(N[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(q,g);},onValueCommit:O=>{let N=new utils.Decimal(O[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);v(N).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(zi,{onClick:O=>{R(O*100);let N=new utils.Decimal(O).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);N=hooks.utils.formatNumber(N,n)??N,a(N,g),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(N.length,N.length);},100);}})]})]})})]})},zi=e=>{let{t}=i18n.useTranslation(),r=[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:t("common.max"),value:1}];return jsxRuntime.jsx(ui.Flex,{gap:2,width:"100%",children:r.map((o,n)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(o.value);},className:"oui-w-1/5",children:o.label},n))})};var io=e=>{let{record:t}=e,[r,o]=react.useState(false),[n,{data:i,error:a,reset:s,isMutating:u}]=hooks.useMutation("/v1/order"),{t:l}=i18n.useTranslation(),d=hooks.useConfig("brokerId"),c=react.useCallback(()=>{o(false);let y={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:d};Number(t.visible_quantity)<Number(t.quantity)&&(y.visible_quantity=0),typeof t.reduce_only<"u"&&(y.reduce_only=t.reduce_only),n(y);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:u,disabled:u,onClick:y=>{u||(y.preventDefault(),y.stopPropagation(),c());},children:l("orders.history.renew")})};var ao=e=>{let{position:t,order:r}=K(),{quote_dp:o,base_dp:n}=$(),{t:i}=i18n.useTranslation();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:n,position:t,order:r,label:i("common.edit"),isEditing:true})};var co=()=>{let{sl_trigger_price:e,tp_trigger_price:t,sl_order_price:r,tp_order_price:o,order:n}=K(),{t:i}=i18n.useTranslation(),a=hooks.useSymbolsInfo()[n.symbol]();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${i("tpsl.tp")} -`,"\xA0"]}),jsxRuntime.jsx(so,{price:o,quoteDP:a.quote_dp})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}),jsxRuntime.jsx(so,{price:r,quoteDP:a.quote_dp})]}):null]})},so=({price:e,quoteDP:t})=>{let{t:r}=i18n.useTranslation();return e?e===types.OrderType.MARKET?jsxRuntime.jsx("span",{children:r("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{className:"oui-text-base-contrast-80",rule:"price",dp:t,children:e}):null};function mo(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:hooks.findTPSLFromOrder(e),o=r?`${i18n.i18n.t("tpsl.tp")} - ${i18n.i18n.t("common.marketPrice")}`:void 0,n=t?`${i18n.i18n.t("tpsl.sl")} - ${i18n.i18n.t("common.marketPrice")}`:void 0;return {tpTriggerPrice:o,slTriggerPrice:n}}var yo=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=K();return jsxRuntime.jsx(ia,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:true})},ia=e=>{let{direction:t="row",order:r,position:o}=e,n=hooks.useSymbolsInfo(),{t:i}=i18n.useTranslation(),a=react.useMemo(()=>{let l=[];if(!e.tooltip||!r||!o)return;let d=r.quantity;return d===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(d=o.position_qty),e.takeProfitPrice&&l.push(jsxRuntime.jsx(fo,{qty:d,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:n[r.symbol]()},"tp")),e.stopLossPrice&&l.push(jsxRuntime.jsx(fo,{qty:d,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:n[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:l})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),s=react.useMemo(()=>{let l=[];return r?.symbol?(e.takeProfitPrice&&l.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.tp")} -`,"\xA0"]}):""},"tp")),e.stopLossPrice&&l.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}):""},"sl")),l.length===0?jsxRuntime.jsx("span",{children:"-"}):(l.length===2&&t==="row"&&l.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),l)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol,i]),u=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:s});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:u}):u},fo=e=>{let{qty:t,price:r,entryPrice:o,orderSide:n,orderType:i,symbolInfo:a}=e,{t:s}=i18n.useTranslation(),u=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:n,orderType:i},{symbol:a}),d=(i===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL")==="TP"?`${s("tpsl.tpPnl")}:`:`${s("tpsl.slPnl")}:`;return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:d}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:u===0?"oui-text-base-contrast-36":u>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:u===0?"":u>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(u)}`})]})};var Oo=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let n=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=react.useState(false),[u,l]=react.useState(false),[d,c]=react.useState(false),{editAlgoOrder:y,checkMinNotional:T}=Z(),{base:h,quote_dp:f,quote_max:C,quote_min:I}=$(),L=react.useMemo(()=>{if(!((!n||i)&&!u)){if(Number(r)>C)return `Trigger price must be less than ${C}`;if(Number(r)<I)return `Trigger price must be greater than ${I}`}},[u,r,n,i]),k=()=>{s(false),l(false);},g=()=>{o(t.trigger_price?.toString()??"0"),s(false),l(false);},S=react.useRef(null),R=A=>{S.current&&!S.current.contains(A.target)&&!a&&g();};react.useEffect(()=>(document.addEventListener("mousedown",R),()=>{document.removeEventListener("mousedown",R);}),[a,t.trigger_price]);let v=A=>{if(A?.stopPropagation(),A?.preventDefault(),l(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let J=T(t.symbol,t.price,t.quantity);if(J){ui.toast.error(J),c(false),g();return}}s(true);}},O=A=>{A.key==="Enter"&&v(A);},N=()=>{if((L??"").length>0)return;c(true);let A={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(A={...A,order_tag:t.order_tag}),y(`${t.algo_order_id}`,A).then(J=>{k(),o(r);},J=>{ui.toast.error(J.message),o(t.trigger_price?.toString()??"--"),g();}).finally(()=>c(false));},q=react.useRef(null);if(!n||i)return jsxRuntime.jsx(ui.Text,{children:"--"});let X=()=>!u||e.disableEdit?jsxRuntime.jsx(da,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:q,dp:f,value:r,setValue:o,setEditing:l,handleKeyDown:O,onClick:v,onClose:g,hintInfo:L});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(qe,{type:2,base:h,value:r,cancelPopover:g,isSubmitting:d,onConfirm:N}),children:jsxRuntime.jsx("div",{onClick:A=>{A.stopPropagation(),A.preventDefault();},ref:S,children:X()})})},da=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var wo=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o,sharePnLConfig:n}=e,{t:i}=i18n.useTranslation();return react.useMemo(()=>{switch(t){case "all":return [Ie({width:130,showType:true,onSymbolChange:r,enableSort:false}),ga({width:130}),Me({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:130,title:i("common.orderPrice"),disableEdit:true,enableSort:false}),xt({width:130,enableSort:false}),ho({width:130,symbolsInfo:e.symbolsInfo}),Gt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:130,enableSort:false}),rt({width:130}),ot({width:130}),Ee({width:130}),$e({width:130}),Co({width:130}),Ue({width:160,enableSort:false})];case "pending":return [Ie({width:172,showType:true,onSymbolChange:r,enableSort:false}),Me({width:162,className:"oui-pr-0",enableSort:false}),We({width:162,className:"oui-pr-0",enableSort:false}),tt({width:162,className:"oui-pr-0"}),xa({width:130}),ze({width:162,isPending:true}),Ee({width:162}),$e({width:162}),Ue({width:162,enableSort:false}),Sa({width:162})];case "tp_sl":return [Ie({width:176,showType:true,onSymbolChange:r,enableSort:false}),ya({width:176}),ho({width:176,symbolsInfo:e.symbolsInfo}),ba({width:176}),_a({width:176}),Ee({width:176}),Ue({width:176,enableSort:false}),Oa({width:176})];case "filled":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,title:i("common.orderPrice"),disableEdit:true}),Pa({width:124}),tt({width:124,disableEdit:true}),Gt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo,hideShare:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "cancelled":return [Ie({showType:true,width:154,onSymbolChange:r,enableSort:false}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:124,disableEdit:true,enableSort:false}),xt({width:124,enableSort:false}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124})];case "rejected":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,disableEdit:true}),xt({width:124}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "orderHistory":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),We({width:124,disableEdit:true}),xt({width:124}),tt({width:124,disableEdit:true}),Gt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:150}),Co({width:80})]}},[t,o,n,i])};function Ie(e){return {title:i18n.i18n.t("common.symbol"),dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let o=ce(r)?.join(","),n=o?.length?` (${o})`:"";return `${t.split("_")[1]}-PERP${n}`},render:(t,r)=>{let o=ne(r);return jsxRuntime.jsxs(ui.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:n=>{e?.onSymbolChange?.({symbol:t}),n.stopPropagation(),n.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(r)?.map((n,i)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",className:"oui-break-normal oui-whitespace-nowrap",children:n},i))})]})]})}}}function ga(e){return {title:i18n.i18n.t("common.side"),dataIndex:"side",width:e?.width,onSort:e?.enableSort?(t,r,o)=>r.side.localeCompare(t.side):void 0,renderPlantText:(t,r)=>ue(t),render:(t,r)=>{let o=ne(r)?"oui-text-base-contrast-20":t===types.OrderSide.BUY?"oui-text-trade-profit":"oui-text-trade-loss";return jsxRuntime.jsx("span",{className:ui.cn("oui-font-semibold",o),children:ue(t)})}}}function Me(e){return {title:i18n.i18n.t("orders.column.fill&Quantity"),dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o} / `)+`${r.quantity}`},render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(Kt,{order:r,disableEdit:e?.disableEdit})}}function ya(e){return {title:i18n.i18n.t("common.quantity"),className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(Kt,{order:r})}}function We(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,o)=>it(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>utils.commifyOptional(r.price?.toString(),{fallback:i18n.i18n.t("common.marketPrice")}),render:(t,r)=>jsxRuntime.jsx(Vr,{order:r,disableEdit:e?.disableEdit})}}function ba(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:o,slTriggerPrice:n}=mo(r),i=`${o||""}${n?`${o?`
17
+ `:""}${n}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsxRuntime.jsx(co,{})}}function Pa(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>utils.commifyOptional(t)}}function tt(e){return {title:i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=r?.algo_order_id!==void 0,n=r?.algo_type==="BRACKET";return !o||n?"--":utils.commifyOptional(t)},render:(t,r)=>jsxRuntime.jsx(Oo,{order:r,disableEdit:e?.disableEdit})}}function ho(e){return {title:e?.title??i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r),s=(a!=null?`${i18n.i18n.t("tpsl.tp")}: ${utils.commifyOptional(a,{fix:n,padEnd:true})}`:"")+(i!=null?`${a?`
18
+ `:""}${i18n.i18n.t("tpsl.sl")}: ${utils.commifyOptional(i,{fix:n,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsxRuntime.jsx(yo,{})}}function xa(e){return {title:i18n.i18n.t("common.tpsl"),className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:n,tp_trigger_price:i}=o(),a=(i!=null?`${i18n.i18n.t("tpsl.tp")}: ${i}`:"")+(n!=null?`${i?`
19
+ `:""}${i18n.i18n.t("tpsl.sl")}: ${n}`:"");return a.length>0?a:"--"},render:(t,r)=>jsxRuntime.jsx(Rr,{order:r})}}function ze(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,o)=>{let n=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return it(n,i)}:void 0,renderPlantText:(t,r)=>Jt(r,e?.isPending??false)==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(Jt(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let o=Jt(r,e?.isPending??false);return o==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:o})}}}function Gt(e){return {title:i18n.i18n.t("common.realizedPnl"),dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??n,a=new utils.Decimal(t??0).toDecimalPlaces(i,utils.Decimal.ROUND_DOWN).toNumber(),s=utils.commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:o}=$(),n=e?.pnlNotionalDecimalPrecision??o,i=new utils.Decimal(t??0).toDecimalPlaces(n,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:n,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsxRuntime.jsx(Je,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:uiShare.SharePnLDialogId})]})}}}function Ee(e){return {title:i18n.i18n.t("orderEntry.reduceOnly"),dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no"),render:t=>jsxRuntime.jsx(ui.Text,{children:t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no")})}}function $e(e){return {title:i18n.i18n.t("orders.column.hidden"),dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes"),render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes")})}}function Ue(e){return {title:i18n.i18n.t("orders.column.orderTime"),dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let o=new Date(t);return dateFns.format(o,"yyyy-MM-dd HH:mm:ss")},render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function rt(e){return {title:i18n.i18n.t("common.fee"),dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function _a(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function ot(e){let t={[types.OrderStatus.NEW]:i18n.i18n.t("orders.status.pending"),[types.OrderStatus.FILLED]:i18n.i18n.t("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:i18n.i18n.t("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:i18n.i18n.t("orders.status.canceled"),[types.OrderStatus.REJECTED]:i18n.i18n.t("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:i18n.i18n.t("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:i18n.i18n.t("orders.status.completed")};return {title:i18n.i18n.t("common.status"),dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)},render:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)}}}function xt(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>it(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===types.OrderType.MARKET&&!t?"--":jsxRuntime.jsx(ui.Text,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>utils.commifyOptional(t,{fix:2})}}function Co(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(io,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(pt,{order:r}):null}}function Sa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(pt,{order:r})}}function Oa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(ao,{order:r}),jsxRuntime.jsx(pt,{order:r})]})}}function it(e,t){return e>t?1:e<t?-1:0}function Jt(e,t){return t?e.price&&e.quantity?new utils.Decimal(e.price).mul(e.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--":e.type===types.OrderType.CLOSE_POSITION&&e.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var vo=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui.Badge,{color:r?"success":"danger",size:"xs",children:o(r?"common.buy":"common.sell")}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Ao=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}`:ue(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(e.item)?.map((o,n)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},n))})},Do=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})},Fo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.status||t.algo_status,n=react.useMemo(()=>({[types.OrderStatus.NEW]:r("orders.status.pending"),[types.OrderStatus.FILLED]:r("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:r("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:r("orders.status.canceled"),[types.OrderStatus.REJECTED]:r("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:r("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:r("orders.status.completed")}),[r]);return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,size:"2xs",children:n[o]||ue(o)})},jt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:r("common.qty"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:r("tpsl.entirePosition"),intensity:80,children:o?r("tpsl.entirePosition"):t.quantity})})},er=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:r("orders.status.filled")}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var ko=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:[r("common.notional"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o})})},tr=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("orders.column.triggerPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},qo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("common.markPrice"),align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},Ro=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&o;return jsxRuntime.jsx(ui.Statistic,{label:r("common.limitPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsxRuntime.jsx(ui.Text,{children:r("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},Bo=e=>{let{tp_trigger_price:t,tpPnL:r}=K(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.tpTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(St,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.tpPnl")}:`,"\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Mo=e=>{let{sl_trigger_price:t,slPnL:r}=K(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.slTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(St,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.slPnl")}:`,"\xA0\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Wo=e=>{let{t}=i18n.useTranslation(),{tp_order_price:r}=K(),o=react.useMemo(()=>r===void 0?jsxRuntime.jsx(ui.Text,{children:"--"}):r===types.OrderType.MARKET?jsxRuntime.jsx(ui.Text,{children:t("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:r}),[r]);return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.tpPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:o})},zo=e=>{let{t}=i18n.useTranslation(),{sl_order_price:r}=K(),o=react.useMemo(()=>r===void 0?jsxRuntime.jsx(ui.Text,{children:"--"}):r===types.OrderType.MARKET?jsxRuntime.jsx(ui.Text,{children:t("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:r}),[r]);return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.slPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:o})},$o=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:r("tpsl.entirePosition")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t,r]);return jsxRuntime.jsx(ui.Statistic,{label:r("common.quantity"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:o})},Uo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.avgPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:e.item?.average_executed_price??"--"})})},Ko=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.orderPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,placeholder:t("common.marketPrice"),children:e.item?.price??"--"})})},Qo=e=>{let t=e?.item?.realized_pnl,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[r("common.realizedPnl"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"}),jsxRuntime.jsx(Je,{order:e.item,sharePnLConfig:e.sharePnLConfig,modalId:uiShare.SharePnLBottomSheetId,iconSize:12})]})})},St=e=>{let{classNames:t,content:r}=e,[o,n]=react.useState(false);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:n,arrow:{className:t?.arrow},children:jsxRuntime.jsx("div",{onClick:()=>n(i=>!i),children:e.children})})},Vo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsxs(ui.Flex,{justify:"end",gapX:1,mt:1,children:[jsxRuntime.jsxs(ui.Text,{size:"2xs",intensity:36,children:[t("common.fee"),":"]}),jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:80,children:e.item?.total_fee??"--"})]})};var or=e=>{let{t}=i18n.useTranslation();return !e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(St,{classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof e.pnl?.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:true,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${t("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"sell",children:e.pnl?.slPnL})]}),children:jsxRuntime.jsx("button",{onClick:()=>{e.setOpen(!e.open);},children:jsxRuntime.jsxs(ui.Flex,{gap:1,width:"1",children:[e.tp_trigger_price&&jsxRuntime.jsx(Yo,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Yo,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})})},Yo=e=>{let{type:t,value:r,quote_dp:o}=e;return r?jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",className:ui.cn("oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,padding:false,rm:utils.Decimal.ROUND_DOWN,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-36",children:[`${t} `,":\xA0\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var nr=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[n,i]=react.useState(false),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:u,roi:l}=mt(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:u,roi:l,quote_dp:r,open:n,setOpen:i}};var ir=e=>{let t=nr(e);return jsxRuntime.jsx(or,{...t})};var sr=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:r=>e.setOpen(true),children:t("common.cancel")}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:t("orders.cancelOrder"),actions:{primary:{label:t("common.confirm"),loading:e.isLoading,fullWidth:true,size:"md",onClick:r=>{e.onCancel(r);}},secondary:{label:t("common.cancel"),fullWidth:true,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:t("orders.cancelOrder.description")})})]})};var lr=e=>{let{state:t}=e,[r,o]=react.useState(false),{onCancelOrder:n}=Z(),[i,a]=react.useState(false);return {...t,open:r,setOpen:o,onCancel:l=>n?(l?.preventDefault(),l?.stopPropagation(),a(true),n(t.item).then(d=>{o(false);},d=>{ui.toast.error(d.message);}).finally(()=>{a(false);})):Promise.resolve(),onClose:()=>{o(false);},isLoading:i}};var dr=e=>{let t=lr(e);return jsxRuntime.jsx(sr,{...t})};var ur=e=>{let {t}=i18n.useTranslation(),{item:r}=e;r.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:t("common.edit")})})};var Zo=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:n,isAlgoOrder:i}=e,a=t===types.OrderSide.BUY,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-2",children:[jsxRuntime.jsx(ui.Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxRuntime.jsxs(ui.Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ce(e.item)?.map((u,l)=>jsxRuntime.jsx(ui.Badge,{color:u.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:u},l)),a&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:s("common.buy")}),!a&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:s("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{}),jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[i&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("orders.column.triggerPrice")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:n??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.price")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?s("common.marketPrice"):"--",children:e.isStopMarket?s("common.marketPrice"):r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:s("common.qty")}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o??"--"})]})]}),jsxRuntime.jsxs(ui.Flex,{className:"oui-gap-[2px]",children:[jsxRuntime.jsx(ui.Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:u=>{e.setOrderConfirm(!u);}}),jsxRuntime.jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:s("orderEntry.disableOrderConfirm")})]})]})};var yr=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation(),{parseErrorMsg:n}=reactApp.useOrderEntryFormErrorMsg(e.errors),i=n("order_quantity"),a=n("order_price"),s=n("trigger_price"),u=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,l=d=>{let c=e.baseTick;if(c&&c>0){let y=hooks.utils.formatNumber(d,c)??d;e.setQuantity(y);}};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:3,width:"100%",itemAlign:"start",className:"oui-text-sm",children:[jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",showIcon:true,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[ce(e.item)?.map((d,c)=>jsxRuntime.jsx(ui.Badge,{color:d.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:d},c)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:o("common.buy")}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:o("common.sell")})]})]}),jsxRuntime.jsx(ui.Divider,{intensity:8,className:"oui-w-full"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:o("common.lastPrice")}),jsxRuntime.jsx(ui.Text.numeral,{dp:e.item?.symbolInfo?.duote_dp,children:e.curMarkPrice??"--"})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",direction:"column",itemAlign:"stretch",gap:2,children:[e.isAlgoOrder&&jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("orders.column.triggerPrice")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:s?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:d=>e.setTriggerPrice(d),tooltip:s,tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast oui-w-full",root:ui.cn("oui-outline-line-12",s&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.price")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:a?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?o("orderEntry.orderType.market"):e.price,onValueChange:d=>e.setPrice(d),tooltip:a,tooltipProps:{content:{className:"oui-bg-base-5"},arrow:{className:"oui-fill-base-5"}},classNames:{input:"oui-text-base-contrast",root:ui.cn("oui-outline-line-12",a&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:o("common.quantity")}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:i?"danger":void 0,align:"right",fullWidth:true,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:d=>{e.setQuantity(d);},onBlur:d=>l(d.target.value),tooltip:i,tooltipProps:{content:{className:"oui-bg-base-6"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast",root:ui.cn("oui-outline-line-12",i&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:d=>{e.setSliderValue(d[0]);},color:"primary"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primary",size:"2xs",dp:2,padding:false,rule:"percentages",children:`${u??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,onClick:()=>{e.setQuantity(e.maxQty.toString());},children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primary",children:o("common.max")}),jsxRuntime.jsx(ui.Text.numeral,{intensity:54,size:"2xs",dp:e.base_dp,children:e.maxQty})]})]})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",gap:3,mt:2,children:[jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"secondary",onClick:d=>{e.onClose();},children:o("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:true,onClick:d=>{d.stopPropagation(),d.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:o("common.confirm")})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:o("orders.editOrder"),size:"xs",actions:{primary:{label:o("common.confirm"),onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:true},secondary:{label:o("common.cancel"),onClick:e.onCloseDialog,fullWidth:true}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(Zo,{...e})})]})};var _r=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:n=true,position:i}=e,{item:a}=t,{hide:s}=ui.useModal(),[u,l]=react.useState(false),d=a?.algo_order_id!==void 0&&a.algo_type!==types.AlgoOrderRootType.BRACKET,c=a?.type==="MARKET"&&d;c||a?.type==="MARKET";let [T,h]=react.useState(false),f=react.useMemo(()=>d&&a.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${a.type}`:a.type,[a,d]),[C,I]=hooks.useLocalStorage("orderly_order_confirm",true),{base_dp:L,base_tick:k}=e.state,{formattedOrder:g,setValue:S,markPrice:v,errors:O,validate:N,maxQty:q}=cs({order:a,orderType:f,position:i}),X=()=>{N().then(P=>{C?l(true):F(g);},P=>{P?.total?.message&&ui.toast.error(P?.total.message);}).catch(P=>{});},A=react.useCallback(()=>{l(false);},[]),J=()=>g?F(g):Promise.reject(),D=react.useCallback(()=>{s();},[]),F=react.useCallback(async P=>{let M,Le=a.visible_quantity!==void 0?a.visible_quantity===0:a.visible!==void 0?a.visible===0:false;if(a.algo_order_id!==void 0){if(c&&"order_price"in P){let{order_price:Ne,...wt}=P;P=wt;}M=r(a.algo_order_id.toString(),{...P});}else M=o(a.order_id.toString(),{...P,...Le?{visible_quantity:0}:{}});try{h(!0);let Ne=await M;D();}catch(Ne){ui.toast.error(Ne?.message??`${Ne}`);}finally{h(false);}},[r,o]),re=react.useMemo(()=>{let P=g.order_quantity;return P&&Number(P)!==0&&q!==0?new utils.Decimal(P).div(q).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[g.order_quantity,q]),de=a.price!=g.order_price||a.quantity!=g.order_quantity||a.trigger_price!=g.trigger_price,Ge=hooks.useThrottledCallback(P=>{let M=new utils.Decimal(P).div(100).mul(q).toDecimalPlaces(L,utils.Decimal.ROUND_DOWN).toNumber();S("order_quantity",hooks.utils.formatNumber(M,k));},50,{}),b=(P,M)=>{S(P,M);};return {...t,curMarkPrice:v,isAlgoOrder:d,isStopMarket:c,price:g.order_price,setPrice:P=>b("order_price",P),priceEdit:!c,triggerPrice:g.trigger_price,setTriggerPrice:P=>b("trigger_price",P),quantity:g.order_quantity,setQuantity:P=>{b("order_quantity",P);},maxQty:q,sliderValue:re,setSliderValue:Ge,onClose:D,onSheetConfirm:X,errors:O,orderType:f,isChanged:de,baseTick:k,dialogOpen:u,setDialogOpen:l,onDialogConfirm:J,onCloseDialog:A,submitting:T,orderConfirm:C,setOrderConfirm:I}},cs=e=>{let{order:t,orderType:r,position:o}=e,[n,i]=react.useState({side:t.side,order_type:r,order_price:t.price,order_quantity:t.quantity,trigger_price:t.trigger_price,reduce_only:t.reduce_only,symbol:t.symbol}),{reduce_only:a}=t,s=o?.position_qty,u=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),l=react.useMemo(()=>a?Math.abs(s??0):t.quantity+Math.abs(u),[t.quantity,u,a,s]),{symbolInfo:d,markPrice:c,errors:y,validate:T}=hooks.useOrderEntity({...n,symbol:t.symbol},{maxQty:l});return {symbolInfo:d,markPrice:c,errors:y,validate:T,setValue:(f,C)=>{i(I=>({...I,[f]:C}));},formattedOrder:n,maxQty:l}};var Sr=e=>{let t=_r(e);return jsxRuntime.jsx(yr,{...t})};var Or=e=>{let{state:t}=e,{t:r}=i18n.useTranslation(),o=hooks.useSymbolsInfo()[e.state.item.symbol](),{editAlgoOrder:n,editOrder:i}=Z(),{order:a,position:s}=K(),u=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{symbolInfo:o,isEditing:true,order:e.state.item,position:s})}).catch(l=>{}):ui.modal.sheet({title:r("orders.editOrder"),classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(Sr,{position:s,state:t,editAlgoOrder:n,editOrder:i})}).catch(l=>{});},[t]);return {...t,onShowEditSheet:u}};var hr=e=>{let t=Or(e);return jsxRuntime.jsx(ur,{...t})};var Cr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(xs,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(_s,{...e}),e.type==="pending"&&jsxRuntime.jsx(ir,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(Ss,{...e})]}),xs=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(vo,{...e}),jsxRuntime.jsx(Do,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Ao,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(Fo,{...e})]})]}),_s=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:Os(e)}),Ss=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(hr,{state:e}),jsxRuntime.jsx(dr,{state:e})]});function Os(e){switch(e.type){case "all":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case "pending":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(jt,{...e}),jsxRuntime.jsx(er,{...e}),jsxRuntime.jsx(ko,{...e}),jsxRuntime.jsx(tr,{...e}),jsxRuntime.jsx(Ro,{...e}),jsxRuntime.jsx(qo,{...e})]});case "tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Bo,{...e}),jsxRuntime.jsx(Wo,{...e}),jsxRuntime.jsx($o,{...e}),jsxRuntime.jsx(Mo,{...e}),jsxRuntime.jsx(zo,{...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(jt,{...e}),jsxRuntime.jsx(er,{...e}),jsxRuntime.jsx(tr,{...e,align:"end"}),jsxRuntime.jsx(Uo,{...e}),jsxRuntime.jsx(Ko,{...e}),jsxRuntime.jsx(Qo,{...e}),jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Vo,{...e})]})}}var Tr=e=>{let t=$();return {...e,...t}};var Lr=e=>{let{className:t,...r}=e,o=Tr(r);return jsxRuntime.jsx(Cr,{...o,className:t})};var Nr=e=>{let{sharePnLConfig:t,...r}=e,o=wo({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:t,symbolsInfo:e.symbolsInfo});return jsxRuntime.jsx(Rt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",height:"100%",itemAlign:"start",children:[e.filterItems.length>0&&jsxRuntime.jsx(ui.DataFilter,{items:e.filterItems,onFilter:n=>{e.onFilter(n);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(As,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardDataTable,{columns:o,loading:e.isLoading,dataSource:e.dataSource,bordered:true,ignoreLoadingCheck:true,testIds:{body:e.testIds?.tableBody},classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(n,i)=>({className:ui.cn("oui-h-[48px]",ne(n)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(n,i)=>`${e.type}${i}${n.order_id||n.algo_order_id}_index${i}`,renderRowContainer:(n,i,a)=>((e.type==="tp_sl"||e.type==="pending")&&(a=jsxRuntime.jsx(zt,{order:n,children:a})),jsxRuntime.jsx(Dt,{symbol:n.symbol,children:a})),pagination:e.pagination,manualPagination:e.manualPagination,features:[ui.TableFeatures.DownloadFeature],getTableInstance:n=>{e.tableInstance.current=n;}})]})})},wr=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(Rt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Grid,{cols:1,rows:2,className:"oui-w-full oui-grid-rows-[auto,1fr]",gap:2,children:[e.showFilter?jsxRuntime.jsx(ui.Flex,{gap:2,p:2,className:"oui-rounded-b-xl oui-bg-base-9",children:e.filterItems.map(r=>r.type!=="select"?null:jsxRuntime.jsx(ui.Picker,{options:r.options,size:"sm",value:r.value,className:"oui-text-2xs oui-text-base-contrast-54 ",placeholder:r.name==="side"?t("common.side.all"):r.name==="status"?t("common.status.all"):"",onValueChange:o=>{e.onFilter?.({name:r.name,value:o});}},`item-${r.name}`))}):jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ui.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(r,o)=>{let n=jsxRuntime.jsx(Lr,{item:r,index:o,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange,sharePnLConfig:e.sharePnLConfig});return ["tp_sl","pending"].includes(e.type)&&(n=jsxRuntime.jsx(zt,{order:r,children:n})),jsxRuntime.jsx(Dt,{symbol:r.symbol,children:n})}})]})})},As=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",disabled:(e.dataSource?.length??0)==0,className:"disabled:oui-bg-transport",onClick:r=>e.onCancelAll(),"data-testid":`oui-testid-dataList-${e.type.toLowerCase()}-cancelAll-button`,children:t("orders.cancelAll")})};var dn=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let n=e[o];if(n.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||n.algo_type===types.AlgoOrderRootType.TP_SL)if(n.algo_status!==types.OrderStatus.FILLED&&n.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];!a.is_activated||!a.trigger_price||(a.parent_algo_type=n.algo_type,r.push(a));}else for(let i=0;i<n.child_orders.length;i++){let a=n.child_orders[i];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=n.algo_type,r.push(a));}else r.push(n);}return r},[e]);var Nt=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=false,onSymbolChange:n,filterConfig:i,pnlNotionalDecimalPrecision:a,sharePnLConfig:s}=e,{t:u}=i18n.useTranslation(),l=hooks.useSymbolsInfo(),d=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),c=50,{page:y,pageSize:T,setPage:h,pagination:f,parsePagination:C}=ui.usePagination({pageSize:c});react.useEffect(()=>{h(1);},[e.symbol]);let{orderStatus:I,ordersSide:L,dateRange:k,filterItems:g,onFilter:S,filterDays:R,updateFilterDays:v}=Vs(r,{ordersStatus:t,setPage:h,filterConfig:i}),O=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),N=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),q=react.useRef();react.useImperativeHandle(e.ref,()=>({download:()=>{let It=`orders_${dateFns.format(new Date,"yyyyMMdd_HHmmss")}`;q.current?.download(It);}}));let[X,{isLoading:A,loadMore:J,cancelOrder:D,updateOrder:F,cancelAlgoOrder:re,updateAlgoOrder:de,cancelAllOrders:Ge,cancelAllTPSLOrders:b,meta:P,refresh:M}]=hooks.useOrderStream({symbol:e.symbol,status:I,side:L,page:o||!d?void 0:y,size:d?T:500,sourceTypeAll:r==="orderHistory",dateRange:k,includes:O,excludes:N}),Le=`orderly_${r}_pageSize`,[Ne,wt]=hooks.useLocalStorage(Le,c);react.useEffect(()=>{Ne!==T&&wt(T);},[T,Ne]);let fn=react.useCallback(()=>{let It=e.type==="pending"?u("orders.pending.cancelAll"):e.type==="tp_sl"?u("orders.tpsl.cancelAll"):"",Pn=u("orders.pending.cancelAll.description");ui.modal.confirm({title:It,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:Pn}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await b():await Ge(),M(),Promise.resolve(!0)}catch(Er){return Er?.message!==void 0&&toast.error(Er.message),Promise.resolve(false)}finally{Promise.resolve();}}});},[r,u]),gn=dn(X??[]),yn=reactApp.useDataTap(r!=="tp_sl"?gn:X,{fallbackData:[]})??void 0,bn=react.useMemo(()=>d?C(P):f,[P,d,C,f]);return {type:r,dataSource:yn,isLoading:A,loadMore:J,cancelOrder:D,updateOrder:F,cancelAlgoOrder:re,updateAlgoOrder:de,pagination:bn,manualPagination:d,pnlNotionalDecimalPrecision:a,onFilter:S,filterItems:g,onCancelAll:fn,onSymbolChange:n,sharePnLConfig:s,tableInstance:q,symbolsInfo:l,filterDays:R,updateFilterDays:v}},Vs=(e,t)=>{let{t:r}=i18n.useTranslation(),[o,n]=react.useState(t.ordersStatus??"all"),[i,a]=react.useState(t.filterConfig?.side??"all"),[s,u]=react.useState(90),l=t.filterConfig?.range??(e==="all"||e==="orderHistory"?Ir({to:new Date,from:Fe(dateFns.subDays(new Date,89))}):{}),[d,c]=react.useState(l),y=f=>{u(f),c({from:He(dateFns.subDays(new Date,f-1)),to:Fe(new Date)}),t.setPage(1);},T=f=>{if(f.name==="side"&&(a(f.value),t.setPage(1)),f.name==="status"&&(n(f.value),t.setPage(1)),f.name==="dateRange"){c(Ir(f.value)),t.setPage(1);let C=Ir(f.value);if(C.from&&C.to){let I=Math.abs(dateFns.differenceInDays(C.from,C.to))+1,k={1:{from:He(new Date),to:Fe(new Date)},7:{from:He(dateFns.subDays(new Date,6)),to:Fe(new Date)},30:{from:He(dateFns.subDays(new Date,29)),to:Fe(new Date)},90:{from:He(dateFns.subDays(new Date,89)),to:Fe(new Date)}}[I];k&&vt(k.from,C.from)&&vt(k.to,C.to)?u(I):u(null);}}};return {filterItems:react.useMemo(()=>{let f={type:"select",name:"side",options:[{label:r("common.side.all"),value:"all"},{label:r("common.buy"),value:"BUY"},{label:r("common.sell"),value:"SELL"}],value:i},C={type:"range",name:"dateRange",value:d},I={type:"select",name:"status",options:[{label:r("common.status.all"),value:"all"},{label:r("orders.status.pending"),value:types.OrderStatus.INCOMPLETE},{label:r("orders.status.filled"),value:types.OrderStatus.FILLED},{label:r("orders.status.partialFilled"),value:types.OrderStatus.PARTIAL_FILLED},{label:r("orders.status.canceled"),value:types.OrderStatus.CANCELLED},{label:r("orders.status.rejected"),value:types.OrderStatus.REJECTED}],value:o};switch(e){case "all":return [f,I,C];case "pending":return [f];case "tp_sl":return [f];case "filled":return [f];case "cancelled":return [f];case "rejected":return [f];case "orderHistory":return [f,I,C]}},[e,i,o,d,r]),onFilter:T,ordersSide:i==="all"?void 0:i,dateRange:d,orderStatus:o==="all"?void 0:o,filterDays:s,updateFilterDays:y}};function He(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Fe(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var Ir=e=>({from:He(e.from),to:Fe(e.to??e.from)});var Te=react.forwardRef((e,t)=>{let{testIds:r,...o}=e,n=Nt({...o,ref:t});return jsxRuntime.jsx(Nr,{...n,testIds:r})}),Gs=e=>{let t=Nt({...e,enableLoadMore:true});return jsxRuntime.jsx(wr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var pn=e=>{let{t}=i18n.useTranslation(),r={pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision};return jsxRuntime.jsxs(ui.Tabs,{defaultValue:e.current||"all",variant:"contained",className:"oui-h-full",classNames:{tabsContent:"oui-h-[calc(100%_-_28px)]"},children:[jsxRuntime.jsx(ui.TabPanel,{value:"all",title:t("common.all"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:t("orders.status.pending"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:t("common.tpsl"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:t("orders.status.filled"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision,sharePnLConfig:e.sharePnLConfig,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:t("orders.status.canceled"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,...r})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:t("orders.status.rejected"),children:jsxRuntime.jsx(Te,{ref:e.orderListRef,type:"rejected",ordersStatus:types.OrderStatus.REJECTED,...r})})]})};var _e=(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))(_e||{}),el=react.forwardRef((e,t)=>{let r=Et({...e,ref:t});return jsxRuntime.jsx(pn,{...r})});
20
20
 
21
- exports.DesktopOrderList = Cr;
21
+ exports.DesktopOrderList = Nr;
22
22
  exports.DesktopOrderListWidget = Te;
23
- exports.MobileOrderList = Tr;
24
- exports.MobileOrderListWidget = Ws;
25
- exports.OrdersWidget = Qs;
26
- exports.TabType = Se;
27
- exports.useOrderListScript = Tt;
28
- exports.useOrdersScript = wt;
23
+ exports.MobileOrderList = wr;
24
+ exports.MobileOrderListWidget = Gs;
25
+ exports.OrdersWidget = el;
26
+ exports.TabType = _e;
27
+ exports.useOrderListScript = Nt;
28
+ exports.useOrdersScript = Et;
29
29
  //# sourceMappingURL=out.js.map
30
30
  //# sourceMappingURL=index.js.map