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