@orderly.network/ui-orders 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { useDataTap } from '@orderly.network/react-app';
|
|
|
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
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
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)??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})});
|
|
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})});
|
|
17
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
19
|
//# sourceMappingURL=out.js.map
|