@orderly.network/ui-orders 2.0.7 → 2.1.0

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