UNPKG

@orderly.network/ui-orders

Version:

17 lines (16 loc) 70.7 kB
import { createContext, forwardRef, useMemo, useEffect, useRef, useImperativeHandle, useCallback, useState, useContext } from 'react'; import { usePagination, modal, Text, Flex, DataFilter, TableFeatures, cn, Tabs, TabPanel, Button, Badge, toast as toast$1, Popover, ThrottledButton, Tooltip, CloseIcon, ShareIcon, PopoverRoot, PopoverTrigger, PopoverContent, Slider, Input, inputFormatter, CheckIcon, Grid, Picker, ListView, Divider, Statistic, SimpleDialog, useModal, Checkbox } from '@orderly.network/ui'; import { OrderStatus, AlgoOrderRootType, OrderSide, OrderType, AlgoOrderType } from '@orderly.network/types'; import { AuthGuardDataTable } from '@orderly.network/ui-connector'; import { useSymbolsInfo, useOrderStream, useLocalStorage, getMinNotional, useMutation, useSWRConfig, useAccount, unstable_serialize, utils, useSymbolPriceRange, useConfig, useReferralInfo, useSymbolLeverage, useMaxQty, useThrottledCallback, useOrderEntity } from '@orderly.network/hooks'; import { useTranslation, i18n, Trans } from '@orderly.network/i18n'; import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; import { commifyOptional, Decimal, commify } from '@orderly.network/utils'; import { PositionTPSLPopover, PositionTPSLSheet } from '@orderly.network/ui-tpsl'; import { SharePnLDialogId, SharePnLBottomSheetId } from '@orderly.network/ui-share'; import { format, subDays } from 'date-fns'; import { useDataTap, useOrderEntryFormErrorMsg } from '@orderly.network/react-app'; var Ct=e=>{let{current:t,pnlNotionalDecimalPrecision:r,sharePnLConfig:o}=e,n=useRef(null);return useImperativeHandle(e.ref,()=>({download:()=>{n.current?.download?.();}})),{current:t,pnlNotionalDecimalPrecision:r,orderListRef:n,sharePnLConfig:o}};var Te=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function ue(e){let t=e.type,r=e.algo_type;if(typeof t<"u"){let o=[];if(e.parent_algo_type){if(r===AlgoOrderType.STOP_LOSS){let i=t===OrderType.CLOSE_POSITION?[i18n.t("common.position"),i18n.t("tpsl.sl")]:[i18n.t("tpsl.sl")];o.push(...i);}if(r===AlgoOrderType.TAKE_PROFIT){let i=t===OrderType.CLOSE_POSITION?[i18n.t("common.position"),i18n.t("tpsl.tp")]:[i18n.t("tpsl.tp")];o.push(...i);}return o}let n=typeof t=="string"?t.replace("_ORDER",""):"";if([OrderType.ASK,OrderType.BID].includes(t))return [i18n.t("orderEntry.orderType.limit")];if(e.algo_order_id===void 0||e.algo_order_id&&r==="BRACKET")return [{[OrderType.LIMIT]:i18n.t("orderEntry.orderType.limit"),[OrderType.MARKET]:i18n.t("orderEntry.orderType.market"),[OrderType.POST_ONLY]:i18n.t("orderEntry.orderType.postOnly"),[OrderType.IOC]:i18n.t("orderEntry.orderType.ioc"),[OrderType.FOK]:i18n.t("orderEntry.orderType.fok")}[n]||Te(n)];if(n)return [{[OrderType.LIMIT]:i18n.t("orderEntry.orderType.stopLimit"),[OrderType.MARKET]:i18n.t("orderEntry.orderType.stopMarket")}[n]||n]}if(typeof r<"u"){let o=[];r===AlgoOrderRootType.POSITIONAL_TP_SL&&o.push(i18n.t("common.position"));let n=e?.child_orders?.find(a=>a.algo_type===AlgoOrderType.TAKE_PROFIT&&!!a.trigger_price),i=e?.child_orders?.find(a=>a.algo_type===AlgoOrderType.STOP_LOSS&&!!a.trigger_price);return (n||i)&&o.push(n&&i?i18n.t("common.tpsl"):n?i18n.t("tpsl.tp"):i18n.t("tpsl.sl")),o}}function ne(e){return e.status===OrderStatus.CANCELLED||e.algo_status===OrderStatus.CANCELLED}function ln(e){if(e.algo_type!==AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(n=>n.algo_type===AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(n=>n.algo_type===AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function lt(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=ln(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let n=e.side===OrderSide.BUY?e.quantity:e.quantity*-1,i=r?.trigger_price&&utils.priceToPnl({qty:n,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&utils.priceToPnl({qty:n,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=i?utils.calcTPSL_ROI({pnl:i,qty:e.quantity,price:e.price}):void 0,d=a?utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:i,slPnL:a},roi:{tpRoi:s,slRoi:d}}}var Cr=createContext({}),W=()=>useContext(Cr),Tt=e=>{let t=useSymbolsInfo()[e.symbol];return jsx(Cr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var Lr=createContext({}),X=()=>useContext(Lr),Nt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:n}=e,{t:i}=useTranslation(),a=useSymbolsInfo(),s=useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),d=useCallback(async(l,b)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:false;await modal.sheet({title:i("orders.editOrder"),classNames:{content:"oui-edit-order-sheet-content"},content:jsx(Fragment,{children:"Content"})});},[i]),u=useCallback((l,b,m)=>{let{min_notional:O}=a[l](),_=getMinNotional({price:b,qty:m,min_notional:O});if(_!==void 0)return i("orderEntry.total.error.min",{value:_})},[a,i]);return jsx(Lr.Provider,{value:{onCancelOrder:s,onEditOrder:d,editOrder:r,editAlgoOrder:n,checkMinNotional:u},children:e.children})};var Ir=createContext({}),G=()=>useContext(Ir),It=e=>{let{quote_dp:t}=W(),[r,o]=useState(),[n]=useMutation("/v1/algo/order","DELETE"),[i]=useMutation("/v1/algo/order","PUT"),a=useSWRConfig(),{state:s}=useAccount(),d=useMemo(()=>unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),u=async h=>n(null,{order_id:h.algo_order_id,symbol:h.symbol}),l=async(h,F)=>i({order_id:h.algo_order_id,child_orders:h.child_orders.map(T=>({order_id:T.algo_order_id,quantity:F.order_quantity}))}),b=h=>a.cache.get(d)?.data.rows.find(T=>T.symbol===h),{sl_trigger_price:m,tp_trigger_price:O,tpPnL:_,slPnL:I}=wn({order:e.order,position:r,quote_dp:t});return useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??false)){let h=b(e.order.symbol);h&&o(h);}},[e.order.symbol]),jsx(Ir.Provider,{value:{order:e.order,sl_trigger_price:m,tp_trigger_price:O,tpPnL:_,slPnL:I,onCancelOrder:u,onUpdateOrder:l,getRelatedPosition:b,position:r},children:e.children})};function wn(e){let{order:t,position:r,quote_dp:o}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:n,tp_trigger_price:i}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,u=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:n,tp_trigger_price:i,slPnL:u,tpPnL:d}}var qe=e=>{let{type:t,base:r,value:o,cancelPopover:n,isSubmitting:i,onConfirm:a}=e,{t:s}=useTranslation();return jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsx("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:(()=>{let u={values:{base:r,value:commify(o)},components:[jsx("span",{className:"oui-text-warning-darken"})]};switch(t){case 0:return jsx(Trans,{i18nKey:"order.edit.confirm.quantity",...u});case 1:return jsx(Trans,{i18nKey:"order.edit.confirm.price",...u});case 2:return jsx(Trans,{i18nKey:"order.edit.confirm.triggerPrice",...u})}})()}),jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsx(Button,{color:"secondary",size:"md",onClick:n,disabled:i,children:s("common.cancel")}),jsx(ThrottledButton,{size:"md",loading:i,onClick:a,children:s("common.confirm")})]}),jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:n,children:jsx(CloseIcon,{size:16,color:"white",opacity:1})})]})};var Re=e=>{let{inputRef:t,dp:r,value:o,setValue:n,setEditing:i,error:a,handleKeyDown:s,onClick:d,onClose:u,onFocus:l,onBlur:b,hintInfo:m}=e;useEffect(()=>{let _=t.current;if(_){let I=_.value.length;_.setSelectionRange(I,I);}i(true);},[]);let O=(m?.length||0)>0;return jsx(Tooltip,{content:m,open:O,children:jsx(Input,{ref:t,type:"text",size:"sm",formatters:[inputFormatter.numberFormatter,inputFormatter.dpFormatter(r),inputFormatter.currencyFormatter],value:o,onValueChange:_=>n(_),helpText:a,onClick:_=>{_.stopPropagation(),_.preventDefault();},autoComplete:"off",onFocus:l,onBlur:b,onKeyDown:s,autoFocus:true,color:O?"danger":void 0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsx("button",{onClick:d,children:jsx(CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Ft=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[n,i]=useState(t.quantity.toString()),[a,s]=useState(false),{t:d}=useTranslation();useEffect(()=>{w(t.quantity.toString());},[e.order.quantity]);let[u,l]=useState(false),[b,m]=useState(),{editOrder:O,editAlgoOrder:_,checkMinNotional:I}=X(),{onUpdateOrder:h,position:F}=G(),{base_dp:T,base:V,base_tick:f}=W(),w=async(g,y)=>{i(g);let k=Math.abs(F?.position_qty||0);if(F&&o&&Number(g)>k)m(d("orders.quantity.lessThanPosition",{quantity:k}));else {let Ce=Number(g);y&&Ce>y?m(d("orders.quantity.lessThan",{quantity:commifyOptional(y,{fix:T})})):m(void 0);}return Promise.resolve()},M=()=>{l(false),s(false);},R=()=>{l(false),w(t.quantity.toString()),s(false);},[x,C]=useState(false),D=useRef(null),te=()=>{if(b)return;if(Number(n)===Number(t.quantity)){s(false);return}let g=t.algo_order_id!==void 0?t.trigger_price:t.price;if(g!==null&&t.reduce_only!==true){let y=I(t.symbol,g,n);if(y){toast$1.error(y),C(false),R();return}}l(true);},E=g=>{g?.stopPropagation(),g?.preventDefault(),te();},Y=g=>{g.key==="Enter"&&(g?.stopPropagation(),g?.preventDefault(),te());},v=useCallback(()=>{C(true);let g={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:n,algo_order_id:t.algo_order_id};if(typeof g.algo_order_id<"u"&&g.order_type==="MARKET"){let{order_price:k,...Ce}=g;g=Ce;}typeof t.reduce_only<"u"&&(g.reduce_only=t.reduce_only),t.order_tag!==void 0&&(g={...g,order_tag:t.order_tag}),t?.visible_quantity===0&&(g.visible_quantity=0),t?.tag!==void 0&&(g.order_tag=t.tag);let y;"algo_type"in t&&t.algo_type===AlgoOrderRootType.TP_SL?y=h(t,g):t.algo_order_id!==void 0?y=_(t.algo_order_id.toString(),g):y=O(t.order_id.toString(),g),y.then(k=>{M(),w(n.toString());},k=>{toast$1.error(k.message),w(t.quantity.toString()),R();}).finally(()=>C(false));},[n]),A=useRef(null),re=useRef(null),de=g=>{A.current&&re.current&&!A.current.contains(g.target)&&!re.current.contains(g.target)&&!u&&R();};useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[u,t.quantity]);let De=()=>!a||e.disableEdit?jsx(Gn,{order:t,quantity:n,setEditing:s,disableEdit:e.disableEdit}):jsx(Jn,{inputRef:D,quantitySliderRef:re,base_dp:T,base_tick:f,quantity:n,setQuantity:w,editing:a,setEditing:s,handleKeyDown:Y,onClick:E,onClose:R,symbol:t.symbol,reduce_only:o,positionQty:F?.position_qty,error:b,confirmOpen:u,side:t.side,order:t,setError:m});return jsx(Popover,{open:u,onOpenChange:l,content:jsx(qe,{type:0,base:V,value:n,cancelPopover:R,isSubmitting:x,onConfirm:v}),contentProps:{onOpenAutoFocus:g=>{}},children:jsx("div",{onClick:g=>{g.stopPropagation(),g.preventDefault();},ref:A,children:De()})})},Gn=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxs(Flex,{direction:"row",justify:"start",gap:1,className:cn("oui-max-w-[110px] oui-relative",t.side===OrderSide.BUY&&"oui-text-trade-profit",t.side===OrderSide.SELL&&"oui-text-trade-loss",ne(t)&&"oui-text-base-contrast-20"),onClick:n=>{n.stopPropagation(),n.preventDefault(),e.setEditing(true);},children:["algo_type"in t&&t.algo_type===AlgoOrderRootType.TP_SL?null:jsxs(Fragment,{children:[jsx("span",{children:o}),jsx("span",{children:"/"})]}),jsx(Flex,{r:"base",className:cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsx(Text,{size:"2xs",children:r})})]})},Jn=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:n,quantity:i,setQuantity:a,editing:s,setEditing:d,handleKeyDown:u,onClick:l,onClose:b,error:m,symbol:O,reduce_only:_,positionQty:I,confirmOpen:h,side:F,order:T}=e,V=useMaxQty(O,T.side,T.reduce_only),f=useMemo(()=>_?Math.abs(I??0):T.quantity+Math.abs(V),[T.quantity,V,_,I]),[w,M]=useState(void 0);useEffect(()=>{if(w===void 0){let x=new Decimal(i).div(f).abs().mul(100).toNumber();M(x);}},[w,f,i]);let R=async x=>(n>0&&(x=utils.formatNumber(x,n)??x),a(`${x}`,f));return jsxs(PopoverRoot,{open:!h,children:[jsx(PopoverTrigger,{children:jsx(Re,{inputRef:t,dp:o,value:i,setValue:x=>{let C=Math.abs(Math.min(Number(x),f)).toString();if(a(x,f),x.endsWith("."))return;if(Number(C)===0){M(0);return}let D=new Decimal(x).div(f).mul(100).toDecimalPlaces(2,Decimal.ROUND_DOWN).toNumber();M(Math.min(100,D));},setEditing:d,handleKeyDown:u,onClick:l,onClose:b,onBlur:x=>{R(x.target.value);},hintInfo:m})}),jsx(PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:x=>{x.preventDefault();},children:jsxs(Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsx(Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:false,unit:"%",rm:Decimal.ROUND_DOWN,children:`${w}`}),jsxs(Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsx(Slider,{markCount:4,value:[w??0],onValueChange:x=>{let C=Array.from(x.values());M(C[0]);let D=new Decimal(C[0]).div(100).mul(f).abs().toFixed(o,Decimal.ROUND_DOWN);a(D,f);},onValueCommit:x=>{let C=new Decimal(x[0]).div(100).mul(f).abs().toFixed(o,Decimal.ROUND_DOWN);R(C).finally(()=>{t.current.focus();});}}),jsx(Xn,{onClick:x=>{M(x*100);let C=new Decimal(x).mul(f).abs().toFixed(o,Decimal.ROUND_DOWN);C=utils.formatNumber(C,n)??C,a(C,f),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(C.length,C.length);},100);}})]})]})})]})},Xn=e=>{let{t}=useTranslation(),r=[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:t("common.max"),value:1}];return jsx(Flex,{gap:2,width:"100%",children:r.map((o,n)=>jsx(Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(o.value);},className:"oui-w-1/5",children:o.label},n))})};var Ur=e=>{let{order:t}=e,{t:r}=useTranslation(),[o,n]=useState(()=>t.type===OrderType.MARKET&&!t.price?"Market":t.price?.toString()??"Market"),[i,a]=useState(false),[s,d]=useState(false),u=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&u,[b,m]=useState(false),{editOrder:O,editAlgoOrder:_,checkMinNotional:I}=X(),{base:h,quote_dp:F}=W(),T=useSymbolPriceRange(t.symbol,t.side,u?t.trigger_price:void 0),V=()=>{a(false),d(false);},f=()=>{a(false),n(t.price?.toString()??"Market"),d(false);},w=useMemo(()=>!T||l||!s?"":Number(o)>T.max?r("orders.price.greaterThan",{max:T.max}):Number(o)<T.min?r("orders.price.lessThan",{min:T.min}):"",[l,s,T,o,r]),M=v=>{if(v?.stopPropagation(),v?.preventDefault(),!(w.length>0)){if(o===`${t.price}`){d(false);return}if(t.reduce_only!==true){let A=I(t.symbol,o,t.quantity);if(A){toast$1.error(A),m(false),f();return}}a(true);}},R=v=>{v.key==="Enter"&&M(v);},x=()=>{m(true);let v=t.order_id,A={order_price:o,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(A.reduce_only=t.reduce_only),t.order_tag!==void 0&&(A={...A,order_tag:t.order_tag}),u&&(v=t.algo_order_id,A={...A,order_id:v,price:o,algo_order_id:v}),t?.visible_quantity===0&&(A.visible_quantity=0),t.tag!==void 0&&(A.order_tag=t.tag);let re;t.algo_order_id!==void 0?re=_(t.algo_order_id.toString(),A):re=O(t.order_id.toString(),A),re.then(de=>{V(),n(o);},de=>{toast$1.error(de.message),f();}).finally(()=>m(false));},C=useRef(null);useEffect(()=>{e.order.price&&n(`${e.order.price}`);},[e.order.price]);let D=useRef(null),te=v=>{D.current&&!D.current.contains(v.target)&&!i&&f();};if(useEffect(()=>(document.addEventListener("mousedown",te),()=>{document.removeEventListener("mousedown",te);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||o==="Market")return jsx("span",{children:r("common.marketPrice")});let Y=()=>!s||e.disableEdit?jsx(si,{order:t,price:o,setEditing:d,disableEdit:e.disableEdit}):jsx(Re,{inputRef:C,dp:F,value:o,setValue:n,setEditing:d,handleKeyDown:R,onClick:M,onClose:f,hintInfo:w});return jsx(Popover,{open:i,onOpenChange:a,content:jsx(qe,{type:1,base:h,value:o,cancelPopover:f,isSubmitting:b,onConfirm:x}),children:jsx("div",{onClick:v=>{v.stopPropagation(),v.preventDefault();},ref:D,children:Y()})})},si=e=>{let{order:t,price:r}=e;return jsx("div",{className:cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsx(Flex,{r:"base",className:cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsx(Text,{size:"2xs",children:commifyOptional(r)})})})};var Gr=e=>{let{order:t}=e,[r,o]=useState("");useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let n=t?.algo_order_id!==void 0,i=t?.algo_type==="BRACKET",[a,s]=useState(false),[d,u]=useState(false),[l,b]=useState(false),{editAlgoOrder:m,checkMinNotional:O}=X(),{base:_,quote_dp:I,quote_max:h,quote_min:F}=W(),T=useMemo(()=>{if(!((!n||i)&&!d)){if(Number(r)>h)return `Trigger price must be less than ${h}`;if(Number(r)<F)return `Trigger price must be greater than ${F}`}},[d,r,n,i]),V=()=>{s(false),u(false);},f=()=>{o(t.trigger_price?.toString()??"0"),s(false),u(false);},w=useRef(null),M=E=>{w.current&&!w.current.contains(E.target)&&!a&&f();};useEffect(()=>(document.addEventListener("mousedown",M),()=>{document.removeEventListener("mousedown",M);}),[a,t.trigger_price]);let R=E=>{if(E?.stopPropagation(),E?.preventDefault(),u(false),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==true){let Y=O(t.symbol,t.price,t.quantity);if(Y){toast$1.error(Y),b(false),f();return}}s(true);}},x=E=>{E.key==="Enter"&&R(E);},C=()=>{if((T??"").length>0)return;b(true);let E={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),m(`${t.algo_order_id}`,E).then(Y=>{V(),o(r);},Y=>{toast$1.error(Y.message),o(t.trigger_price?.toString()??"--"),f();}).finally(()=>b(false));},D=useRef(null);if(!n||i)return jsx(Text,{children:"--"});let te=()=>!d||e.disableEdit?jsx(ci,{order:t,price:r,setEditing:u,disableEdit:e.disableEdit}):jsx(Re,{inputRef:D,dp:I,value:r,setValue:o,setEditing:u,handleKeyDown:x,onClick:R,onClose:f,hintInfo:T});return jsx(Popover,{open:a,onOpenChange:s,content:jsx(qe,{type:2,base:_,value:r,cancelPopover:f,isSubmitting:l,onConfirm:C}),children:jsx("div",{onClick:E=>{E.stopPropagation(),E.preventDefault();},ref:w,children:te()})})},ci=e=>{let{order:t,price:r}=e;return jsx("div",{className:cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",ne(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(true);},children:jsx(Flex,{r:"base",className:cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsx(Text,{size:"2xs",children:r})})})};var mt=e=>{let{order:t}=e,{t:r}=useTranslation(),{onCancelOrder:o}=X(),[n,i]=useState(false);return jsx(ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:a=>{o&&(a.preventDefault(),a.stopPropagation(),i(true),o(t).then(s=>s,s=>{toast$1.error(s.message);}).finally(()=>{i(false);}));},loading:n,children:r("common.cancel")})};var Jr=e=>{let{record:t}=e,[r,o]=useState(false),[n,{data:i,error:a,reset:s,isMutating:d}]=useMutation("/v1/order"),{t:u}=useTranslation(),l=useConfig("brokerId"),b=useCallback(()=>{o(false);let m={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(m.visible_quantity=0),typeof t.reduce_only<"u"&&(m.reduce_only=t.reduce_only),n(m);},[]);return jsx(Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:m=>{d||(m.preventDefault(),m.stopPropagation(),b());},children:u("orders.history.renew")})};var eo=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=G();return jsx(Ni,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:true})},Ni=e=>{let{direction:t="row",order:r,position:o}=e,n=useSymbolsInfo(),{t:i}=useTranslation(),a=useMemo(()=>{let u=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&u.push(jsx(Zr,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:AlgoOrderType.TAKE_PROFIT,symbolInfo:n[r.symbol]()},"tp")),e.stopLossPrice&&u.push(jsx(Zr,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:AlgoOrderType.STOP_LOSS,symbolInfo:n[r.symbol]()},"sl")),jsx("div",{children:u})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),s=useMemo(()=>{let u=[];return r?.symbol?(e.takeProfitPrice&&u.push(jsx(Text.numeral,{className:cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.tp")} -`,"\xA0"]}):""},"tp")),e.stopLossPrice&&u.push(jsx(Text.numeral,{className:cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:n[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxs("span",{className:"oui-text-base-contrast-54",children:[`${i("tpsl.sl")} -`,"\xA0"]}):""},"sl")),u.length===0?jsx("span",{children:"-"}):(u.length===2&&t==="row"&&u.splice(1,0,jsx("span",{children:"/"},"split")),u)):jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol,i]),d=jsx("div",{className:cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:s});return e.tooltip?jsx(Tooltip,{content:a,className:"oui-bg-base-5",arrow:{className:"oui-fill-base-5"},children:d}):d},Zr=e=>{let{qty:t,price:r,entryPrice:o,orderSide:n,orderType:i,symbolInfo:a}=e,{t:s}=useTranslation(),d=utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:n,orderType:i},{symbol:a}),l=(i===AlgoOrderType.TAKE_PROFIT?"TP":"SL")==="TP"?`${s("tpsl.tpPnl")}:`:`${s("tpsl.slPnl")}:`;return jsxs("div",{className:"oui-flex oui-items-center",children:[jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:l}),jsx(Text.numeral,{rule:"price",dp:a.quote_dp,padding:false,className:d===0?"oui-text-base-contrast-36":d>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsx("span",{children:d===0?"":d>0?"+":"-"}),suffix:jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(d)}`})]})};var no=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=W(),{t:n}=useTranslation(),{sl_trigger_price:i,tp_trigger_price:a}=useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:s,roi:d}=lt(t);return !a&&!i?"--":jsx(Tooltip,{content:jsxs(Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof s.tpPnL<"u"&&jsx(Text.numeral,{prefix:jsxs(Text,{intensity:80,children:[`${n("tpsl.tpPnl")}:`," \xA0"]}),suffix:jsx(Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:true,children:s.tpPnL}),typeof s.slPnL<"u"&&jsx(Text.numeral,{prefix:jsxs(Text,{intensity:80,children:[`${n("tpsl.slPnl")}:`," \xA0"]}),suffix:jsx(Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:s.slPnL})]}),className:"oui-bg-base-6",children:jsxs(Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsx(ro,{type:"TP",value:a,quote_dp:r}),jsx(ro,{type:"SL",value:i,quote_dp:r})]})})},ro=e=>{let{type:t,value:r,quote_dp:o}=e,{t:n}=useTranslation();return r?jsx(Text.numeral,{className:cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxs("span",{className:"oui-text-base-contrast-54",children:[t==="TP"?`${n("tpsl.tp")} -`:`${n("tpsl.sl")} -`,"\xA0"]}),children:r},"tp"):jsx(Fragment,{})};var io=e=>{let{position:t,order:r}=G(),{quote_dp:o,base_dp:n}=W(),{t:i}=useTranslation();return jsx(PositionTPSLPopover,{quoteDP:o,baseDP:n,position:t,order:r,label:i("common.edit"),isEditing:true})};var so=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=G(),{t:r}=useTranslation();return jsxs("div",{children:[t?jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxs(Text,{intensity:54,children:[`${r("tpsl.tp")} -`,"\xA0"]}),jsx("span",{children:r("common.marketPrice")})]}):null,e?jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxs("span",{className:"oui-text-base-contrast-54",children:[`${r("tpsl.sl")} -`,"\xA0"]}),jsx("span",{children:r("common.marketPrice")})]}):null]})};function lo(e){let{sl_trigger_price:t,tp_trigger_price:r}=!("algo_type"in e)||!Array.isArray(e.child_orders)?{}:utils.findTPSLFromOrder(e),o=r?`${i18n.t("tpsl.tp")} - ${i18n.t("common.marketPrice")}`:void 0,n=t?`${i18n.t("tpsl.sl")} - ${i18n.t("common.marketPrice")}`:void 0;return {tpTriggerPrice:o,slTriggerPrice:n}}var Wt=e=>{let{t}=useTranslation();return e.sharePnLConfig==null?jsx(Fragment,{}):jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),modal.show(e.modalId,{pnl:{entity:{symbol:e.order.symbol,pnl:e.order.realized_pnl,side:e.order.side=="BUY"?t("share.pnl.share.long"):t("share.pnl.share.short"),openPrice:e.order.average_executed_price,openTime:e.order.updated_time,quantity:e.order.quantity},refCode:e.refCode,leverage:e.leverage,...e.sharePnLConfig}});},children:jsx(ShareIcon,{color:"white",opacity:.54,size:e.iconSize??16})})};var uo=e=>{let{sharePnLConfig:t,order:r,modalId:o,iconSize:n}=e,{getFirstRefCode:i}=useReferralInfo(),a=useMemo(()=>i()?.code,[i]),s=useSymbolLeverage(e.order.symbol);return {iconSize:n,order:r,refCode:a,leverage:s,sharePnLConfig:t,modalId:o}};var Ze=e=>{let t=uo(e);return jsx(Wt,{...t})};var fo=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o,sharePnLConfig:n}=e,{t:i}=useTranslation();return useMemo(()=>{switch(t){case "all":return [Ne({width:130,showType:true,onSymbolChange:r,enableSort:false}),Me({width:130,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:130,title:i("orders.column.orderPrice"),disableEdit:true,enableSort:false}),ft({width:130,enableSort:false}),co({width:130,symbolsInfo:e.symbolsInfo}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:130,enableSort:false}),et({width:130}),tt({width:130}),we({width:130}),$e({width:130}),mo({width:130}),Ue({width:160,enableSort:false})];case "pending":return [Ne({width:172,showType:true,onSymbolChange:r,enableSort:false}),Me({width:162,className:"oui-pr-0",enableSort:false}),We({width:162,className:"oui-pr-0",enableSort:false}),je({width:162,className:"oui-pr-0"}),oa({width:130}),ze({width:162,isPending:true}),we({width:162}),$e({width:162}),Ue({width:162,enableSort:false}),ia({width:162})];case "tp_sl":return [Ne({width:176,showType:true,onSymbolChange:r,enableSort:false}),ea({width:176}),co({width:176,symbolsInfo:e.symbolsInfo}),ta({width:176}),na({width:176}),we({width:176}),Ue({width:176,enableSort:false}),aa({width:176})];case "filled":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,title:i("orders.column.orderPrice"),disableEdit:true}),ra({width:124}),je({width:124,disableEdit:true}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo,hideShare:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:176})];case "cancelled":return [Ne({showType:true,width:154,onSymbolChange:r,enableSort:false}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0",enableSort:false}),We({width:124,disableEdit:true,enableSort:false}),ft({width:124,enableSort:false}),je({width:124,disableEdit:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124})];case "rejected":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:124,disableEdit:true,className:"oui-pl-0 oui-pr-0"}),We({width:124,disableEdit:true}),ft({width:124}),je({width:124,disableEdit:true}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:176})];case "orderHistory":return [Ne({showType:true,width:154,onSymbolChange:r}),Me({width:150,disableEdit:true,className:"oui-pl-6 oui-pr-0"}),We({width:124,disableEdit:true}),ft({width:124}),je({width:124,disableEdit:true}),zt({width:124,pnlNotionalDecimalPrecision:o,sharePnLConfig:n,symbolsInfo:e.symbolsInfo}),ze({width:124}),et({width:124}),tt({width:124}),we({width:124}),$e({width:124}),Ue({width:150}),mo({width:80})]}},[t,o,n,i])};function Ne(e){return {title:i18n.t("common.symbol"),dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,renderPlantText:(t,r)=>{let o=ue(r)?.join(","),n=o?.length?` (${o})`:"";return `${t.split("_")[1]}-PERP${n}`},render:(t,r)=>{let o=ne(r);return jsxs(Flex,{gap:2,children:[jsx("div",{className:cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxs(Flex,{direction:"column",itemAlign:"start",children:[jsx(Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:n=>{e?.onSymbolChange?.({symbol:t}),n.stopPropagation(),n.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsx(Flex,{direction:"row",gap:1,children:ue(r)?.map((n,i)=>jsx(Badge,{color:n.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",className:"oui-break-normal oui-whitespace-nowrap",children:n},i))})]})]})}}}function Me(e){return {title:i18n.t("orders.column.fill&Quantity"),dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return ot(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.type===OrderType.CLOSE_POSITION&&r.status!==OrderStatus.FILLED)return i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===AlgoOrderRootType.TP_SL?"":`${o} / `)+`${r.quantity}`},render:(t,r)=>r.type===OrderType.CLOSE_POSITION&&r.status!==OrderStatus.FILLED?i18n.t("tpsl.entirePosition"):jsx(Ft,{order:r,disableEdit:e?.disableEdit})}}function ea(e){return {title:i18n.t("common.quantity"),className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??false?(t,r)=>{let o=(t.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,n=(r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return ot(o,n)}:void 0,renderPlantText:(t,r)=>{if(r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL)return i18n.t("tpsl.entirePosition");let o=r.total_executed_quantity;return ("algo_type"in r&&r.algo_type===AlgoOrderRootType.TP_SL?"":`${o}/`)+`${r.quantity}`},render:(t,r)=>r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?i18n.t("tpsl.entirePosition"):jsx(Ft,{order:r})}}function We(e){return {title:e?.title??i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??false?(t,r,o)=>ot(t.price??0,r.price??0):void 0,renderPlantText:(t,r)=>commifyOptional(r.price?.toString(),{fallback:i18n.t("common.marketPrice")}),render:(t,r)=>jsx(Ur,{order:r,disableEdit:e?.disableEdit})}}function ta(e){return {title:e?.title??i18n.t("common.price"),dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let{tpTriggerPrice:o,slTriggerPrice:n}=lo(r),i=`${o||""}${n?`${o?` `:""}${n}`:""}`;return i.length>0?i:"--"},render:(t,r)=>jsx(so,{})}}function ra(e){return {title:i18n.t("common.avgPrice"),dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>commifyOptional(t)}}function je(e){return {title:i18n.t("common.trigger"),className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=r?.algo_order_id!==void 0,n=r?.algo_type==="BRACKET";return !o||n?"--":commifyOptional(t)},render:(t,r)=>jsx(Gr,{order:r,disableEdit:e?.disableEdit})}}function co(e){return {title:e?.title??i18n.t("common.trigger"),className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),{sl_trigger_price:i,tp_trigger_price:a}=!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:utils.findTPSLFromOrder(r),s=(a!=null?`${i18n.t("tpsl.tp")}: ${commifyOptional(a,{fix:n,padEnd:true})}`:"")+(i!=null?`${a?` `:""}${i18n.t("tpsl.sl")}: ${commifyOptional(i,{fix:n,padEnd:true})}`:"");return s.length>0?s:"--"},render:(t,r)=>jsx(eo,{})}}function oa(e){return {title:i18n.t("common.tpsl"),className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,renderPlantText:(t,r)=>{let o=()=>!("algo_type"in r)||!Array.isArray(r.child_orders)?{}:utils.findTPSLFromOrder(r.child_orders[0]),{sl_trigger_price:n,tp_trigger_price:i}=o(),a=(i!=null?`${i18n.t("tpsl.tp")}: ${i}`:"")+(n!=null?`${i?` `:""}${i18n.t("tpsl.sl")}: ${n}`:"");return a.length>0?a:"--"},render:(t,r)=>jsx(no,{order:r})}}function ze(e){return {title:i18n.t("common.notional"),dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??false?(t,r,o)=>{let n=t.type===OrderType.CLOSE_POSITION&&t.status!==OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,i=r.type===OrderType.CLOSE_POSITION&&r.status!==OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return ot(n,i)}:void 0,renderPlantText:(t,r)=>$t(r,e?.isPending??false)==="Entire position"?i18n.t("tpsl.entirePosition"):commifyOptional($t(r,e?.isPending??false),{fix:2}),render:(t,r)=>{let o=$t(r,e?.isPending??false);return o==="Entire position"?i18n.t("tpsl.entirePosition"):jsx(Text.numeral,{rm:Decimal.ROUND_DOWN,dp:2,children:o})}}}function zt(e){return {title:i18n.t("common.realizedPnl"),dataIndex:"realized_pnl",width:e?.width,className:e?.className,renderPlantText:(t,r)=>{let o=e?.symbolsInfo?.[r.symbol],n=o?.("quote_dp"),i=e?.pnlNotionalDecimalPrecision??n,a=new Decimal(t??0).toDecimalPlaces(i,Decimal.ROUND_DOWN).toNumber(),s=commifyOptional(a);return a>0?`+${s}`:s},render:(t,r)=>{let{quote_dp:o}=W(),n=e?.pnlNotionalDecimalPrecision??o,i=new Decimal(t??0).toDecimalPlaces(n,Decimal.ROUND_DOWN).toNumber();return jsxs(Flex,{gap:1,children:[jsx(Text.numeral,{dp:n,rm:Decimal.ROUND_DOWN,padding:false,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"}),!e?.hideShare&&jsx(Ze,{order:r,sharePnLConfig:e?.sharePnLConfig,modalId:SharePnLDialogId})]})}}}function we(e){return {title:i18n.t("orderEntry.reduceOnly"),dataIndex:"reduce_only",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t?i18n.t("common.yes"):i18n.t("common.no"),render:t=>jsx(Text,{children:t?i18n.t("common.yes"):i18n.t("common.no")})}}function $e(e){return {title:i18n.t("orders.column.hidden"),dataIndex:"visible",width:e?.width,className:e?.className,renderPlantText:(t,r)=>t!==0?i18n.t("common.no"):i18n.t("common.yes"),render:(t,r)=>jsx(Text,{children:r.visible_quantity!==0?i18n.t("common.no"):i18n.t("common.yes")})}}function Ue(e){return {title:i18n.t("orders.column.orderTime"),dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>{let o=new Date(t);return format(o,"yyyy-MM-dd HH:mm:ss")},render:t=>jsx(Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function et(e){return {title:i18n.t("common.fee"),dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function na(e){return {title:i18n.t("common.notional"),dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(t,r)=>r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?i18n.t("tpsl.entirePosition"):commifyOptional(r.quantity===0?"--":`${new Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`),render:(t,r)=>r.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?i18n.t("tpsl.entirePosition"):jsx(Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function tt(e){let t={[OrderStatus.NEW]:i18n.t("orders.status.pending"),[OrderStatus.FILLED]:i18n.t("orders.status.filled"),[OrderStatus.PARTIAL_FILLED]:i18n.t("orders.status.partialFilled"),[OrderStatus.CANCELLED]:i18n.t("orders.status.canceled"),[OrderStatus.REJECTED]:i18n.t("orders.status.rejected"),[OrderStatus.INCOMPLETE]:i18n.t("orders.status.incomplete"),[OrderStatus.COMPLETED]:i18n.t("orders.status.completed")};return {title:i18n.t("common.status"),dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,renderPlantText:(r,o)=>{let n=r||o.algo_status;return t[n]||Te(n)},render:(r,o)=>{let n=r||o.algo_status;return t[n]||Te(n)}}}function ft(e){return {title:i18n.t("common.avgOpen"),dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??false?(t,r)=>ot(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>r.type===OrderType.MARKET&&!t?"--":jsx(Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t}),renderPlantText:(t,r)=>commifyOptional(t,{fix:2})}}function mo(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===OrderStatus.CANCELLED?jsx(Jr,{record:r}):r.status===OrderStatus.NEW||r.algo_status===OrderStatus.NEW?jsx(mt,{order:r}):null}}function ia(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsx(mt,{order:r})}}function aa(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxs(Flex,{gap:3,children:[jsx(io,{order:r}),jsx(mt,{order:r})]})}}function ot(e,t){return e>t?1:e<t?-1:0}function $t(e,t){return t?e.price&&e.quantity?new Decimal(e.price).mul(e.quantity).toFixed(2,Decimal.ROUND_DOWN):"--":e.type===OrderType.CLOSE_POSITION&&e.status!==OrderStatus.FILLED?i18n.t("tpsl.entirePosition"):e.total_executed_quantity===0||Number.isNaN(e.average_executed_price)||e.average_executed_price===null?"--":`${e.total_executed_quantity*e.average_executed_price}`}var Po=e=>{let{item:t}=e,r=t.side===OrderSide.BUY,{t:o}=useTranslation();return jsx(Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsx(Badge,{color:r?"success":"danger",size:"xs",children:o(r?"common.buy":"common.sell")}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},xo=e=>{let {item:t}=e;useCallback(()=>{let o=typeof t.type=="string"?t.type.replace("_ORDER","").toLowerCase():t.type;return t.algo_order_id&&t.algo_type!==AlgoOrderRootType.BRACKET?`Stop ${o}`:Te(t.type)},[t]);return jsx(Flex,{direction:"row",gap:1,children:ue(e.item)?.map((o,n)=>jsx(Badge,{color:o.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:o},n))})},So=e=>{let{item:t}=e;return jsx(Text.formatted,{rule:"date",formatString:"yyyy-MM-dd hh:mm:ss",intensity:36,size:"2xs",children:t.updated_time})},_o=e=>{let{item:t}=e,{t:r}=useTranslation(),o=t.status||t.algo_status,n=useMemo(()=>({[OrderStatus.NEW]:r("orders.status.pending"),[OrderStatus.FILLED]:r("orders.status.filled"),[OrderStatus.PARTIAL_FILLED]:r("orders.status.partialFilled"),[OrderStatus.CANCELLED]:r("orders.status.canceled"),[OrderStatus.REJECTED]:r("orders.status.rejected"),[OrderStatus.INCOMPLETE]:r("orders.status.incomplete"),[OrderStatus.COMPLETED]:r("orders.status.completed")}),[r]);return jsx(Text.formatted,{intensity:80,size:"2xs",children:n[o]||Te(o)})},Kt=e=>{let{item:t}=e,{t:r}=useTranslation(),o=t.type===OrderType.CLOSE_POSITION&&t?.status!==OrderStatus.FILLED;return jsx(Statistic,{label:r("common.qty"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.base_dp,padding:false,coloring:true,placeholder:r("tpsl.entirePosition"),intensity:80,children:o?r("tpsl.entirePosition"):t.quantity})})},Qt=e=>{let{item:t}=e,{t:r}=useTranslation();return jsx(Statistic,{label:jsx(Text,{children:r("orders.status.filled")}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.base_dp,intensity:80,padding:false,rm:Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var Oo=e=>{let{item:t}=e,{t:r}=useTranslation(),o=useMemo(()=>t.price&&t.quantity?new Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsx(Statistic,{align:"end",label:jsxs(Text,{children:[r("common.notional"),jsx(Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.quote_dp,coloring:true,intensity:80,padding:false,rm:Decimal.ROUND_DOWN,children:o})})},Ht=e=>{let{item:t}=e,{t:r}=useTranslation();return jsx(Statistic,{label:r("orders.column.triggerPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsx(Text.numeral,{dp:e.quote_dp,intensity:80,padding:false,rm:Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},ho=e=>{let{item:t}=e,{t:r}=useTranslation();return jsx(Statistic,{label:r("common.markPrice"),align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.mark_price})})},Co=e=>{let{item:t}=e,{t:r}=useTranslation(),o=t?.algo_order_id!==void 0,n=t?.type==="MARKET"&&o;return jsx(Statistic,{label:r("common.limitPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:n?jsx(Text,{children:r("common.marketPrice")}):jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.price??"--"})})},To=e=>{let{tp_trigger_price:t,tpPnL:r}=G(),{t:o}=useTranslation();return jsx(Statistic,{label:o("tpsl.tpTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(yt,{content:r&&jsx(Text.numeral,{size:"2xs",showIdentifier:true,prefix:jsxs(Text,{intensity:54,children:[`${o("tpsl.tpPnl")}:`,"\xA0"]}),suffix:jsx(Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,color:"buy",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},Lo=e=>{let{sl_trigger_price:t,slPnL:r}=G(),{t:o}=useTranslation();return jsx(Statistic,{label:o("tpsl.slTrigger"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(yt,{content:r&&jsx(Text.numeral,{size:"2xs",prefix:jsxs(Text,{intensity:54,children:[`${o("tpsl.slPnl")}:`,"\xA0\xA0"]}),suffix:jsx(Text,{intensity:20,children:"\xA0USDC"}),coloring:true,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,color:"sell",padding:false,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},No=e=>{let{t}=useTranslation();return jsx(Statistic,{label:t("tpsl.tpPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text,{intensity:80,children:t("common.marketPrice")})})},wo=e=>{let{t}=useTranslation();return jsx(Statistic,{label:t("tpsl.slPrice"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text,{intensity:80,children:t("common.marketPrice")})})},Io=e=>{let{item:t}=e,{t:r}=useTranslation(),o=useMemo(()=>t.algo_type===AlgoOrderRootType.POSITIONAL_TP_SL?jsx("span",{className:"oui-text-base-contrast-80",children:r("tpsl.entirePosition")}):jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,intensity:80,padding:false,children:t.quantity}),[t,r]);return jsx(Statistic,{label:r("common.quantity"),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:o})},Eo=e=>{let{t}=useTranslation();return jsx(Statistic,{label:jsxs(Text,{children:[t("common.avgPrice"),jsx(Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,intensity:80,padding:false,children:e.item?.average_executed_price??"--"})})},vo=e=>{let{t}=useTranslation();return jsx(Statistic,{label:jsxs(Text,{children:[t("orders.column.orderPrice"),jsx(Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,intensity:80,padding:false,placeholder:t("common.marketPrice"),children:e.item?.price??"--"})})},Ao=e=>{let t=e?.item?.realized_pnl,{t:r}=useTranslation();return jsx(Statistic,{label:jsxs(Text,{children:[r("common.realizedPnl"),jsx(Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxs(Flex,{gap:1,children:[jsx(Text.numeral,{dp:e.quote_dp,rm:Decimal.ROUND_DOWN,padding:false,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"}),jsx(Ze,{order:e.item,sharePnLConfig:e.sharePnLConfig,modalId:SharePnLBottomSheetId,iconSize:12})]})})},yt=e=>{let{classNames:t,content:r}=e,[o,n]=useState(false);return typeof r>"u"?e.children:jsx(Tooltip,{content:r,className:t?.content,open:o,onOpenChange:n,arrow:{className:t?.arrow},children:jsx("div",{onClick:()=>n(i=>!i),children:e.children})})};var Vt=e=>{let {t}=useTranslation(),{item:r}=e;r.quantity>0;return jsx(Fragment,{children:jsx(Button,{variant:"outlined",fullWidth:true,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:t("common.edit")})})};var ko=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:n,isAlgoOrder:i}=e,a=t===OrderSide.BUY,{t:s}=useTranslation();return jsxs("div",{className:"oui-pt-2",children:[jsx(Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxs(Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsx(Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,children:e.item.symbol}),jsxs(Flex,{direction:"row",gap:1,children:[ue(e.item)?.map((d,u)=>jsx(Badge,{color:d.toLocaleLowerCase()==="position"?"primary":"neutral",size:"xs",children:d},u)),a&&jsx(Badge,{color:"success",size:"xs",children:s("common.buy")}),!a&&jsx(Badge,{color:"danger",size:"xs",children:s("common.sell")})]})]}),jsx(Divider,{}),jsxs(Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[i&&jsxs(Flex,{justify:"between",width:"100%",gap:1,children:[jsx(Text,{children:s("orders.column.triggerPrice")}),jsx(Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:Decimal.ROUND_DOWN,suffix:jsx(Text,{intensity:54,children:" USDC"}),children:n??"--"})]}),jsxs(Flex,{justify:"between",width:"100%",gap:1,children:[jsx(Text,{children:s("common.price")}),jsx(Text.numeral,{intensity:80,dp:e.quote_dp,padding:false,rm:Decimal.ROUND_DOWN,suffix:jsx(Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?s("common.marketPrice"):"--",children:e.isStopMarket?s("common.marketPrice"):r??"--"})]}),jsxs(Flex,{justify:"between",width:"100%",gap:1,children:[jsx(Text,{children:s("common.qty")}),jsx(Text.numeral,{color:t===OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:false,rm:Decimal.ROUND_DOWN,children:o??"--"})]})]}),jsxs(Flex,{className:"oui-gap-[2px]",children:[jsx(Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:d=>{e.setOrderConfirm(!d);}}),jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:s("orderEntry.disableOrderConfirm")})]})]})};var jt=e=>{let{item:t}=e,r=t.side===OrderSide.BUY,{t:o}=useTranslation(),{parseErrorMsg:n}=u