UNPKG

@orderly.network/ui-orders

Version:

19 lines (17 loc) 78.5 kB
'use strict'; var react = require('react'); var ui = require('@orderly.network/ui'); var types = require('@orderly.network/types'); var i18n = require('@orderly.network/i18n'); var uiConnector = require('@orderly.network/ui-connector'); var hooks = require('@orderly.network/hooks'); var dateFns = require('date-fns'); var uiShare = require('@orderly.network/ui-share'); var utils = require('@orderly.network/utils'); var jsxRuntime = require('react/jsx-runtime'); var uiTpsl = require('@orderly.network/ui-tpsl'); var reactApp = require('@orderly.network/react-app'); var wt=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:o}=e,n=react.useRef(null);return react.useImperativeHandle(e.ref,()=>({download:()=>{n.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:n,sharePnLConfig:o}};var ue=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ce(e){let t=e.type,r=e.algo_type;if(typeof t<"u"){let o=[];if(e.parent_algo_type){if(r===types.AlgoOrderType.STOP_LOSS){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.sl")]:[i18n.i18n.t("tpsl.sl")];o.push(...i);}if(r===types.AlgoOrderType.TAKE_PROFIT){let i=t===types.OrderType.CLOSE_POSITION?[i18n.i18n.t("common.position"),i18n.i18n.t("tpsl.tp")]:[i18n.i18n.t("tpsl.tp")];o.push(...i);}return o}let n=typeof t=="string"?t.replace("_ORDER",""):"";if([types.OrderType.ASK,types.OrderType.BID].includes(t))return [i18n.i18n.t("orderEntry.orderType.limit")];if(e.algo_order_id===void 0||e.algo_order_id&&r==="BRACKET")return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.limit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.market"),[types.OrderType.POST_ONLY]:i18n.i18n.t("orderEntry.orderType.postOnly"),[types.OrderType.IOC]:i18n.i18n.t("orderEntry.orderType.ioc"),[types.OrderType.FOK]:i18n.i18n.t("orderEntry.orderType.fok")}[n]||ue(n)];if(n)return [{[types.OrderType.LIMIT]:i18n.i18n.t("orderEntry.orderType.stopLimit"),[types.OrderType.MARKET]:i18n.i18n.t("orderEntry.orderType.stopMarket")}[n]||n]}if(typeof r<"u"){let o=[];r===types.AlgoOrderRootType.POSITIONAL_TP_SL&&o.push(i18n.i18n.t("common.position"));let n=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!a.trigger_price),i=e?.child_orders?.find(a=>a.algo_type===types.AlgoOrderType.STOP_LOSS&&!!a.trigger_price);return (n||i)&&o.push(n&&i?i18n.i18n.t("common.tpsl"):n?i18n.i18n.t("tpsl.tp"):i18n.i18n.t("tpsl.sl")),o}}function ne(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function yn(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(n=>n.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function ct(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=yn(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let n=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:n,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=i?hooks.utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:d}}}function It(e,t){return !e||!t?false:e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}var vt=e=>{let{t}=i18n.useTranslation();return e.sharePnLConfig==null?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),ui.modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?t("share.pnl.share.long"):t("share.pnl.share.short"),openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsxRuntime.jsx(ui.ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})})};var Er=e=>{let{sharePnLConfig:t,order:r,modalId:o,iconSize:n}=e,{getFirstRefCode:i}=hooks.useReferralInfo(),a=react.useMemo(()=>i()?.code,[i]),s=hooks.useSymbolLeverage(e.order.symbol);return {iconSize:n,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:o}};var Je=e=>{let t=Er(e);return jsxRuntime.jsx(vt,{...t})};var vr=react.createContext({}),$=()=>react.useContext(vr),At=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(vr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var kr=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=$(),{t:n}=i18n.useTranslation(),{sl_trigger_price:i,tp_trigger_price:a}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:s,roi:d}=ct(t);return !a&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof s.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:s.tpPnL}),typeof s.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsxs(ui.Text,{intensity:80,children:[`${n("tpsl.slPnl")}:`," \xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:s.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Dr,{type:"TP",value:a,quote_dp:r}),jsxRuntime.jsx(Dr,{type:"SL",value:i,quote_dp:r})]})})},Dr=e=>{let{type:t,value:r,quote_dp:o}=e,{t:n}=i18n.useTranslation();return r?jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[t==="TP"?`${n("tpsl.tp")} -`:`${n("tpsl.sl")} -`,"\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Rr=react.createContext({}),Z=()=>react.useContext(Rr),Ft=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:n}=e,{t:i}=i18n.useTranslation(),a=hooks.useSymbolsInfo(),s=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),d=react.useCallback(async(l,f)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:false;await ui.modal.sheet({title:i("orders.editOrder"),classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[i]),u=react.useCallback((l,f,S)=>{let{min_notional:C}=a[l](),h=hooks.getMinNotional({price:f,qty:S,min_notional:C});if(h!==void 0)return i("orderEntry.total.error.min",{value:h})},[a,i]);return jsxRuntime.jsx(Rr.Provider,{value:{onCancelOrder:s,onEditOrder:d,editOrder:r,editAlgoOrder:n,checkMinNotional:u},children:e.children})};var mt=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),{onCancelOrder:o}=Z(),[n,i]=react.useState(false);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{o&&(a.preventDefault(),a.stopPropagation(),i(true),o(t).then(s=>s,s=>{ui.toast.error(s.message);}).finally(()=>{i(false);}));},loading:n,children:r("common.cancel")})};var qe=e=>{let{type:t,base:r,value:o,cancelPopover:n,isSubmitting:i,onConfirm:a}=e,{t:s}=i18n.useTranslation();return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsx("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:(()=>{let u={values:{base:r,value:utils.commify(o)},components:[jsxRuntime.jsx("span",{className:"oui-text-warning-darken"})]};switch(t){case 0:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.quantity",...u});case 1:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.price",...u});case 2:return jsxRuntime.jsx(i18n.Trans,{i18nKey:"order.edit.confirm.triggerPrice",...u})}})()}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:n,disabled:i,children:s("common.cancel")}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:i,onClick:a,children:s("common.confirm")})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:n,children:jsxRuntime.jsx(ui.CloseIcon,{size:16,color:"white",opacity:1})})]})};var Re=e=>{let{inputRef:t,dp:r,value:o,setValue:n,setEditing:i,error:a,handleKeyDown:s,onClick:d,onClose:u,onFocus:l,onBlur:f,hintInfo:S}=e;react.useEffect(()=>{let h=t.current;if(h){let p=h.value.length;h.setSelectionRange(p,p);}i(true);},[]);let C=(S?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:S,open:C,children:jsxRuntime.jsx(ui.Input,{ref:t,type:"text",size:"sm",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(r),ui.inputFormatter.currencyFormatter],value:o,onValueChange:h=>n(h),helpText:a,onClick:h=>{h.stopPropagation(),h.preventDefault();},autoComplete:"off",onFocus:l,onBlur:f,onKeyDown:s,autoFocus:true,color:C?"danger":void 0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsxRuntime.jsx("button",{onClick:d,children:jsxRuntime.jsx(ui.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Kr=e=>{let{order:t}=e,{t:r}=i18n.useTranslation(),[o,n]=react.useState(()=>t.type===types.OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[i,a]=react.useState(false),[s,d]=react.useState(false),u=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&u,[f,S]=react.useState(false),{editOrder:C,editAlgoOrder:h,checkMinNotional:p}=Z(),{base:P,quote_dp:w}=$(),T=hooks.useSymbolPriceRange(t.symbol,t.side,u?t.trigger_price:void 0),q=()=>{a(false),d(false);},g=()=>{a(false),n(t.price?.toString()??"Market"),d(false);},E=react.useMemo(()=>!T||l||!s?"":Number(o)>T.max?r("orders.price.greaterThan",{max:T.max}):Number(o)<T.min?r("orders.price.lessThan",{min:T.min}):"",[l,s,T,o,r]),z=A=>{if(A?.stopPropagation(),A?.preventDefault(),!(E.length>0)){if(o===`${t.price}`){d(false);return}if(t.reduce_only!==true){let D=p(t.symbol,o,t.quantity);if(D){ui.toast.error(D),S(false),g();return}}a(true);}},R=A=>{A.key==="Enter"&&z(A);},O=()=>{S(true);let A=t.order_id,D={order_price:o,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(D.reduce_only=t.reduce_only),t.order_tag!==void 0&&(D={...D,order_tag:t.order_tag}),u&&(A=t.algo_order_id,D={...D,order_id:A,price:o,algo_order_id:A}),t?.visible_quantity===0&&(D.visible_quantity=0),t.tag!==void 0&&(D.order_tag=t.tag);let re;t.algo_order_id!==void 0?re=h(t.algo_order_id.toString(),D):re=C(t.order_id.toString(),D),re.then(de=>{q(),n(o);},de=>{ui.toast.error(de.message),g();}).finally(()=>S(false));},L=react.useRef(null);react.useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let F=react.useRef(null),X=A=>{F.current&&!F.current.contains(A.target)&&!i&&g();};if(react.useEffect(()=>(document.addEventListener("mousedown",X),()=>{document.removeEventListener("mousedown",X);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||o==="Market")return jsxRuntime.jsx("span",{children:r("common.marketPrice")});let Y=()=>!s||e.disableEdit?jsxRuntime.jsx(di,{order:t,price:o,setEditing:d,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:L,dp:w,value:o,setValue:n,setEditing:d,handleKeyDown:R,onClick:z,onClose:g,hintInfo:E});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:a,content:jsxRuntime.jsx(qe,{type:1,base:P,value:o,cancelPopover:g,isSubmitting:f,onConfirm:O}),children:jsxRuntime.jsx("div",{onClick:A=>{A.stopPropagation(),A.preventDefault();},ref:F,children:Y()})})},di=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var Vr=react.createContext({}),G=()=>react.useContext(Vr),Bt=e=>{let{quote_dp:t}=$(),[r,o]=react.useState(),[n]=hooks.useMutation("/v1/algo/order","DELETE"),[i]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),u=async P=>n(null,{order_id:P.algo_order_id,symbol:P.symbol}),l=async(P,w)=>i({order_id:P.algo_order_id,child_orders:P.child_orders.map(T=>({order_id:T.algo_order_id,quantity:w.order_quantity}))}),f=P=>a.cache.get(d)?.data.rows.find(T=>T.symbol===P),{sl_trigger_price:S,tp_trigger_price:C,tpPnL:h,slPnL:p}=Pi({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??false)){let P=f(e.order.symbol);P&&o(P);}},[e.order.symbol]),jsxRuntime.jsx(Vr.Provider,{value:{order:e.order,sl_trigger_price:S,tp_trigger_price:C,tpPnL:h,slPnL:p,onCancelOrder:u,onUpdateOrder:l,getRelatedPosition:f,position:r},children:e.children})};function Pi(e){let{order:t,position:r,quote_dp:o}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:n,tp_trigger_price:i}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,u=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:n,tp_trigger_price:i,slPnL:u,tpPnL:d}}var zt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[n,i]=react.useState(t.quantity.toString()),[a,s]=react.useState(false),{t:d}=i18n.useTranslation();react.useEffect(()=>{E(t.quantity.toString());},[e.order.quantity]);let[u,l]=react.useState(false),[f,S]=react.useState(),{editOrder:C,editAlgoOrder:h,checkMinNotional:p}=Z(),{onUpdateOrder:P,position:w}=G(),{base_dp:T,base:q,base_tick:g}=$(),E=async(y,b)=>{i(y);let B=Math.abs(w?.position_qty||0);if(w&&o&&Number(y)>B)S(d("orders.quantity.lessThanPosition",{quantity:B}));else {let Le=Number(y);b&&Le>b?S(d("orders.quantity.lessThan",{quantity:utils.commifyOptional(b,{fix:T})})):S(void 0);}return Promise.resolve()},z=()=>{l(false),s(false);},R=()=>{l(false),E(t.quantity.toString()),s(false);},[O,L]=react.useState(false),F=react.useRef(null),X=()=>{if(f)return;if(Number(n)===Number(t.quantity)){s(false);return}let y=t.algo_order_id!==void 0?t.trigger_price:t.price;if(y!==null&&t.reduce_only!==true){let b=p(t.symbol,y,n);if(b){ui.toast.error(b),L(false),R();return}}l(true);},v=y=>{y?.stopPropagation(),y?.preventDefault(),X();},Y=y=>{y.key==="Enter"&&(y?.stopPropagation(),y?.preventDefault(),X());},A=react.useCallback(()=>{L(true);let y={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:n,algo_order_id:t.algo_order_id};if(typeof y.algo_order_id<"u"&&y.order_type==="MARKET"){let{order_price:B,...Le}=y;y=Le;}typeof t.reduce_only<"u"&&(y.reduce_only=t.reduce_only),t.order_tag!==void 0&&(y={...y,order_tag:t.order_tag}),t?.visible_quantity===0&&(y.visible_quantity=0),t?.tag!==void 0&&(y.order_tag=t.tag);let b;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?b=P(t,y):t.algo_order_id!==void 0?b=h(t.algo_order_id.toString(),y):b=C(t.order_id.toString(),y),b.then(B=>{z(),E(n.toString());},B=>{ui.toast.error(B.message),E(t.quantity.toString()),R();}).finally(()=>L(false));},[n]),D=react.useRef(null),re=react.useRef(null),de=y=>{D.current&&re.current&&!D.current.contains(y.target)&&!re.current.contains(y.target)&&!u&&R();};react.useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[u,t.quantity]);let Ge=()=>!a||e.disableEdit?jsxRuntime.jsx(Ei,{order:t,quantity:n,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(vi,{inputRef:F,quantitySliderRef:re,base_dp:T,base_tick:g,quantity:n,setQuantity:E,editing:a,setEditing:s,handleKeyDown:Y,onClick:v,onClose:R,symbol:t.symbol,reduce_only:o,positionQty:w?.position_qty,error:f,confirmOpen:u,side:t.side,order:t,setError:S});return jsxRuntime.jsx(ui.Popover,{open:u,onOpenChange:l,content:jsxRuntime.jsx(qe,{type:0,base:q,value:n,cancelPopover:R,isSubmitting:O,onConfirm:A}),contentProps:{onOpenAutoFocus:y=>{}},children:jsxRuntime.jsx("div",{onClick:y=>{y.stopPropagation(),y.preventDefault();},ref:D,children:Ge()})})},Ei=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",ne(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})},vi=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:n,quantity:i,setQuantity:a,editing:s,setEditing:d,handleKeyDown:u,onClick:l,onClose:f,error:S,symbol:C,reduce_only:h,positionQty:p,confirmOpen:P,side:w,order:T}=e,q=hooks.useMaxQty(C,T.side,T.reduce_only),g=react.useMemo(()=>h?Math.abs(p??0):T.quantity+Math.abs(q),[T.quantity,q,h,p]),[E,z]=react.useState(void 0);react.useEffect(()=>{if(E===void 0){let O=new utils.Decimal(i).div(g).abs().mul(100).toNumber();z(O);}},[E,g,i]);let R=async O=>(n>0&&(O=hooks.utils.formatNumber(O,n)??O),a(`${O}`,g));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!P,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(Re,{inputRef:t,dp:o,value:i,setValue:O=>{let L=Math.abs(Math.min(Number(O),g)).toString();if(a(O,g),O.endsWith("."))return;if(Number(L)===0){z(0);return}let F=new utils.Decimal(O).div(g).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();z(Math.min(100,F));},setEditing:d,handleKeyDown:u,onClick:l,onClose:f,onBlur:O=>{R(O.target.value);},hintInfo:S})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:O=>{O.preventDefault();},children:jsxRuntime.jsxs(ui.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${E}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[E??0],onValueChange:O=>{let L=Array.from(O.values());z(L[0]);let F=new utils.Decimal(L[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(F,g);},onValueCommit:O=>{let L=new utils.Decimal(O[0]).div(100).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);R(L).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Ai,{onClick:O=>{z(O*100);let L=new utils.Decimal(O).mul(g).abs().toFixed(o,utils.Decimal.ROUND_DOWN);L=hooks.utils.formatNumber(L,n)??L,a(L,g),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(L.length,L.length);},100);}})]})]})})]})},Ai=e=>{let{t}=i18n.useTranslation(),r=[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:t("common.max"),value:1}];return jsxRuntime.jsx(ui.Flex,{gap:2,width:"100%",children:r.map((o,n)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(o.value);},className:"oui-w-1/5",children:o.label},n))})};var to=e=>{let{record:t}=e,[r,o]=react.useState(false),[n,{data:i,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),{t:u}=i18n.useTranslation(),l=hooks.useConfig("brokerId"),f=react.useCallback(()=>{o(false);let S={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(S.visible_quantity=0),typeof t.reduce_only<"u"&&(S.reduce_only=t.reduce_only),n(S);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:S=>{d||(S.preventDefault(),S.stopPropagation(),f());},children:u("orders.history.renew")})};var ro=e=>{let{position:t,order:r}=G(),{quote_dp:o,base_dp:n}=$(),{t:i}=i18n.useTranslation();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:n,position:t,order:r,label:i("common.edit"),isEditing:true})};var no=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=G(),{t:r}=i18n.useTranslation();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${r("tpsl.tp")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${r("tpsl.sl")} -`,"\xA0"]}),jsxRuntime.jsx("span",{children:r("common.marketPrice")})]}):null]})};function io(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:hooks.utils.findTPSLFromOrder(e),o=r?`${i18n.i18n.t("tpsl.tp")} - ${i18n.i18n.t("common.marketPrice")}`:void 0,n=t?`${i18n.i18n.t("tpsl.sl")} - ${i18n.i18n.t("common.marketPrice")}`:void 0;return {tpTriggerPrice:o,slTriggerPrice:n}}var uo=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=G();return jsxRuntime.jsx(Ji,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:true})},Ji=e=>{let{direction:t="row",order:r,position:o}=e,n=hooks.useSymbolsInfo(),{t:i}=i18n.useTranslation(),a=react.useMemo(()=>{let u=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&u.push(jsxRuntime.jsx(so,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:n[r.symbol]()},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(so,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:n[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:u})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),s=react.useMemo(()=>{let u=[];return r?.symbol?(e.takeProfitPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.tp")} -`,"\xA0"]}):""},"tp")),e.stopLossPrice&&u.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}):""},"sl")),u.length===0?jsxRuntime.jsx("span",{children:"-"}):(u.length===2&&t==="row"&&u.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),u)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol,i]),d=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:s});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:a,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:d}):d},so=e=>{let{qty:t,price:r,entryPrice:o,orderSide:n,orderType:i,symbolInfo:a}=e,{t:s}=i18n.useTranslation(),d=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:n,orderType:i},{symbol:a}),l=(i===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL")==="TP"?`${s("tpsl.tpPnl")}:`:`${s("tpsl.slPnl")}:`;return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:l}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:d===0?"oui-text-base-contrast-36":d>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:d===0?"":d>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(d)}`})]})};var yo=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let n=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=react.useState(false),[d,u]=react.useState(false),[l,f]=react.useState(false),{editAlgoOrder:S,checkMinNotional:C}=Z(),{base:h,quote_dp:p,quote_max:P,quote_min:w}=$(),T=react.useMemo(()=>{if(!((!n||i)&&!d)){if(Number(r)>P)return `Trigger price must be less than ${P}`;if(Number(r)<w)return `Trigger price must be greater than ${w}`}},[d,r,n,i]),q=()=>{s(false),u(false);},g=()=>{o(t.trigger_price?.toString()??"0"),s(false),u(false);},E=react.useRef(null),z=v=>{E.current&&!E.current.contains(v.target)&&!a&&g();};react.useEffect(()=>(document.addEventListener("mousedown",z),()=>{document.removeEventListener("mousedown",z);}),[a,t.trigger_price]);let R=v=>{if(v?.stopPropagation(),v?.preventDefault(),u(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let Y=C(t.symbol,t.price,t.quantity);if(Y){ui.toast.error(Y),f(false),g();return}}s(true);}},O=v=>{v.key==="Enter"&&R(v);},L=()=>{if((T??"").length>0)return;f(true);let v={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(v={...v,order_tag:t.order_tag}),S(`${t.algo_order_id}`,v).then(Y=>{q(),o(r);},Y=>{ui.toast.error(Y.message),o(t.trigger_price?.toString()??"--"),g();}).finally(()=>f(false));},F=react.useRef(null);if(!n||i)return jsxRuntime.jsx(ui.Text,{children:"--"});let X=()=>!d||e.disableEdit?jsxRuntime.jsx(ea,{order:t,price:r,setEditing:u,disableEdit:e.disableEdit}):jsxRuntime.jsx(Re,{inputRef:F,dp:p,value:r,setValue:o,setEditing:u,handleKeyDown:O,onClick:R,onClose:g,hintInfo:T});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(qe,{type:2,base:h,value:r,cancelPopover:g,isSubmitting:l,onConfirm:L}),children:jsxRuntime.jsx("div",{onClick:v=>{v.stopPropagation(),v.preventDefault();},ref:E,children:X()})})},ea=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var Oo=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o,sharePnLConfig:n}=e,{t:i}=i18n.useTranslation();return react.useMemo(()=>{switch(t){case "all":return [Ie({width:130,showType:true,onSymbolChange:r,enableSort:false}),aa({width:130}),Me({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:130,title:i("common.orderPrice"),disableEdit:true,enableSort:false}),bt({width:130,enableSort:false}),bo({width:130,symbolsInfo:e.symbolsInfo}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:130,enableSort:false}),rt({width:130}),ot({width:130}),Ee({width:130}),$e({width:130}),Po({width:130}),Ue({width:160,enableSort:false})];case "pending":return [Ie({width:172,showType:true,onSymbolChange:r,enableSort:false}),Me({width:162,className:"oui-pr-0",enableSort:false}),We({width:162,className:"oui-pr-0",enableSort:false}),tt({width:162,className:"oui-pr-0"}),ua({width:130}),ze({width:162,isPending:true}),Ee({width:162}),$e({width:162}),Ue({width:162,enableSort:false}),ma({width:162})];case "tp_sl":return [Ie({width:176,showType:true,onSymbolChange:r,enableSort:false}),sa({width:176}),bo({width:176,symbolsInfo:e.symbolsInfo}),la({width:176}),ca({width:176}),Ee({width:176}),Ue({width:176,enableSort:false}),pa({width:176})];case "filled":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,title:i("common.orderPrice"),disableEdit:true}),da({width:124}),tt({width:124,disableEdit:true}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo,hideShare:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "cancelled":return [Ie({showType:true,width:154,onSymbolChange:r,enableSort:false}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:124,disableEdit:true,enableSort:false}),bt({width:124,enableSort:false}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124})];case "rejected":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,disableEdit:true}),bt({width:124}),tt({width:124,disableEdit:true}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:176})];case "orderHistory":return [Ie({showType:true,width:154,onSymbolChange:r}),Me({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),We({width:124,disableEdit:true}),bt({width:124}),tt({width:124,disableEdit:true}),Ht({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:124}),rt({width:124}),ot({width:124}),Ee({width:124}),$e({width:124}),Ue({width:150}),Po({width:80})]}},[t,o,n,i])};function Ie(e){return {title:i18n.i18n.t("common.symbol"),dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let o=ce(r)?.join(","),n=o?.length?` (${o})`:"";return `${t.split("_")[1]}-PERP${n}`},render:(t,r)=>{let o=ne(r);return jsxRuntime.jsxs(ui.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:n=>{e?.onSymbolChange?.({symbol:t}),n.stopPropagation(),n.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(r)?.map((n,i)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",className:"oui-break-normal oui-whitespace-nowrap",children:n},i))})]})]})}}}function aa(e){return {title:i18n.i18n.t("common.side"),dataIndex:"side",width:e?.width,onSort:e?.enableSort?(t,r,o)=>r.side.localeCompare(t.side):void 0,renderPlantText:(t,r)=>ue(t),render:(t,r)=>{let o=ne(r)?"oui-text-base-contrast-20":t===types.OrderSide.BUY?"oui-text-trade-profit":"oui-text-trade-loss";return jsxRuntime.jsx("span",{className:ui.cn("oui-font-semibold",o),children:ue(t)})}}}function Me(e){return {title:i18n.i18n.t("orders.column.fill&Quantity"),dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o} / `)+`${r.quantity}`},render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(zt,{order:r,disableEdit:e?.disableEdit})}}function sa(e){return {title:i18n.i18n.t("common.quantity"),className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return it(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL)return i18n.i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===types.AlgoOrderRootType.TP_SL?"":`${o}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(zt,{order:r})}}function We(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,o)=>it(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>utils.commifyOptional(r.price?.toString(),{fallback:i18n.i18n.t("common.marketPrice")}),render:(t,r)=>jsxRuntime.jsx(Kr,{order:r,disableEdit:e?.disableEdit})}}function la(e){return {title:e?.title??i18n.i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:o,slTriggerPrice:n}=io(r),i=`${o||""}${n?`${o?` `:""}${n}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsxRuntime.jsx(no,{})}}function da(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>utils.commifyOptional(t)}}function tt(e){return {title:i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=r?.algo_order_id!==void 0,n=r?.algo_type==="BRACKET";return !o||n?"--":utils.commifyOptional(t)},render:(t,r)=>jsxRuntime.jsx(yo,{order:r,disableEdit:e?.disableEdit})}}function bo(e){return {title:e?.title??i18n.i18n.t("common.trigger"),className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r),s=(a!=null?`${i18n.i18n.t("tpsl.tp")}: ${utils.commifyOptional(a,{fix:n,padEnd:true})}`:"")+(i!=null?`${a?` `:""}${i18n.i18n.t("tpsl.sl")}: ${utils.commifyOptional(i,{fix:n,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsxRuntime.jsx(uo,{})}}function ua(e){return {title:i18n.i18n.t("common.tpsl"),className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:hooks.utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:n,tp_trigger_price:i}=o(),a=(i!=null?`${i18n.i18n.t("tpsl.tp")}: ${i}`:"")+(n!=null?`${i?` `:""}${i18n.i18n.t("tpsl.sl")}: ${n}`:"");return a.length>0?a:"--"},render:(t,r)=>jsxRuntime.jsx(kr,{order:r})}}function ze(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,o)=>{let n=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return it(n,i)}:void 0,renderPlantText:(t,r)=>Vt(r,e?.isPending??false)==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(Vt(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let o=Vt(r,e?.isPending??false);return o==="Entire position"?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:o})}}}function Ht(e){return {title:i18n.i18n.t("common.realizedPnl"),dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??n,a=new utils.Decimal(t??0).toDecimalPlaces(i,utils.Decimal.ROUND_DOWN).toNumber(),s=utils.commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:o}=$(),n=e?.pnlNotionalDecimalPrecision??o,i=new utils.Decimal(t??0).toDecimalPlaces(n,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text.numeral,{dp:n,rm:utils.Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsxRuntime.jsx(Je,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:uiShare.SharePnLDialogId})]})}}}function Ee(e){return {title:i18n.i18n.t("orderEntry.reduceOnly"),dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no"),render:t=>jsxRuntime.jsx(ui.Text,{children:t?i18n.i18n.t("common.yes"):i18n.i18n.t("common.no")})}}function $e(e){return {title:i18n.i18n.t("orders.column.hidden"),dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes"),render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?i18n.i18n.t("common.no"):i18n.i18n.t("common.yes")})}}function Ue(e){return {title:i18n.i18n.t("orders.column.orderTime"),dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let o=new Date(t);return dateFns.format(o,"yyyy-MM-dd HH:mm:ss")},render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function rt(e){return {title:i18n.i18n.t("common.fee"),dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function ca(e){return {title:i18n.i18n.t("common.notional"),dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):utils.commifyOptional(r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?i18n.i18n.t("tpsl.entirePosition"):jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function ot(e){let t={[types.OrderStatus.NEW]:i18n.i18n.t("orders.status.pending"),[types.OrderStatus.FILLED]:i18n.i18n.t("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:i18n.i18n.t("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:i18n.i18n.t("orders.status.canceled"),[types.OrderStatus.REJECTED]:i18n.i18n.t("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:i18n.i18n.t("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:i18n.i18n.t("orders.status.completed")};return {title:i18n.i18n.t("common.status"),dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)},render:(r,o)=>{let n=r||o.algo_status;return t[n]||ue(n)}}}function bt(e){return {title:i18n.i18n.t("common.avgPrice"),dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>it(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===types.OrderType.MARKET&&!t?"--":jsxRuntime.jsx(ui.Text,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>utils.commifyOptional(t,{fix:2})}}function Po(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===types.OrderStatus.CANCELLED?jsxRuntime.jsx(to,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(mt,{order:r}):null}}function ma(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(mt,{order:r})}}function pa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(ro,{order:r}),jsxRuntime.jsx(mt,{order:r})]})}}function it(e,t){return e>t?1:e<t?-1:0}function Vt(e,t){return t?e.price&&e.quantity?new utils.Decimal(e.price).mul(e.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--":e.type===types.OrderType.CLOSE_POSITION&&e.status!==types.OrderStatus.FILLED?i18n.i18n.t("tpsl.entirePosition"):e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var To=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui.Badge,{color:r?"success":"danger",size:"xs",children:o(r?"common.buy":"common.sell")}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Lo=e=>{let {item:t}=e;react.useCallback(()=>{let o=typeof t.type=="string"?t.type.replace("_ORDER","").toLowerCase():t.type;return t.algo_order_id&&t.algo_type!==types.AlgoOrderRootType.BRACKET?`Stop ${o}`:ue(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:ce(e.item)?.map((o,n)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},n))})},No=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:"yyyy-MM-dd hh:mm:ss",intensity:36,size:"2xs",children:t.updated_time})},wo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.status||t.algo_status,n=react.useMemo(()=>({[types.OrderStatus.NEW]:r("orders.status.pending"),[types.OrderStatus.FILLED]:r("orders.status.filled"),[types.OrderStatus.PARTIAL_FILLED]:r("orders.status.partialFilled"),[types.OrderStatus.CANCELLED]:r("orders.status.canceled"),[types.OrderStatus.REJECTED]:r("orders.status.rejected"),[types.OrderStatus.INCOMPLETE]:r("orders.status.incomplete"),[types.OrderStatus.COMPLETED]:r("orders.status.completed")}),[r]);return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,size:"2xs",children:n[o]||ue(o)})},Jt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:r("common.qty"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:r("tpsl.entirePosition"),intensity:80,children:o?r("tpsl.entirePosition"):t.quantity})})},Xt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:r("orders.status.filled")}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var Io=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:[r("common.notional"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:o})})},Zt=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("orders.column.triggerPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},Eo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:r("common.markPrice"),align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},vo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&o;return jsxRuntime.jsx(ui.Statistic,{label:r("common.limitPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsxRuntime.jsx(ui.Text,{children:r("common.marketPrice")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},Ao=e=>{let{tp_trigger_price:t,tpPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.tpTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(xt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.tpPnl")}:`,"\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Do=e=>{let{sl_trigger_price:t,slPnL:r}=G(),{t:o}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:o("tpsl.slTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(xt,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsxs(ui.Text,{intensity:54,children:[`${o("tpsl.slPnl")}:`,"\xA0\xA0"]}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Fo=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.tpPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},ko=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:t("tpsl.slPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:t("common.marketPrice")})})},qo=e=>{let{item:t}=e,{t:r}=i18n.useTranslation(),o=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:r("tpsl.entirePosition")}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t,r]);return jsxRuntime.jsx(ui.Statistic,{label:r("common.quantity"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:o})},Ro=e=>{let{t}=i18n.useTranslation();return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:[t("common.avgPrice"),jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text