@orderly.network/ui-orders 2.0.0 → 2.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC } from 'react';
3
3
  import * as _orderly_network_types from '@orderly.network/types';
4
- import { OrderStatus } from '@orderly.network/types';
4
+ import { OrderStatus, API, OrderSide } from '@orderly.network/types';
5
+ import { PaginationMeta } from '@orderly.network/ui';
5
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
7
 
7
8
  declare enum TabType {
@@ -15,21 +16,35 @@ declare enum TabType {
15
16
  }
16
17
  declare const OrdersWidget: FC<{
17
18
  current?: TabType;
19
+ pnlNotionalDecimalPrecision?: number;
18
20
  }>;
19
21
 
20
22
  declare const useOrdersScript: (props: {
21
23
  current?: TabType;
24
+ pnlNotionalDecimalPrecision?: number;
22
25
  }) => {
23
26
  current: TabType | undefined;
27
+ pnlNotionalDecimalPrecision: number | undefined;
24
28
  };
25
29
  type OrdersBuilderState$1 = ReturnType<typeof useOrdersScript>;
26
30
 
27
31
  declare const useOrderListScript: (props: {
28
32
  type: TabType;
29
- ordersStatus?: OrderStatus;
33
+ ordersStatus?: OrderStatus | undefined;
34
+ symbol?: string | undefined;
35
+ enableLoadMore?: boolean | undefined;
36
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
37
+ filterConfig?: {
38
+ side?: OrderSide | "all" | undefined;
39
+ range?: {
40
+ from?: Date | undefined;
41
+ to?: Date | undefined;
42
+ } | undefined;
43
+ } | undefined;
44
+ pnlNotionalDecimalPrecision?: number | undefined;
30
45
  }) => {
31
46
  type: TabType;
32
- dataSource: any[] | null;
47
+ dataSource: any[] | undefined;
33
48
  isLoading: boolean;
34
49
  loadMore: () => void;
35
50
  cancelOrder: (orderId: number, symbol?: string | undefined) => Promise<any>;
@@ -39,26 +54,63 @@ declare const useOrderListScript: (props: {
39
54
  page: number;
40
55
  pageSize: number;
41
56
  setPage: react.Dispatch<react.SetStateAction<number>>;
42
- setPageSize: (pageSize: number) => void;
57
+ setPageSize: (size: number) => void;
43
58
  meta: {
44
59
  count: number;
45
60
  page: number;
46
61
  pageSize: number;
47
62
  pageTotal: number;
48
63
  };
64
+ pagination: PaginationMeta;
65
+ manualPagination: boolean;
66
+ pnlNotionalDecimalPrecision: number | undefined;
49
67
  onFilter: (filter: {
50
68
  name: string;
51
69
  value: any;
52
70
  }) => void;
53
71
  filterItems: any[];
72
+ onCancelAll: () => void;
73
+ onSymbolChange: ((symbol: API.Symbol) => void) | undefined;
54
74
  };
55
75
  type OrdersBuilderState = ReturnType<typeof useOrderListScript>;
56
76
 
57
- declare const OrderList: FC<OrdersBuilderState>;
77
+ declare const DesktopOrderList: FC<OrdersBuilderState>;
78
+ declare const MobileOrderList: FC<OrdersBuilderState & {
79
+ classNames?: {
80
+ root?: string;
81
+ cell?: string;
82
+ content?: string;
83
+ };
84
+ showFilter?: boolean;
85
+ }>;
58
86
 
59
- declare const OrderListWidget: (props: {
87
+ declare const DesktopOrderListWidget: (props: {
88
+ type: TabType;
89
+ ordersStatus?: OrderStatus | undefined;
90
+ /** if has value, will be fetch current symbol orders*/
91
+ symbol?: string | undefined;
92
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
93
+ pnlNotionalDecimalPrecision?: number | undefined;
94
+ }) => react_jsx_runtime.JSX.Element;
95
+ declare const MobileOrderListWidget: (props: {
60
96
  type: TabType;
61
- ordersStatus?: OrderStatus;
97
+ ordersStatus?: OrderStatus | undefined;
98
+ /** if has value, will be fetch current symbol orders*/
99
+ symbol?: string | undefined;
100
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
101
+ classNames?: {
102
+ root?: string | undefined;
103
+ cell?: string | undefined;
104
+ content?: string | undefined;
105
+ } | undefined;
106
+ showFilter?: boolean | undefined;
107
+ filterConfig?: {
108
+ side?: OrderSide | "all" | undefined;
109
+ range?: {
110
+ from?: Date | undefined;
111
+ to?: Date | undefined;
112
+ } | undefined;
113
+ } | undefined;
62
114
  }) => react_jsx_runtime.JSX.Element;
63
115
 
64
- export { OrderList, OrderListWidget, type OrdersBuilderState$1 as OrdersBuilderState, OrdersWidget, TabType, useOrderListScript, useOrdersScript };
116
+ export { DesktopOrderList, DesktopOrderListWidget, MobileOrderList, MobileOrderListWidget, type OrdersBuilderState$1 as OrdersBuilderState, OrdersWidget, TabType, useOrderListScript, useOrdersScript };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { FC } from 'react';
3
3
  import * as _orderly_network_types from '@orderly.network/types';
4
- import { OrderStatus } from '@orderly.network/types';
4
+ import { OrderStatus, API, OrderSide } from '@orderly.network/types';
5
+ import { PaginationMeta } from '@orderly.network/ui';
5
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
7
 
7
8
  declare enum TabType {
@@ -15,21 +16,35 @@ declare enum TabType {
15
16
  }
16
17
  declare const OrdersWidget: FC<{
17
18
  current?: TabType;
19
+ pnlNotionalDecimalPrecision?: number;
18
20
  }>;
19
21
 
20
22
  declare const useOrdersScript: (props: {
21
23
  current?: TabType;
24
+ pnlNotionalDecimalPrecision?: number;
22
25
  }) => {
23
26
  current: TabType | undefined;
27
+ pnlNotionalDecimalPrecision: number | undefined;
24
28
  };
25
29
  type OrdersBuilderState$1 = ReturnType<typeof useOrdersScript>;
26
30
 
27
31
  declare const useOrderListScript: (props: {
28
32
  type: TabType;
29
- ordersStatus?: OrderStatus;
33
+ ordersStatus?: OrderStatus | undefined;
34
+ symbol?: string | undefined;
35
+ enableLoadMore?: boolean | undefined;
36
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
37
+ filterConfig?: {
38
+ side?: OrderSide | "all" | undefined;
39
+ range?: {
40
+ from?: Date | undefined;
41
+ to?: Date | undefined;
42
+ } | undefined;
43
+ } | undefined;
44
+ pnlNotionalDecimalPrecision?: number | undefined;
30
45
  }) => {
31
46
  type: TabType;
32
- dataSource: any[] | null;
47
+ dataSource: any[] | undefined;
33
48
  isLoading: boolean;
34
49
  loadMore: () => void;
35
50
  cancelOrder: (orderId: number, symbol?: string | undefined) => Promise<any>;
@@ -39,26 +54,63 @@ declare const useOrderListScript: (props: {
39
54
  page: number;
40
55
  pageSize: number;
41
56
  setPage: react.Dispatch<react.SetStateAction<number>>;
42
- setPageSize: (pageSize: number) => void;
57
+ setPageSize: (size: number) => void;
43
58
  meta: {
44
59
  count: number;
45
60
  page: number;
46
61
  pageSize: number;
47
62
  pageTotal: number;
48
63
  };
64
+ pagination: PaginationMeta;
65
+ manualPagination: boolean;
66
+ pnlNotionalDecimalPrecision: number | undefined;
49
67
  onFilter: (filter: {
50
68
  name: string;
51
69
  value: any;
52
70
  }) => void;
53
71
  filterItems: any[];
72
+ onCancelAll: () => void;
73
+ onSymbolChange: ((symbol: API.Symbol) => void) | undefined;
54
74
  };
55
75
  type OrdersBuilderState = ReturnType<typeof useOrderListScript>;
56
76
 
57
- declare const OrderList: FC<OrdersBuilderState>;
77
+ declare const DesktopOrderList: FC<OrdersBuilderState>;
78
+ declare const MobileOrderList: FC<OrdersBuilderState & {
79
+ classNames?: {
80
+ root?: string;
81
+ cell?: string;
82
+ content?: string;
83
+ };
84
+ showFilter?: boolean;
85
+ }>;
58
86
 
59
- declare const OrderListWidget: (props: {
87
+ declare const DesktopOrderListWidget: (props: {
88
+ type: TabType;
89
+ ordersStatus?: OrderStatus | undefined;
90
+ /** if has value, will be fetch current symbol orders*/
91
+ symbol?: string | undefined;
92
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
93
+ pnlNotionalDecimalPrecision?: number | undefined;
94
+ }) => react_jsx_runtime.JSX.Element;
95
+ declare const MobileOrderListWidget: (props: {
60
96
  type: TabType;
61
- ordersStatus?: OrderStatus;
97
+ ordersStatus?: OrderStatus | undefined;
98
+ /** if has value, will be fetch current symbol orders*/
99
+ symbol?: string | undefined;
100
+ onSymbolChange?: ((symbol: API.Symbol) => void) | undefined;
101
+ classNames?: {
102
+ root?: string | undefined;
103
+ cell?: string | undefined;
104
+ content?: string | undefined;
105
+ } | undefined;
106
+ showFilter?: boolean | undefined;
107
+ filterConfig?: {
108
+ side?: OrderSide | "all" | undefined;
109
+ range?: {
110
+ from?: Date | undefined;
111
+ to?: Date | undefined;
112
+ } | undefined;
113
+ } | undefined;
62
114
  }) => react_jsx_runtime.JSX.Element;
63
115
 
64
- export { OrderList, OrderListWidget, type OrdersBuilderState$1 as OrdersBuilderState, OrdersWidget, TabType, useOrderListScript, useOrdersScript };
116
+ export { DesktopOrderList, DesktopOrderListWidget, MobileOrderList, MobileOrderListWidget, type OrdersBuilderState$1 as OrdersBuilderState, OrdersWidget, TabType, useOrderListScript, useOrdersScript };
package/dist/index.js CHANGED
@@ -3,19 +3,23 @@
3
3
  var ui = require('@orderly.network/ui');
4
4
  var types = require('@orderly.network/types');
5
5
  var uiConnector = require('@orderly.network/ui-connector');
6
- var utils = require('@orderly.network/utils');
7
- var react = require('react');
8
6
  var hooks = require('@orderly.network/hooks');
7
+ var react = require('react');
9
8
  var jsxRuntime = require('react/jsx-runtime');
10
- require('date-fns');
9
+ var utils = require('@orderly.network/utils');
10
+ var uiTpsl = require('@orderly.network/ui-tpsl');
11
+ var reactApp = require('@orderly.network/react-app');
12
+ var dateFns = require('date-fns');
11
13
 
12
- var ye=e=>{let{current:t}=e;return {current:t}};var be=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function Fe(e){if(typeof e.type<"u")return typeof e.type=="string"?[e.type.replace("_ORDER","").toLowerCase()]:[e.type];if(typeof e.algo_type<"u"){let t=new Array;e.algo_type==="POSITIONAL_TP_SL"&&t.push("Position");let r=e.child_orders.find(i=>i.algo_type==="TAKE_PROFIT"&&!!i.trigger_price),o=e.child_orders.find(i=>i.algo_type==="STOP_LOSS"&&!!i.trigger_price);return (r||o)&&t.push(r&&o?"TP/SL":r?"TP":"SL"),t}}function I(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}var A=react.createContext({}),Re=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:i}=e,n=hooks.useSymbolsInfo(),u=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),a=react.useCallback(async(l,c)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:!1;await ui.modal.sheet({title:"Edit Order",contentClassName:"orderly-edit-order-sheet-content",content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[]),d=react.useCallback((l,c,m)=>{let{min_notional:g}=n[l]();return hooks.checkNotional(c,m,g)},[n]);return jsxRuntime.jsx(A.Provider,{value:{onCancelOrder:u,onEditOrder:a,editOrder:r,editAlgoOrder:i,checkMinNotional:d},children:e.children})};var Me=react.createContext({}),le=()=>react.useContext(Me),Be=e=>{let[t,r]=react.useState(),[o]=hooks.useMutation("/v1/algo/order","DELETE"),[i]=hooks.useMutation("/v1/algo/order","PUT"),n=hooks.useSWRConfig(),{state:u}=hooks.useAccount(),a=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",u.accountId]),[u.accountId]),d=async f=>o(null,{order_id:f.algo_order_id,symbol:f.symbol}),l=async(f,w)=>i({order_id:f.algo_order_id,child_orders:f.child_orders.map(C=>({order_id:C.algo_order_id,quantity:w.order_quantity}))}),c=f=>n.cache.get(a)?.data.rows.find(C=>C.symbol===f),{sl_trigger_price:m,tp_trigger_price:g}=react.useMemo(()=>!("algo_type"in e.order)||!Array.isArray(e.order.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order),[e.order]);return react.useEffect(()=>{if("algo_type"in e.order){let f=c(e.order.symbol);f&&r(f);}},[e.order.symbol]),jsxRuntime.jsx(Me.Provider,{value:{order:e.order,sl_trigger_price:m,tp_trigger_price:g,onCancelOrder:d,onUpdateOrder:l,getRelatedPosition:c,position:t},children:e.children})};var $e=react.createContext({}),W=()=>react.useContext($e),ze=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx($e.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol},children:e.children})};var Q=e=>{let{type:t,base:r,value:o,cancelPopover:i,isSubmitting:n,onConfirm:u}=e,a=react.useMemo(()=>{switch(t){case 0:return `You agree changing the quantity of ${r}-PERP order to `;case 1:return `You agree changing the price of ${r}-PERP order to `;case 2:return `You agree changing the trigger price of ${r}-PERP order to `}},[t]);return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:[a,jsxRuntime.jsx("span",{className:"oui-text-warning",children:utils.commify(o)}),"."]}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",onClick:i,disabled:n,children:"Cancel"}),jsxRuntime.jsx(ui.Button,{loading:n,onClick:u,children:"Confirm"})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:i,children:jsxRuntime.jsx(ui.CloseIcon,{size:18})})]})};var Y=e=>{let{inputRef:t,dp:r,value:o,setPrice:i,setEditting:n,error:u,handleKeyDown:a,onClick:d,onClose:l,hintInfo:c}=e;return react.useEffect(()=>{let m=t.current;if(m){let g=m.value.length;m.setSelectionRange(g,g);}n(!0);},[]),jsxRuntime.jsx(ui.Tooltip,{content:c,open:(c?.length||0)>0,children:jsxRuntime.jsx(ui.Input,{ref:t,type:"text",size:"sm",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(r)],value:o,onValueChange:m=>i(m),helpText:u,onClick:m=>{m.stopPropagation(),m.preventDefault();},onKeyDown:a,autoFocus:!0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsxRuntime.jsx("button",{onClick:d,children:jsxRuntime.jsx(ui.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Oe=e=>{let{order:t}=e,[r,o]=react.useState(t.quantity.toString()),[i,n]=react.useState(!1);react.useEffect(()=>{O(t.quantity.toString());},[e.order.quantity]);let[u,a]=react.useState(!1),[d,l]=react.useState(),{editOrder:c,editAlgoOrder:m,checkMinNotional:g}=react.useContext(A),{onUpdateOrder:f,position:w}=le(),{base_dp:C,base:E}=W(),O=s=>{o(s);let P=Math.abs(w?.position_qty||0);w&&Number(s)>P?l(`Quantity should be less than position quantity : ${P}`):l(void 0);},x=()=>{a(!1),n(!1);},S=()=>{a(!1),O(t.quantity.toString()),n(!1);},[D,N]=react.useState(!1),M=react.useRef(null),T=()=>{if(d)return;if(Number(r)===Number(t.quantity)){n(!1);return}let s=t.algo_order_id!==void 0?t.trigger_price:t.price;if(s!==null&&t.reduce_only!==!0){let P=g(t.symbol,s,r);if(P){ui.toast.error(P),N(!1),S();return}}a(!0);},b=s=>{s?.stopPropagation(),s?.preventDefault(),T();},v=s=>{s.key==="Enter"&&(s?.stopPropagation(),s?.preventDefault(),T());},ae=react.useCallback(()=>{N(!0);let s={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:r,algo_order_id:t.algo_order_id};if(typeof s.algo_order_id<"u"&&s.order_type==="MARKET"){let{order_price:U,...Pt}=s;s=Pt;}typeof t.reduce_only<"u"&&(s.reduce_only=t.reduce_only),t.order_tag!==void 0&&(s={...s,order_tag:t.order_tag}),t?.visible_quantity===0&&(s.visible_quantity=0),t?.tag!==void 0&&(s.order_tag=t.tag);let P;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?P=f(t,s):t.algo_order_id!==void 0?P=m(t.algo_order_id.toString(),s):P=c(t.order_id.toString(),s),P.then(U=>{x(),O(r.toString());},U=>{ui.toast.error(U.message),O(t.quantity.toString()),S();}).finally(()=>N(!1));},[r]),se=react.useRef(null),de=s=>{se.current&&!se.current.contains(s.target)&&!u&&S();};react.useEffect(()=>(document.addEventListener("mousedown",de),()=>{document.removeEventListener("mousedown",de);}),[u]);let _=()=>!i||e.disableEdit?jsxRuntime.jsx(Gt,{order:t,quantity:r,setEditing:n,disableEdit:e.disableEdit}):jsxRuntime.jsx(Y,{inputRef:M,dp:C,value:r,setPrice:O,setEditting:n,handleKeyDown:v,onClick:b,onClose:S});return jsxRuntime.jsx(ui.Popover,{open:u,onOpenChange:a,content:jsxRuntime.jsx(Q,{type:0,base:E,value:r,cancelPopover:S,isSubmitting:D,onConfirm:ae}),children:jsxRuntime.jsx("div",{ref:se,children:_()})})},Gt=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",I(t)&&"oui-text-base-conrast-20"),onClick:i=>{i.stopPropagation(),i.preventDefault(),e.setEditing(!0);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})};var ot=e=>{let{order:t}=e,[r,o]=react.useState(t.price?.toString()??"Market"),[i,n]=react.useState(!1),[u,a]=react.useState(!1),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[c,m]=react.useState(!1),{editOrder:g,editAlgoOrder:f,checkMinNotional:w}=react.useContext(A),{base:C,quote_dp:E}=W(),O=()=>{n(!1),a(!1);},x=()=>{n(!1),o(t.price?.toString()??"Market"),a(!1);},S=_=>{if(_?.stopPropagation(),_?.preventDefault(),r===`${t.price}`){a(!1);return}if(t.reduce_only!==!0){let s=w(t.symbol,r,t.quantity);if(s){ui.toast.error(s),m(!1),x();return}}n(!0);},D=_=>{_.key==="Enter"&&S(_);},N=()=>{m(!0);let _=t.order_id,s={order_price:r,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(s.reduce_only=t.reduce_only),t.order_tag!==void 0&&(s={...s,order_tag:t.order_tag}),d&&(_=t.algo_order_id,s={...s,order_id:_,price:r,algo_order_id:_}),t?.visible_quantity===0&&(s.visible_quantity=0),t.tag!==void 0&&(s.order_tag=t.tag);let P;t.algo_order_id!==void 0?P=f(t.algo_order_id.toString(),s):P=g(t.order_id.toString(),s),P.then(U=>{O(),o(r);},U=>{ui.toast.error(U.message),o(t.price.toString()),x();}).finally(()=>m(!1));},M=react.useRef(null),T=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),b=react.useMemo(()=>!T||l||!u?"":Number(r)>T.max?`Price can not be greater than ${T.max} USDC.`:Number(r)<T.min?`Price can not be less than ${T.min} USDC.`:"",[l,u,T,r]);react.useEffect(()=>{e.order.price&&o(`${e.order.price}`);},[e.order.price]);let v=react.useRef(null),ae=_=>{v.current&&!v.current.contains(_.target)&&!i&&x();};if(react.useEffect(()=>(document.addEventListener("mousedown",ae),()=>{document.removeEventListener("mousedown",ae);}),[i]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let de=()=>!u||e.disableEdit?jsxRuntime.jsx(or,{order:t,price:r,setEditing:a,disableEdit:e.disableEdit}):jsxRuntime.jsx(Y,{inputRef:M,dp:E,value:r,setPrice:o,setEditting:a,handleKeyDown:D,onClick:S,onClose:x,hintInfo:b});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:n,content:jsxRuntime.jsx(Q,{type:1,base:C,value:r,cancelPopover:x,isSubmitting:c,onConfirm:N}),children:jsxRuntime.jsx("div",{ref:v,children:de()})})},or=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",I(t)&&"oui-text-base-conrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var lt=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let i=t?.algo_order_id!==void 0,[n,u]=react.useState(!1),[a,d]=react.useState(!1),[l,c]=react.useState(!1),{editAlgoOrder:m,checkMinNotional:g}=react.useContext(A),{base:f,quote_dp:w}=W(),C=()=>{u(!1),d(!1);},E=()=>{o(t.trigger_price?.toString()??"0"),u(!1),d(!1);},O=react.useRef(null),x=b=>{O.current&&!O.current.contains(b.target)&&!n&&E();};react.useEffect(()=>(document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x);}),[n]);let S=b=>{if(b?.stopPropagation(),b?.preventDefault(),d(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let v=g(t.symbol,t.price,t.quantity);if(v){ui.toast.error(v),c(!1),E();return}}u(!0);}},D=b=>{b.key==="Enter"&&S(b);},N=()=>{c(!0);let b={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(b={...b,order_tag:t.order_tag}),m(`${t.algo_order_id}`,b).then(v=>{C(),o(r);},v=>{ui.toast.error(v.message),o(t.trigger_price?.toString()??"--"),E();}).finally(()=>c(!1));},M=react.useRef(null);if(!i)return jsxRuntime.jsx(ui.Text,{children:"--"});let T=()=>!a||e.disableEdit?jsxRuntime.jsx(sr,{order:t,price:r,setEditing:d,disableEdit:e.disableEdit}):jsxRuntime.jsx(Y,{inputRef:M,dp:w,value:r,setPrice:o,setEditting:d,handleKeyDown:D,onClick:S,onClose:E});return jsxRuntime.jsx(ui.Popover,{open:n,onOpenChange:u,content:jsxRuntime.jsx(Q,{type:2,base:f,value:r,cancelPopover:E,isSubmitting:l,onConfirm:N}),children:jsxRuntime.jsx("div",{ref:O,children:T()})})},sr=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",I(t)&&"oui-text-base-conrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var Se=e=>{let{order:t}=e,{onCancelOrder:r}=react.useContext(A),[o,i]=react.useState(!1);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",onClick:n=>{r&&(n.preventDefault(),n.stopPropagation(),i(!0),r(t).then(u=>u,u=>{ui.toast.error(u.message);}).finally(()=>{i(!1);}));},loading:o,children:"Cancel"})};var ut=e=>{let{record:t}=e,[r,o]=react.useState(!1),[i,{data:n,error:u,reset:a,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),c=react.useCallback(()=>{o(!1);let m={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(m.visible_quantity=0),typeof t.reduce_only<"u"&&(m.reduce_only=t.reduce_only),i(m);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:m=>{d||(m.preventDefault(),m.stopPropagation(),c());},children:"Renew"})};var pt=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=le();return jsxRuntime.jsx(_r,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},_r=e=>{let{direction:t="row",order:r,position:o}=e,i=hooks.useSymbolsInfo(),n=react.useMemo(()=>{let d=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&d.push(jsxRuntime.jsx(mt,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:i[r.symbol]()},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(mt,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:i[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:d})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),u=react.useMemo(()=>{let d=[];return r?.symbol?(e.takeProfitPrice&&d.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20"),rule:"price",precision:i[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"TP\xA0-\xA0"}):""},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 "),rule:"price",precision:i[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"SL\xA0-\xA0"}):""},"sl")),d.length===0?jsxRuntime.jsx("span",{children:"-"}):(d.length===2&&t==="row"&&d.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),d)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol]),a=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:u});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:n,children:a}):a},mt=e=>{let{qty:t,price:r,entryPrice:o,orderSide:i,orderType:n,symbolInfo:u}=e,a=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:i,orderType:n},{symbol:u}),d=n===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL";return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:`${d} PnL:`}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",className:a===0?"oui-text-base-contrast-36":a>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:a===0?"":a>0?"+":"-"}),surfix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(a)}`})]})};var gt=e=>(()=>{switch(e){case"all":return [B({width:130,showType:!0}),$({width:130}),G({width:130,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),z({width:130,title:"Order price",disableEdit:!0}),pe({width:130}),ft({width:130}),J({width:130}),oe({width:130}),ie({width:130}),K({width:130}),V({width:130}),Ce({width:130})];case"pending":return [B({width:162,showType:!0}),$({width:162}),G({width:162,className:"oui-pr-0"}),z({width:162,className:"oui-pr-0"}),te({width:162,className:"oui-pr-0"}),J({width:162}),K({width:162}),V({width:162}),re({width:162}),Ce({width:162})];case"tp_sl":return [B({width:176,showType:!0}),$({width:176}),kr({width:176}),ft({width:176}),z({width:176,disableEdit:!0}),qr({width:176}),K({width:176}),re({width:176}),Dr({width:176})];case"filled":return [B({width:124}),Fr({width:124}),$({width:124}),G({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),z({width:124,title:"Order price",disableEdit:!0}),Rr({width:124}),te({width:124,disableEdit:!0}),J({width:124}),oe({width:124}),ie({width:124}),K({width:124}),V({width:124}),re({width:124})];case"cancelled":return [B({showType:!0,width:124}),$({width:124}),G({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),z({width:124,disableEdit:!0}),pe({width:124}),te({width:124,disableEdit:!0}),J({width:124}),oe({width:124}),ie({width:124}),K({width:124}),V({width:124})];case"rejected":return [B({showType:!0,width:124}),$({width:124}),G({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),z({width:124,disableEdit:!0}),pe({width:124}),te({width:124,disableEdit:!0}),J({width:124}),oe({width:124}),ie({width:124}),K({width:124}),V({width:124}),re({width:124})];case"orderHistory":return [B({showType:!0,width:124}),$({width:124}),G({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),z({width:124,disableEdit:!0}),pe({width:124}),te({width:124,disableEdit:!0}),J({width:124}),oe({width:124}),ie({width:124}),K({width:124}),V({width:124}),re({width:124}),Ce({width:124})]}})();function B(e){return {title:"Instrument",dataIndex:"symbol",className:"oui-h-[48px]",width:e?.width,onSort:e?.enableSort?(t,r,o)=>o==="asc"?t.symbol.localeCompare(r.symbol):r.symbol.localeCompare(t.symbol):void 0,render:(t,r)=>{typeof r.type=="string"?r.type.replace("_ORDER","").toLowerCase():r.type;let i=I(r);return jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",size:"xs",className:" oui-text-xs",onClick:n=>{n.stopPropagation(),n.preventDefault();},children:t}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:Fe(r)?.map(n=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?i?"neutural":"primary":"neutural",size:"xs",children:n}))})]})}}}function $(e){return {title:"Side",dataIndex:"side",width:e?.width,className:"oui-h-[48px]",onSort:e?.enableSort?(t,r,o)=>o==="asc"?r.side.localeCompare(t.side):t.side.localeCompare(r.side):void 0,render:(t,r)=>{let o=I(r)?"oui-text-base-contrast-20":t===types.OrderSide.BUY?"oui-text-trade-profit":"oui-text-trade-loss";return jsxRuntime.jsx("span",{className:ui.cn("oui-font-semibold",o),children:be(t)})}}}function Fr(e){return {title:"Type",dataIndex:"type",width:e?.width,className:e?.className,formatter:(t,r)=>{let o=typeof r.type=="string"?r.type.replace("_ORDER","").toLowerCase():r.type;return r.algo_order_id?`Stop ${o}`:be(t)}}}function G(e){return {title:"Filled / Quantity",dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Oe,{order:r,disableEdit:e?.disableEdit})}}function kr(e){return {title:"Quantity",className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Oe,{order:r})}}function z(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(ot,{order:r,disableEdit:e?.disableEdit})}}function Rr(e){return {title:"Avg. price",dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:utils.commifyOptional(t)})}}function te(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(lt,{order:r,disableEdit:e?.disableEdit})}}function ft(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(pt,{})}}function J(e){return {title:"Est. total",dataIndex:"executed",width:e?.width,className:e?.className,render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,children:r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?"--":`${r.total_executed_quantity*r.average_executed_price}`})}}function K(e){return {title:"Reduce only",dataIndex:"reduce_only",width:e?.width,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text,{children:t?"Yes":"No"})}}function V(e){return {title:"Hidden",dataIndex:"visible",width:e?.width,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?"No":"Yes"})}}function re(e){return {title:"Order time",dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function oe(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function qr(e){return {title:"Notional",dataIndex:"notional",width:e?.width,onSort:e?.enableSort,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function ie(e){return {title:"Status",dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:ui.capitalizeFirstLetter((r?.algo_status||r.status)?.toLocaleLowerCase())})}}function pe(e){return {title:"Avg. open",dataIndex:"average_open_price",width:e?.width,onSort:e?.enableSort,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function Ce(e){return {title:"",dataIndex:"",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===types.OrderStatus.CANCELLED?jsxRuntime.jsx(ut,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(Se,{order:r}):null}}function Dr(e){return {title:"",dataIndex:"",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",children:"Edit"}),jsxRuntime.jsx(Se,{order:r})]})}}var Te=e=>{let t=gt(e.type);return jsxRuntime.jsx(Re,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsx(ui.Flex,{direction:"column",width:"100%",itemAlign:"start",children:jsxRuntime.jsxs(uiConnector.AuthGuardDataTable,{columns:t,loading:e.isLoading,dataSource:e.dataSource,ignoreLoadingCheck:!0,classNames:{root:"oui-items-start"},onRow:(r,o)=>({className:I(r)?"oui-text-base-contrast-20":""}),generatedRowKey:(r,o)=>`${e.type}${o}${r.order_id||r.algo_order_id}_index${o}`,renderRowContainer:(r,o,i)=>(e.type==="tp_sl"&&(i=jsxRuntime.jsx(Be,{order:r,children:i})),jsxRuntime.jsx(ze,{symbol:r.symbol,children:i})),children:[e.filterItems.length>0&&jsxRuntime.jsx(ui.Filter,{items:e.filterItems,onFilter:r=>{e.onFilter(r);}}),jsxRuntime.jsx(ui.Pagination,{...e.meta,onPageChange:e.setPage,onPageSizeChange:e.setPageSize})]})})})};var Ae=e=>{let{ordersStatus:t,type:r}=e,{page:o,pageSize:i,setPage:n,setPageSize:u,parseMeta:a}=ui.usePagination(),{orderStatus:d,ordersSide:l,dateRange:c,filterItems:m,onFilter:g}=Wr(r,{ordersStatus:t,setPage:n}),f=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),w=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),[C,{isLoading:E,loadMore:O,cancelOrder:x,updateOrder:S,cancelAlgoOrder:D,updateAlgoOrder:N,meta:M}]=hooks.useOrderStream({status:d,side:l,page:o,size:i,dateRange:c,includes:f,excludes:w});return {type:r,dataSource:C,isLoading:E,loadMore:O,cancelOrder:x,updateOrder:S,cancelAlgoOrder:D,updateAlgoOrder:N,page:o,pageSize:i,setPage:n,setPageSize:u,meta:a(M),onFilter:g,filterItems:m}},Wr=(e,t)=>{let[r,o]=react.useState(t.ordersStatus),[i,n]=react.useState(void 0),[u,a]=react.useState(),d=c=>{c.name==="side"&&(n(c.value),t.setPage(1)),c.name==="status"&&(o(c.value),t.setPage(1)),c.name==="dateRange"&&(a(c.value),t.setPage(1));};return {filterItems:react.useMemo(()=>{let c={type:"select",name:"side",options:[{label:"All sides",value:void 0},{label:"Buy",value:"BUY"},{label:"Sell",value:"SELL"}],value:i},m={type:"range",name:"dateRange",value:u},g={type:"select",name:"status",options:[{label:"All status",value:void 0},{label:"Pending",value:types.OrderStatus.INCOMPLETE},{label:"Canceled",value:types.OrderStatus.CANCELLED},{label:"Rejected",value:types.OrderStatus.REJECTED}],value:r};switch(e){case"all":return [c,g,m];case"pending":return [c];case"tp_sl":return [c];case"filled":return [c];case"cancelled":return [c];case"rejected":return [c];case"orderHistory":return [c]}},[e,i,r,u]),onFilter:d,ordersSide:i,dateRange:u,orderStatus:r}};var q=e=>{let t=Ae(e);return jsxRuntime.jsx(Te,{...t})};var bt=e=>jsxRuntime.jsxs(ui.Tabs,{defaultValue:e.current||"all",variant:"contained",children:[jsxRuntime.jsx(ui.TabPanel,{value:"all",title:"All",children:jsxRuntime.jsx(q,{type:"all"})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(q,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(q,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(q,{type:"filled",ordersStatus:types.OrderStatus.FILLED})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(q,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(q,{type:"rejected",ordersStatus:types.OrderStatus.REJECTED})}),jsxRuntime.jsx(ui.TabPanel,{value:"orderHistory",title:"Order history",children:jsxRuntime.jsx(q,{type:"orderHistory"})})]});var X=(a=>(a.all="all",a.pending="pending",a.tp_sl="tp_sl",a.filled="filled",a.cancelled="cancelled",a.rejected="rejected",a.orderHistory="orderHistory",a))(X||{}),Jr=e=>{let t=ye(e);return jsxRuntime.jsx(bt,{...t})};
14
+ var ct=e=>{let{current:t,pnlNotionalDecimalPrecision:r}=e;return {current:t,pnlNotionalDecimalPrecision:r}};var Z=e=>e===void 0||e.length===0?e:e.length===1?e.charAt(0).toUpperCase():e.charAt(0).toUpperCase()+e.toLowerCase().slice(1);function de(e){if(typeof e.type<"u"){let t=new Array;if(e.parent_algo_type){if(e.algo_type===types.AlgoOrderType.STOP_LOSS){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","SL"]:["SL"];t.push(...i);}if(e.algo_type===types.AlgoOrderType.TAKE_PROFIT){let i=e.type===types.OrderType.CLOSE_POSITION?["Position","TP"]:["TP"];t.push(...i);}return t}(typeof e.type=="string"?[e.type.replace("_ORDER","").toLowerCase()]:[e.type]).map(i=>Z(i));let o=typeof e.type=="string"?e.type.replace("_ORDER","").toLowerCase():Z(e.type);return e.algo_order_id===void 0||e.algo_order_id&&e.algo_type==="BRACKET"?[Z(o)]:[`Stop ${o}`]}if(typeof e.algo_type<"u"){let t=new Array;e.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL&&t.push("Position");let r=e?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT&&!!i.trigger_price),o=e?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS&&!!i.trigger_price);return (r||o)&&t.push(r&&o?"TP/SL":r?"TP":"SL"),t}}function j(e){return e.status===types.OrderStatus.CANCELLED||e.algo_status===types.OrderStatus.CANCELLED}function Do(e){if(e.algo_type!==types.AlgoOrderRootType.BRACKET)return {tpOrder:void 0,slOrder:void 0};let t=e.child_orders?.[0];if(!t)return {tpOrder:void 0,slOrder:void 0};let r=t?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.TAKE_PROFIT),o=t?.child_orders?.find(i=>i.algo_type===types.AlgoOrderType.STOP_LOSS);return {tpOrder:r,slOrder:o}}function Ge(e){let t={pnl:{tpPnL:void 0,slPnL:void 0},roi:{tpRoi:void 0,slRoi:void 0}},{tpOrder:r,slOrder:o}=Do(e);if(!r&&!o||typeof e.price===void 0||!e.price)return t;let i=e.side===types.OrderSide.BUY?e.quantity:e.quantity*-1,n=r?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:r?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:r.algo_type}),a=o?.trigger_price&&hooks.utils.priceToPnl({qty:i,price:o?.trigger_price,entryPrice:e.price,orderSide:e.side,orderType:o.algo_type}),s=n?hooks.utils.calcTPSL_ROI({pnl:n,qty:e.quantity,price:e.price}):void 0,d=a?hooks.utils.calcTPSL_ROI({pnl:a,qty:e.quantity,price:e.price}):void 0;return {pnl:{tpPnL:n,slPnL:a},roi:{tpRoi:s,slRoi:d}}}var cr=react.createContext({}),B=()=>react.useContext(cr),mt=e=>{let t=hooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(cr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),base_tick:t("base_tick"),quote_tick:t("quote_tick"),base:t("base"),quote:t("quote"),symbol:e.symbol,origin:t(),quote_max:t("quote_max"),quote_min:t("quote_min")},children:e.children})};var pr=react.createContext({}),H=()=>react.useContext(pr),gt=e=>{let{cancelOrder:t,editOrder:r,cancelAlgoOrder:o,editAlgoOrder:i}=e,n=hooks.useSymbolsInfo(),a=react.useCallback(async l=>l.algo_order_id!==void 0?"root_algo_order_id"in l&&l.root_algo_order_id!==l.algo_order_id?o(l.root_algo_order_id,l.symbol):o(l.algo_order_id,l.symbol).then(()=>{}):t(l.order_id,l.symbol).then(()=>{}),[]),s=react.useCallback(async(l,g)=>{l.visible_quantity!==void 0?l.visible_quantity===0:l.visible!==void 0?l.visible===0:!1;await ui.modal.sheet({title:"Edit Order",classNames:{content:"oui-edit-order-sheet-content"},content:jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Content"})});},[]),d=react.useCallback((l,g,u)=>{let{min_notional:O}=n[l]();return hooks.checkNotional(g,u,O)},[n]);return jsxRuntime.jsx(pr.Provider,{value:{onCancelOrder:a,onEditOrder:s,editOrder:r,editAlgoOrder:i,checkMinNotional:d},children:e.children})};var yr=react.createContext({}),z=()=>react.useContext(yr),yt=e=>{let{quote_dp:t}=B(),[r,o]=react.useState(),[i]=hooks.useMutation("/v1/algo/order","DELETE"),[n]=hooks.useMutation("/v1/algo/order","PUT"),a=hooks.useSWRConfig(),{state:s}=hooks.useAccount(),d=react.useMemo(()=>hooks.unstable_serialize(()=>["/v1/positions",s.accountId]),[s.accountId]),l=async _=>i(null,{order_id:_.algo_order_id,symbol:_.symbol}),g=async(_,v)=>n({order_id:_.algo_order_id,child_orders:_.child_orders.map(A=>({order_id:A.algo_order_id,quantity:v.order_quantity}))}),u=_=>a.cache.get(d)?.data.rows.find(A=>A.symbol===_),{sl_trigger_price:O,tp_trigger_price:w,tpPnL:h,slPnL:I}=Zo({order:e.order,position:r,quote_dp:t});return react.useEffect(()=>{if("algo_type"in e.order||(e.order?.reduce_only??!1)){let _=u(e.order.symbol);_&&o(_);}},[e.order.symbol]),jsxRuntime.jsx(yr.Provider,{value:{order:e.order,sl_trigger_price:O,tp_trigger_price:w,tpPnL:h,slPnL:I,onCancelOrder:l,onUpdateOrder:g,getRelatedPosition:u,position:r},children:e.children})};function Zo(e){let{order:t,position:r,quote_dp:o}=e;if(!r)return {sl_trigger_price:void 0,tp_trigger_price:void 0,slPnL:void 0,tpPnL:void 0};let{sl_trigger_price:i,tp_trigger_price:n}=!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t),a=t.quantity;a===0&&t.child_orders?.[0].type==="CLOSE_POSITION"&&(a=r.position_qty);let s=r.average_open_price,d=typeof a=="number"&&typeof n=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:n,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.TAKE_PROFIT},{symbol:{quote_dp:o}}):void 0,l=typeof a=="number"&&typeof i=="number"&&typeof s=="number"?hooks.utils.priceToPnl({qty:a,price:i,entryPrice:r.average_open_price,orderSide:t.side,orderType:types.AlgoOrderType.STOP_LOSS},{symbol:{quote_dp:o}}):void 0;return {sl_trigger_price:i,tp_trigger_price:n,slPnL:l,tpPnL:d}}var Ne=e=>{let{type:t,base:r,value:o,cancelPopover:i,isSubmitting:n,onConfirm:a}=e,s=react.useMemo(()=>{switch(t){case 0:return `You agree changing the quantity of ${r}-PERP order to `;case 1:return `You agree changing the price of ${r}-PERP order to `;case 2:return `You agree changing the trigger price of ${r}-PERP order to `}},[t]);return jsxRuntime.jsxs("div",{className:"oui-pt-5 oui-relative",children:[jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54 oui-text-2xs desktop:oui-text-sm",children:[s,jsxRuntime.jsx("span",{className:"oui-text-warning-darken",children:utils.commify(o)}),"."]}),jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-gap-2 oui-mt-5",children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:i,disabled:n,children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{size:"md",loading:n,onClick:a,children:"Confirm"})]}),jsxRuntime.jsx("button",{className:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-54",onClick:i,children:jsxRuntime.jsx(ui.CloseIcon,{size:18})})]})};var we=e=>{let{inputRef:t,dp:r,value:o,setValue:i,setEditing:n,error:a,handleKeyDown:s,onClick:d,onClose:l,onFocus:g,onBlur:u,hintInfo:O}=e;react.useEffect(()=>{let h=t.current;if(h){let I=h.value.length;h.setSelectionRange(I,I);}n(!0);},[]);let w=(O?.length||0)>0;return jsxRuntime.jsx(ui.Tooltip,{content:O,open:w,children:jsxRuntime.jsx(ui.Input,{ref:t,type:"text",size:"sm",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(r),ui.inputFormatter.currencyFormatter],value:o,onValueChange:h=>i(h),helpText:a,onClick:h=>{h.stopPropagation(),h.preventDefault();},autoComplete:"off",onFocus:g,onBlur:u,onKeyDown:s,autoFocus:!0,color:w?"danger":void 0,classNames:{root:"oui-bg-base-700 oui-px-2 oui-py-1 oui-rounded",input:"oui-pr-2"},suffix:jsxRuntime.jsx("button",{onClick:d,children:jsxRuntime.jsx(ui.CheckIcon,{size:18,color:"white",opacity:1,className:"oui-cursor-pointer oui-opacity-50 hover:oui-opacity-100"})})})})};var Pt=e=>{let{order:t,otherOrderQuantity:r}=e,{reduce_only:o}=t,[i,n]=react.useState(t.quantity.toString()),[a,s]=react.useState(!1);react.useEffect(()=>{x(t.quantity.toString());},[e.order.quantity]);let[d,l]=react.useState(!1),[g,u]=react.useState(),{editOrder:O,editAlgoOrder:w,checkMinNotional:h}=H(),{onUpdateOrder:I,position:_}=z(),{base_dp:v,base:A,base_tick:C}=B(),x=async(m,p)=>{n(m);let k=Math.abs(_?.position_qty||0);if(_&&o&&Number(m)>k)u(`Quantity should be less than position quantity : ${k}`);else {let ie=Number(m);p&&ie>p?u(`Quantity should be less than ${utils.commifyOptional(p,{fix:v})}`):u(void 0);}return Promise.resolve()},F=()=>{l(!1),s(!1);},D=()=>{l(!1),x(t.quantity.toString()),s(!1);},[K,f]=react.useState(!1),S=react.useRef(null),U=()=>{if(g)return;if(Number(i)===Number(t.quantity)){s(!1);return}let m=t.algo_order_id!==void 0?t.trigger_price:t.price;if(m!==null&&t.reduce_only!==!0){let p=h(t.symbol,m,i);if(p){ui.toast.error(p),f(!1),D();return}}l(!0);},le=m=>{m?.stopPropagation(),m?.preventDefault(),U();},E=m=>{m.key==="Enter"&&(m?.stopPropagation(),m?.preventDefault(),U());},P=react.useCallback(()=>{f(!0);let m={symbol:t.symbol,order_type:t.type,side:t.side,order_price:t.price,order_quantity:i,algo_order_id:t.algo_order_id};if(typeof m.algo_order_id<"u"&&m.order_type==="MARKET"){let{order_price:k,...ie}=m;m=ie;}typeof t.reduce_only<"u"&&(m.reduce_only=t.reduce_only),t.order_tag!==void 0&&(m={...m,order_tag:t.order_tag}),t?.visible_quantity===0&&(m.visible_quantity=0),t?.tag!==void 0&&(m.order_tag=t.tag);let p;"algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?p=I(t,m):t.algo_order_id!==void 0?p=w(t.algo_order_id.toString(),m):p=O(t.order_id.toString(),m),p.then(k=>{F(),x(i.toString());},k=>{ui.toast.error(k.message),x(t.quantity.toString()),D();}).finally(()=>f(!1));},[i]),L=react.useRef(null),J=react.useRef(null),oe=m=>{L.current&&J.current&&!L.current.contains(m.target)&&!J.current.contains(m.target)&&!d&&D();};react.useEffect(()=>(document.addEventListener("mousedown",oe),()=>{document.removeEventListener("mousedown",oe);}),[d,t.quantity]);let Ce=()=>!a||e.disableEdit?jsxRuntime.jsx(Si,{order:t,quantity:i,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(_i,{inputRef:S,quantitySliderRef:J,base_dp:v,base_tick:C,quantity:i,setQuantity:x,editing:a,setEditing:s,handleKeyDown:E,onClick:le,onClose:D,symbol:t.symbol,reduce_only:o,positionQty:_?.position_qty,error:g,confirmOpen:d,side:t.side,order:t,setError:u});return jsxRuntime.jsx(ui.Popover,{open:d,onOpenChange:l,content:jsxRuntime.jsx(Ne,{type:0,base:A,value:i,cancelPopover:D,isSubmitting:K,onConfirm:P}),contentProps:{onOpenAutoFocus:m=>{}},children:jsxRuntime.jsx("div",{onClick:m=>{m.stopPropagation(),m.preventDefault();},ref:L,children:Ce()})})},Si=e=>{let{order:t,quantity:r}=e,o=t.total_executed_quantity;return jsxRuntime.jsxs(ui.Flex,{direction:"row",justify:"start",gap:1,className:ui.cn("oui-max-w-[110px] oui-relative",t.side===types.OrderSide.BUY&&"oui-text-trade-profit",t.side===types.OrderSide.SELL&&"oui-text-trade-loss",j(t)&&"oui-text-base-contrast-20"),onClick:i=>{i.stopPropagation(),i.preventDefault(),e.setEditing(!0);},children:["algo_type"in t&&t.algo_type===types.AlgoOrderRootType.TP_SL?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:o}),jsxRuntime.jsx("span",{children:"/"})]}),jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})]})},_i=e=>{let{inputRef:t,quantitySliderRef:r,base_dp:o,base_tick:i,quantity:n,setQuantity:a,editing:s,setEditing:d,handleKeyDown:l,onClick:g,onClose:u,error:O,symbol:w,reduce_only:h,positionQty:I,confirmOpen:_,side:v,order:A}=e,C=hooks.useMaxQty(w,A.side,A.reduce_only),x=react.useMemo(()=>h?Math.abs(I??0):A.quantity+Math.abs(C),[A.quantity,C,h,I]),[F,D]=react.useState(void 0);react.useEffect(()=>{if(F===void 0){let f=new utils.Decimal(n).div(x).abs().mul(100).toNumber();D(f);}},[F,x,n]);let K=async f=>(i>0&&(f=hooks.utils.formatNumber(f,i)??f),a(`${f}`,x));return jsxRuntime.jsxs(ui.PopoverRoot,{open:!_,children:[jsxRuntime.jsx(ui.PopoverTrigger,{children:jsxRuntime.jsx(we,{inputRef:t,dp:o,value:n,setValue:f=>{let S=Math.abs(Math.min(Number(f),x)).toString();if(a(f,x),f.endsWith("."))return;if(Number(S)===0){D(0);return}let U=new utils.Decimal(f).div(x).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber();D(Math.min(100,U));},setEditing:d,handleKeyDown:l,onClick:g,onClose:u,onBlur:f=>{K(f.target.value);},hintInfo:O})}),jsxRuntime.jsx(ui.PopoverContent,{className:"oui-w-[360px] oui-rounded-xl",align:"start",side:"bottom",onOpenAutoFocus:f=>{f.preventDefault();},children:jsxRuntime.jsxs(ui.Flex,{p:1,gap:2,width:"100%",itemAlign:"start",ref:r,children:[jsxRuntime.jsx(ui.Text.numeral,{size:"xs",intensity:98,className:"oui-min-w-[30px] ",dp:2,padding:!1,unit:"%",rm:utils.Decimal.ROUND_DOWN,children:`${F}`}),jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,className:"oui-mt-[6px]",children:[jsxRuntime.jsx(ui.Slider,{markCount:4,value:[F??0],onValueChange:f=>{let S=Array.from(f.values());D(S[0]);let U=new utils.Decimal(S[0]).div(100).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);a(U,x);},onValueCommit:f=>{let S=new utils.Decimal(f[0]).div(100).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);K(S).finally(()=>{t.current.focus();});}}),jsxRuntime.jsx(Pi,{onClick:f=>{D(f*100);let S=new utils.Decimal(f).mul(x).abs().toFixed(o,utils.Decimal.ROUND_DOWN);S=hooks.utils.formatNumber(S,i)??S,a(S,x),setTimeout(()=>{t.current.focus(),t.current.setSelectionRange(S.length,S.length);},100);}})]})]})})]})},Pi=e=>jsxRuntime.jsx(ui.Flex,{gap:2,width:"100%",children:[{label:"0%",value:0},{label:"25%",value:.25},{label:"50%",value:.5},{label:"75%",value:.75},{label:"Max",value:1}].map((r,o)=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",onClick:i=>{i.stopPropagation(),i.preventDefault(),e.onClick(r.value);},className:"oui-w-1/5",children:r.label},o))});var Lr=e=>{let{order:t}=e,[r,o]=react.useState(t.price?.toString()??"Market"),[i,n]=react.useState(!1),[a,s]=react.useState(!1),d=t?.algo_order_id!==void 0,l=t?.type==="MARKET"&&d,[g,u]=react.useState(!1),{editOrder:O,editAlgoOrder:w,checkMinNotional:h}=H(),{base:I,quote_dp:_}=B(),v=hooks.useSymbolPriceRange(t.symbol,t.side,d?t.trigger_price:void 0),A=()=>{n(!1),s(!1);},C=()=>{n(!1),o(t.price?.toString()??"Market"),s(!1);},x=react.useMemo(()=>!v||l||!a?"":Number(r)>v.max?`Price can not be greater than ${v.max} USDC.`:Number(r)<v.min?`Price can not be less than ${v.min} USDC.`:"",[l,a,v,r]),F=P=>{if(P?.stopPropagation(),P?.preventDefault(),!(x.length>0)){if(r===`${t.price}`){s(!1);return}if(t.reduce_only!==!0){let L=h(t.symbol,r,t.quantity);if(L){ui.toast.error(L),u(!1),C();return}}n(!0);}},D=P=>{P.key==="Enter"&&F(P);},K=()=>{u(!0);let P=t.order_id,L={order_price:r,order_quantity:t.quantity,symbol:t.symbol,order_type:t.type,side:t.side};typeof t.reduce_only<"u"&&(L.reduce_only=t.reduce_only),t.order_tag!==void 0&&(L={...L,order_tag:t.order_tag}),d&&(P=t.algo_order_id,L={...L,order_id:P,price:r,algo_order_id:P}),t?.visible_quantity===0&&(L.visible_quantity=0),t.tag!==void 0&&(L.order_tag=t.tag);let J;t.algo_order_id!==void 0?J=w(t.algo_order_id.toString(),L):J=O(t.order_id.toString(),L),J.then(oe=>{A(),o(r);},oe=>{ui.toast.error(oe.message),C();}).finally(()=>u(!1));},f=react.useRef(null);react.useEffect(()=>{e.order.price&&o(`${e.order.price}`);},[e.order.price]);let S=react.useRef(null),U=P=>{S.current&&!S.current.contains(P.target)&&!i&&C();};if(react.useEffect(()=>(document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U);}),[i,t.price]),t.algo_order_id&&t.type=="MARKET"||r==="Market")return jsxRuntime.jsx("span",{children:"Market"});let E=()=>!a||e.disableEdit?jsxRuntime.jsx(vi,{order:t,price:r,setEditing:s,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:f,dp:_,value:r,setValue:o,setEditing:s,handleKeyDown:D,onClick:F,onClose:C,hintInfo:x});return jsxRuntime.jsx(ui.Popover,{open:i,onOpenChange:n,content:jsxRuntime.jsx(Ne,{type:1,base:I,value:r,cancelPopover:C,isSubmitting:g,onConfirm:K}),children:jsxRuntime.jsx("div",{onClick:P=>{P.stopPropagation(),P.preventDefault();},ref:S,children:E()})})},vi=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",j(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:utils.commifyOptional(r)})})})};var Fr=e=>{let{order:t}=e,[r,o]=react.useState("");react.useEffect(()=>{o(t.trigger_price?.toString()??"0");},[t.trigger_price]);let i=t?.algo_order_id!==void 0,n=t?.algo_type==="BRACKET",[a,s]=react.useState(!1),[d,l]=react.useState(!1),[g,u]=react.useState(!1),{editAlgoOrder:O,checkMinNotional:w}=H(),{base:h,quote_dp:I,quote_max:_,quote_min:v}=B(),A=react.useMemo(()=>{if(!((!i||n)&&!d)){if(Number(r)>_)return `Trigger price must be less than ${_}`;if(Number(r)<v)return `Trigger price must be greater than ${v}`}},[d,r,i,n]),C=()=>{s(!1),l(!1);},x=()=>{o(t.trigger_price?.toString()??"0"),s(!1),l(!1);},F=react.useRef(null),D=E=>{F.current&&!F.current.contains(E.target)&&!a&&x();};react.useEffect(()=>(document.addEventListener("mousedown",D),()=>{document.removeEventListener("mousedown",D);}),[a,t.trigger_price]);let K=E=>{if(E?.stopPropagation(),E?.preventDefault(),l(!1),Number(r)!==Number(t.trigger_price)){if(t.price&&t.reduce_only!==!0){let P=w(t.symbol,t.price,t.quantity);if(P){ui.toast.error(P),u(!1),x();return}}s(!0);}},f=E=>{E.key==="Enter"&&K(E);},S=()=>{if((A??"").length>0)return;u(!0);let E={quantity:t.quantity,trigger_price:r,symbol:t.symbol,algo_order_id:t.algo_order_id};t.order_tag!==void 0&&(E={...E,order_tag:t.order_tag}),O(`${t.algo_order_id}`,E).then(P=>{C(),o(r);},P=>{ui.toast.error(P.message),o(t.trigger_price?.toString()??"--"),x();}).finally(()=>u(!1));},U=react.useRef(null);if(!i||n)return jsxRuntime.jsx(ui.Text,{children:"--"});let le=()=>!d||e.disableEdit?jsxRuntime.jsx(Di,{order:t,price:r,setEditing:l,disableEdit:e.disableEdit}):jsxRuntime.jsx(we,{inputRef:U,dp:I,value:r,setValue:o,setEditing:l,handleKeyDown:f,onClick:K,onClose:x,hintInfo:A});return jsxRuntime.jsx(ui.Popover,{open:a,onOpenChange:s,content:jsxRuntime.jsx(Ne,{type:2,base:h,value:r,cancelPopover:x,isSubmitting:g,onConfirm:S}),children:jsxRuntime.jsx("div",{onClick:E=>{E.stopPropagation(),E.preventDefault();},ref:F,children:le()})})},Di=e=>{let{order:t,price:r}=e;return jsxRuntime.jsx("div",{className:ui.cn("oui-flex oui-max-w-[110px] oui-justify-start oui-items-center oui-gap-1 oui-relative oui-font-semibold",j(t)&&"oui-text-base-contrast-20"),onClick:o=>{o.stopPropagation(),o.preventDefault(),e.setEditing(!0);},children:jsxRuntime.jsx(ui.Flex,{r:"base",className:ui.cn("oui-min-w-[70px] oui-h-[28px]",!e.disableEdit&&"oui-bg-base-7 oui-px-2 oui-border oui-border-line-12"),children:jsxRuntime.jsx(ui.Text,{size:"2xs",children:r})})})};var je=e=>{let{order:t}=e,{onCancelOrder:r}=H(),[o,i]=react.useState(!1);return jsxRuntime.jsx(ui.ThrottledButton,{size:"sm",variant:"outlined",color:"secondary",onClick:n=>{r&&(n.preventDefault(),n.stopPropagation(),i(!0),r(t).then(a=>a,a=>{ui.toast.error(a.message);}).finally(()=>{i(!1);}));},loading:o,children:"Cancel"})};var kr=e=>{let{record:t}=e,[r,o]=react.useState(!1),[i,{data:n,error:a,reset:s,isMutating:d}]=hooks.useMutation("/v1/order"),l=hooks.useConfig("brokerId"),g=react.useCallback(()=>{o(!1);let u={symbol:t.symbol,order_type:t.type,order_price:t.price,order_quantity:t.quantity,order_amount:t.amount,side:t.side,broker_id:l};Number(t.visible_quantity)<Number(t.quantity)&&(u.visible_quantity=0),typeof t.reduce_only<"u"&&(u.reduce_only=t.reduce_only),i(u);},[]);return jsxRuntime.jsx(ui.Button,{size:"sm",variant:"outlined",color:"secondary",loading:d,disabled:d,onClick:u=>{d||(u.preventDefault(),u.stopPropagation(),g());},children:"Renew"})};var Br=()=>{let{sl_trigger_price:e,tp_trigger_price:t,order:r,position:o}=z();return jsxRuntime.jsx(Hi,{stopLossPrice:e,takeProfitPrice:t,direction:"column",order:r,position:o,tooltip:!0})},Hi=e=>{let{direction:t="row",order:r,position:o}=e,i=hooks.useSymbolsInfo(),n=react.useMemo(()=>{let d=[];if(!e.tooltip||!r||!o)return;let l=r.quantity;return l===0&&r.child_orders?.[0].type==="CLOSE_POSITION"&&(l=o.position_qty),e.takeProfitPrice&&d.push(jsxRuntime.jsx(Rr,{qty:l,price:e.takeProfitPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.TAKE_PROFIT,symbolInfo:i[r.symbol]()},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(Rr,{qty:l,price:e.stopLossPrice,entryPrice:o.average_open_price,orderSide:r.side,orderType:types.AlgoOrderType.STOP_LOSS,symbolInfo:i[r.symbol]()},"sl")),jsxRuntime.jsx("div",{children:d})},[e.takeProfitPrice,e.stopLossPrice,o?.average_open_price,r?.side,r?.quantity,r?.algo_type]),a=react.useMemo(()=>{let d=[];return r?.symbol?(e.takeProfitPrice&&d.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-profit oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:i[r.symbol]("quote_dp",2),children:e.takeProfitPrice,prefix:!e.stopLossPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"TP\xA0-\xA0"}):""},"tp")),e.stopLossPrice&&d.push(jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-text-trade-loss oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12"),rule:"price",dp:i[r.symbol]("quote_dp",2),children:e.stopLossPrice,prefix:!e.takeProfitPrice||t==="column"?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"SL\xA0-\xA0"}):""},"sl")),d.length===0?jsxRuntime.jsx("span",{children:"-"}):(d.length===2&&t==="row"&&d.splice(1,0,jsxRuntime.jsx("span",{children:"/"},"split")),d)):jsxRuntime.jsx("span",{children:"-"})},[e.takeProfitPrice,e.stopLossPrice,r?.symbol]),s=jsxRuntime.jsx("div",{className:ui.cn("oui-inline-flex oui-text-base-contrast-36",e.direction==="column"?"oui-flex-col":"oui-flex-row oui-gap-1",e.className),children:a});return e.tooltip?jsxRuntime.jsx(ui.Tooltip,{content:n,className:"oui-bg-base-5",tooltipProps:{arrow:{className:"oui-fill-base-5"}},children:s}):s},Rr=e=>{let{qty:t,price:r,entryPrice:o,orderSide:i,orderType:n,symbolInfo:a}=e,s=hooks.utils.priceToPnl({qty:t,price:r,entryPrice:o,orderSide:i,orderType:n},{symbol:a}),d=n===types.AlgoOrderType.TAKE_PROFIT?"TP":"SL";return jsxRuntime.jsxs("div",{className:"oui-flex oui-items-center",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54 oui-mr-1",children:`${d} PnL:`}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:a.quote_dp,padding:!1,className:s===0?"oui-text-base-contrast-36":s>0?"oui-text-trade-profit oui-gap-0":"oui-text-trade-loss oui-gap-0",prefix:jsxRuntime.jsx("span",{children:s===0?"":s>0?"+":"-"}),suffix:jsxRuntime.jsx("span",{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),children:`${Math.abs(s)}`})]})};var Ur=e=>{let{order:t}=e,{quote_dp:r,base_dp:o}=B(),{sl_trigger_price:i,tp_trigger_price:n}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(e.order.child_orders[0]),[e.order]),{pnl:a,roi:s}=Ge(t);return !n&&!i?"--":jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof a.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"buy",showIdentifier:!0,children:a.tpPnL}),typeof a.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:r,color:"sell",children:a.slPnL})]}),className:"oui-bg-base-6",children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(Wr,{type:"TP",value:n,quote_dp:r}),jsxRuntime.jsx(Wr,{type:"SL",value:i,quote_dp:r})]})})},Wr=e=>{let{type:t,value:r,quote_dp:o}=e;return r?jsxRuntime.jsx(ui.Text.numeral,{className:ui.cn("oui-gap-0 oui-decoration-white/20 oui-border-b oui-border-dashed oui-border-base-contrast-12",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),rule:"price",dp:o,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-54",children:[`${t}`,"\xA0-\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var zr=e=>{let{position:t,order:r}=z(),{quote_dp:o,base_dp:i}=B();return jsxRuntime.jsx(uiTpsl.PositionTPSLPopover,{quoteDP:o,baseDP:i,position:t,order:r,label:"Edit",isEditing:!0})};var Qr=()=>{let{sl_trigger_price:e,tp_trigger_price:t}=z();return jsxRuntime.jsxs("div",{children:[t?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"TP\xA0-\xA0"}),jsxRuntime.jsx("span",{children:"Market"})]}):null,e?jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-80 oui-td-bg-transparent",children:[jsxRuntime.jsx("span",{className:"oui-text-base-contrast-54",children:"SL\xA0-\xA0"}),jsxRuntime.jsx("span",{children:"Market"})]}):null]})};var Vr=e=>{let{_type:t,onSymbolChange:r,pnlNotionalDecimalPrecision:o}=e;return react.useMemo(()=>{switch(t){case"all":return [be({width:130,showType:!0,onSymbolChange:r,enableSort:!1}),ve({width:130,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),Ee({width:130,title:"Order price",disableEdit:!0,enableSort:!1}),tt({width:130,enableSort:!1}),$r({width:130}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:130,enableSort:!1}),Qe({width:130}),$e({width:130}),xe({width:130}),Ae({width:130}),Kr({width:130})];case"pending":return [be({width:172,showType:!0,onSymbolChange:r,enableSort:!1}),ve({width:162,className:"oui-pr-0",enableSort:!1}),Ee({width:162,className:"oui-pr-0",enableSort:!1}),Ue({width:162,className:"oui-pr-0"}),cn({width:130}),Ie({width:162,isPending:!0}),xe({width:162}),Ae({width:162}),ze({width:162,enableSort:!1}),pn({width:162})];case"tp_sl":return [be({width:176,showType:!0,onSymbolChange:r,enableSort:!1}),ln({width:176}),$r({width:176}),dn({width:176,disableEdit:!0}),mn({width:176}),xe({width:176}),ze({width:176,enableSort:!1}),gn({width:176})];case"filled":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),Ee({width:124,title:"Order price",disableEdit:!0}),un({width:124}),Ue({width:124,disableEdit:!0}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:124})];case"cancelled":return [be({showType:!0,width:154,onSymbolChange:r,enableSort:!1}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0",enableSort:!1}),Ee({width:124,disableEdit:!0,enableSort:!1}),tt({width:124,enableSort:!1}),Ue({width:124,disableEdit:!0}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124})];case"rejected":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:124,disableEdit:!0,className:"oui-pl-0 oui-pr-0"}),Ee({width:124,disableEdit:!0}),tt({width:124}),Ue({width:124,disableEdit:!0}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:124})];case"orderHistory":return [be({showType:!0,width:154,onSymbolChange:r}),ve({width:150,disableEdit:!0,className:"oui-pl-6 oui-pr-0"}),Ee({width:124,disableEdit:!0}),tt({width:124}),Ue({width:124,disableEdit:!0}),wt({width:124,pnlNotionalDecimalPrecision:o}),Ie({width:124}),Qe({width:124}),$e({width:124}),xe({width:124}),Ae({width:124}),ze({width:150}),Kr({width:80})]}},[t,o])};function be(e){return {title:"Instrument",dataIndex:"symbol",fixed:"left",width:e?.width,onSort:e?.enableSort?(t,r)=>t.symbol.localeCompare(r.symbol):void 0,render:(t,r)=>{let o=j(r);return jsxRuntime.jsxs(ui.Flex,{gap:2,children:[jsxRuntime.jsx("div",{className:ui.cn("oui-rounded-[1px] oui-w-1 oui-h-7 oui-shrink-0",r.side===types.OrderSide.BUY?"oui-bg-trade-profit":"oui-bg-trade-loss")}),jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",children:[jsxRuntime.jsx(ui.Text.formatted,{size:"xs",className:"oui-cursor-pointer oui-text-xs",onClick:i=>{e?.onSymbolChange?.({symbol:t}),i.stopPropagation(),i.preventDefault();},children:`${t.split("_")[1]}-PERP`}),e?.showType&&jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(r)?.map((i,n)=>jsxRuntime.jsx(ui.Badge,{color:i.toLocaleLowerCase()==="position"?o?"neutral":"primary":"neutral",size:"xs",children:i},n))})]})]})}}}function ve(e){return {title:"Filled / Quantity",dataIndex:"fill_quantity",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return Ke(o,i)}:void 0,render:(t,r)=>r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(Pt,{order:r,disableEdit:e?.disableEdit})}}function ln(e){return {title:"Quantity",className:e?.className,dataIndex:"quantity",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>{let o=(t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:t.quantity)??0,i=(r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?0:r.quantity)??0;return Ke(o,i)}:void 0,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(Pt,{order:r})}}function Ee(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort??!1?(t,r,o)=>Ke(t.price??0,r.price??0):void 0,render:(t,r)=>jsxRuntime.jsx(Lr,{order:r,disableEdit:e?.disableEdit})}}function dn(e){return {title:e?.title??"Price",dataIndex:"price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Qr,{})}}function un(e){return {title:"Avg. price",dataIndex:"average_executed_price",className:e?.className,width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:utils.commifyOptional(t)})}}function Ue(e){return {title:"Trigger",className:e?.className,dataIndex:"trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Fr,{order:r,disableEdit:e?.disableEdit})}}function $r(e){return {title:e?.title??"Trigger",className:e?.className,dataIndex:"tpsl_trigger_price",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Br,{})}}function cn(e){return {title:"TP/SL",className:e?.className,dataIndex:"bracketOrderPrice",width:e?.width,onSort:e?.enableSort,render:(t,r)=>jsxRuntime.jsx(Ur,{order:r})}}function Ie(e){return {title:"Est. total",dataIndex:"executed",width:e?.width,className:e?.className,onSort:e?.enableSort??!1?(t,r,o)=>{let i=t.type===types.OrderType.CLOSE_POSITION&&t.status!==types.OrderStatus.FILLED||t.total_executed_quantity===0||Number.isNaN(t.average_executed_price)||t.average_executed_price===null?0:t.total_executed_quantity*t.average_executed_price,n=r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED||r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?0:r.total_executed_quantity*r.average_executed_price;return Ke(i,n)}:void 0,render:(t,r)=>{if(e?.isPending){let o=()=>r.price&&r.quantity?new utils.Decimal(r.price).mul(r.quantity).toFixed(2,utils.Decimal.ROUND_DOWN):"--";return jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,children:o()})}return r.type===types.OrderType.CLOSE_POSITION&&r.status!==types.OrderStatus.FILLED?"Entire position":jsxRuntime.jsx(ui.Text.numeral,{rm:utils.Decimal.ROUND_DOWN,dp:2,children:r.total_executed_quantity===0||Number.isNaN(r.average_executed_price)||r.average_executed_price===null?"--":`${r.total_executed_quantity*r.average_executed_price}`})}}}function wt(e){return {title:"Real. PnL",dataIndex:"realized_pnl",width:e?.width,className:e?.className,render:t=>{let{quote_dp:r}=B(),o=e?.pnlNotionalDecimalPrecision??r,i=new utils.Decimal(t??0).toDecimalPlaces(o,utils.Decimal.ROUND_DOWN).toNumber();return jsxRuntime.jsx(ui.Text.numeral,{dp:o,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(i??0)==0?80:void 0,showIdentifier:(i??0)>0,coloring:(i??0)!=0,children:i??"--"})}}}function xe(e){return {title:"Reduce only",dataIndex:"reduce_only",width:e?.width,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text,{children:t?"Yes":"No"})}}function Ae(e){return {title:"Hidden",dataIndex:"visible",width:e?.width,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text,{children:r.visible_quantity!==0?"No":"Yes"})}}function ze(e){return {title:"Order time",dataIndex:"created_time",width:e?.width,onSort:e?.enableSort,className:e?.className,render:t=>jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:e?.formatString||"yyyy-MM-dd HH:mm:ss",className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:t})}}function Qe(e){return {title:"Fee",dataIndex:"total_fee",width:e?.width,onSort:e?.enableSort,className:e?.className}}function mn(e){return {title:"Notional",dataIndex:"executed",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>r.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?"Entire position":jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.quantity===0?"--":`${new utils.Decimal(r.mark_price).mul(r.quantity).todp(2).toNumber()}`})}}function $e(e){return {title:"Status",dataIndex:"status",width:e?.width,onSort:e?.enableSort,className:e?.className,render:(t,r)=>{let o=t||r.algo_status;return o==="NEW"?Z("pending"):Z(o)}}}function tt(e){return {title:"Avg. open",dataIndex:"average_executed_price",width:e?.width,onSort:e?.enableSort??!1?(t,r)=>Ke(t.average_executed_price??0,r.average_executed_price??0):void 0,className:e?.className,render:(t,r)=>jsxRuntime.jsx(ui.Text.numeral,{className:"oui-break-normal oui-whitespace-nowrap oui-font-semibold",children:r.average_executed_price})}}function Kr(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>r.status===types.OrderStatus.CANCELLED?jsxRuntime.jsx(kr,{record:r}):r.status===types.OrderStatus.NEW||r.algo_status===types.OrderStatus.NEW?jsxRuntime.jsx(je,{order:r}):null}}function pn(e){return {title:"",type:"action",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsx(je,{order:r})}}function gn(e){return {title:"",dataIndex:"action",width:e?.width,className:e?.className,align:"right",fixed:"right",render:(t,r)=>jsxRuntime.jsxs(ui.Flex,{gap:3,children:[jsxRuntime.jsx(zr,{order:r}),jsxRuntime.jsx(je,{order:r})]})}}function Ke(e,t){return e>t?1:e<t?-1:0}var Jr=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY;return jsxRuntime.jsx(ui.Text.formatted,{intensity:80,rule:"symbol",formatString:"base-type",size:"sm",prefix:jsxRuntime.jsx(ui.Badge,{color:r?"success":"danger",size:"xs",children:r?"Buy":"Sell"}),onClick:()=>{e.onSymbolChange?.({symbol:t.symbol});},children:t.symbol})},Xr=e=>{let {item:t}=e;react.useCallback(()=>{let o=typeof t.type=="string"?t.type.replace("_ORDER","").toLowerCase():t.type;return t.algo_order_id&&t.algo_type!==types.AlgoOrderRootType.BRACKET?`Stop ${o}`:Z(t.type)},[t]);return jsxRuntime.jsx(ui.Flex,{direction:"row",gap:1,children:de(e.item)?.map((o,i)=>jsxRuntime.jsx(ui.Badge,{color:o.toLocaleLowerCase()==="position"?"primaryLight":"neutral",size:"xs",children:o},i))})},Zr=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Text.formatted,{rule:"date",formatString:"yyyy-MM-dd hh:mm:ss",intensity:36,size:"2xs",children:t.updated_time})},jr=e=>{let{item:t}=e,r=t.status||t.algo_status,o=()=>r==="NEW"?Z("pending"):Z(r);return jsxRuntime.jsx(ui.Text.formatted,{intensity:36,size:"2xs",children:o()})},vt=e=>{let{item:t}=e,r=t.type===types.OrderType.CLOSE_POSITION&&t?.status!==types.OrderStatus.FILLED;return jsxRuntime.jsx(ui.Statistic,{label:"Qty.",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.base_dp,padding:!1,coloring:!0,placeholder:"Entire position",intensity:80,children:r?"--":t.quantity})})},Et=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsx(ui.Text,{children:"Filled"}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:t.total_executed_quantity})})};var eo=e=>{let{item:t}=e,r=react.useMemo(()=>t.price&&t.quantity?new utils.Decimal(t.price).mul(t.quantity).toFixed(e.quote_dp,utils.Decimal.ROUND_DOWN):"--",[t.price,t.quantity]);return jsxRuntime.jsx(ui.Statistic,{align:"end",label:jsxRuntime.jsxs(ui.Text,{children:["ESt. Total",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,coloring:!0,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:r})})},It=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Trigger price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:e.align,children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,intensity:80,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:t.trigger_price??"--"})})},to=e=>{let{item:t}=e;return jsxRuntime.jsx(ui.Statistic,{label:"Mark price",align:"end",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.mark_price})})},ro=e=>{let{item:t}=e,r=t?.algo_order_id!==void 0,o=t?.type==="MARKET"&&r;return jsxRuntime.jsx(ui.Statistic,{label:"Limit price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:o?jsxRuntime.jsx(ui.Text,{children:"Market"}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.price??"--"})})},oo=e=>{let{tp_trigger_price:t,tpPnL:r}=z();return jsxRuntime.jsx(ui.Statistic,{label:"TP trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(it,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",showIdentifier:!0,prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"TP PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"buy",padding:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},io=e=>{let{sl_trigger_price:t,slPnL:r}=z();return jsxRuntime.jsx(ui.Statistic,{label:"SL trigger",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(it,{content:r&&jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",prefix:jsxRuntime.jsx(ui.Text,{intensity:54,children:"SL PnL:\xA0\xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:"\xA0USDC"}),coloring:!0,children:r}),classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,color:"sell",padding:!1,className:t?"oui-border-b oui-border-dashed oui-border-base-contrast-12":void 0,children:t??"--"})})})},no=e=>jsxRuntime.jsx(ui.Statistic,{label:"TP price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),ao=e=>jsxRuntime.jsx(ui.Statistic,{label:"SL price",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"})}),so=e=>{let{item:t}=e,r=react.useMemo(()=>t.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL?jsxRuntime.jsx("span",{className:"oui-text-base-contrast-80",children:"Entire position"}):jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:t.quantity}),[t]);return jsxRuntime.jsx(ui.Statistic,{label:"Quantity",classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:r})},lo=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Avg price",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,children:e.item?.average_executed_price??"--"})}),uo=e=>jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Order price",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,intensity:80,padding:!1,placeholder:"Market",children:e.item?.price??"--"})}),co=e=>{let t=e?.item?.realized_pnl;return jsxRuntime.jsx(ui.Statistic,{label:jsxRuntime.jsxs(ui.Text,{children:["Real. PnL",jsxRuntime.jsx(ui.Text,{intensity:20,children:"(USDC)"})]}),classNames:{root:"oui-text-xs",label:"oui-text-2xs"},align:"end",children:jsxRuntime.jsx(ui.Text.numeral,{dp:e.quote_dp,rm:utils.Decimal.ROUND_DOWN,padding:!1,intensity:(t??0)==0?80:void 0,showIdentifier:(t??0)>0,coloring:(t??0)!=0,children:t??"--"})})},it=e=>{let{classNames:t,content:r}=e,[o,i]=react.useState(!1);return typeof r>"u"?e.children:jsxRuntime.jsx(ui.Tooltip,{content:r,className:t?.content,open:o,onOpenChange:i,tooltipProps:{arrow:{className:t?.arrow}},children:jsxRuntime.jsx("div",{onClick:()=>i(n=>!n),children:e.children})})};var At=e=>{let {item:t}=e;t.quantity>0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:()=>{e.onShowEditSheet();},children:"Edit"})})};var go=e=>{let{side:t}=e.item,{price:r,quantity:o,triggerPrice:i,isAlgoOrder:n}=e,a=t===types.OrderSide.BUY;return jsxRuntime.jsxs("div",{className:"oui-pt-2",children:[jsxRuntime.jsx(ui.Text,{intensity:80,children:`You agree to edit your ${e.base}-PERP order.`}),jsxRuntime.jsxs(ui.Flex,{gap:2,mb:3,mt:2,justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:!0,children:e.item.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((s,d)=>jsxRuntime.jsx(ui.Badge,{color:s.toLocaleLowerCase()==="position"?"primaryLight":"neutral",size:"xs",children:s},d)),a&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!a&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"Sell"})]})]}),jsxRuntime.jsx(ui.Divider,{}),jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",className:"oui-text-sm oui-text-base-contrast-54",py:3,children:[n&&jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Trigger price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),children:i??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Price"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:80,dp:e.quote_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,suffix:jsxRuntime.jsx(ui.Text,{intensity:54,children:" USDC"}),placeholder:e.isStopMarket?"Market":"--",children:e.isStopMarket?"Market":r??"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",gap:1,children:[jsxRuntime.jsx(ui.Text,{children:"Qty."}),jsxRuntime.jsx(ui.Text.numeral,{color:t===types.OrderSide.BUY?"buy":"sell",dp:e.base_dp,padding:!1,rm:utils.Decimal.ROUND_DOWN,children:o??"--"})]})]}),jsxRuntime.jsxs(ui.Flex,{className:"oui-gap-[2px]",children:[jsxRuntime.jsx(ui.Checkbox,{color:"white",id:"oui-checkbox-disableOrderConfirmation",checked:!e.orderConfirm,onCheckedChange:s=>{e.setOrderConfirm(!s);}}),jsxRuntime.jsx("label",{className:"oui-text-2xs oui-text-base-contrast-54",htmlFor:"oui-checkbox-disableOrderConfirmation",children:"Disable order confirmation"})]})]})};var Bt=e=>{let{item:t}=e,r=t.side===types.OrderSide.BUY,o=e.quantity&&e.maxQty?Math.min(Number(e.quantity)/e.maxQty,1):void 0,i=n=>{let a=e.baseTick;if(a&&a>0){let s=hooks.utils.formatNumber(n,a)??n;e.setQuantity(s);}};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:3,width:"100%",itemAlign:"start",className:"oui-text-sm",children:[jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",showIcon:!0,intensity:80,children:t.symbol}),jsxRuntime.jsxs(ui.Flex,{direction:"row",gap:1,children:[de(e.item)?.map((n,a)=>jsxRuntime.jsx(ui.Badge,{color:n.toLocaleLowerCase()==="position"?"primaryLight":"neutral",size:"xs",children:n},a)),r&&jsxRuntime.jsx(ui.Badge,{color:"success",size:"xs",children:"Buy"}),!r&&jsxRuntime.jsx(ui.Badge,{color:"danger",size:"xs",children:"Sell"})]})]}),jsxRuntime.jsx(ui.Divider,{intensity:8,className:"oui-w-full"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Last price"}),jsxRuntime.jsx(ui.Text.numeral,{dp:e.item?.symbolInfo?.duote_dp,children:e.curMarkPrice??"--"})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",direction:"column",itemAlign:"stretch",gap:2,children:[e.isAlgoOrder&&jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Trigger price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.trigger_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],value:e.triggerPrice,onValueChange:n=>e.setTriggerPrice(n),tooltip:e.errors?.trigger_price?.message,tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98 oui-w-full",root:ui.cn("oui-outline-line-12",e.errors?.trigger_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Price"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.quote}),color:e.errors?.order_price?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp)],disabled:!e.priceEdit,value:e.isStopMarket?"Market":e.price,onValueChange:n=>e.setPrice(n),tooltip:e.errors?.order_price?.message,tooltipProps:{content:{className:"oui-bg-base-5"},arrow:{className:"oui-fill-base-5"}},classNames:{input:"oui-text-base-contrast-98",root:ui.cn("oui-outline-line-12",e.errors?.order_price?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Input.tooltip,{prefix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:"Quantity"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:54,className:"oui-px-3",children:e.base}),color:e.errors?.order_quantity?.message?"danger":void 0,align:"right",fullWidth:!0,autoComplete:"off",formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.base_dp)],value:e.quantity,onValueChange:n=>{e.setQuantity(n);},onBlur:n=>i(n.target.value),tooltip:e.errors?.order_quantity?.message,tooltipProps:{content:{className:"oui-bg-base-6"},arrow:{className:"oui-fill-base-6"}},classNames:{input:"oui-text-base-contrast-98",root:ui.cn("oui-outline-line-12",e.errors?.order_quantity?.message&&"oui-outline-danger")}}),jsxRuntime.jsx(ui.Slider,{markCount:4,value:[e.sliderValue??0],onValueChange:n=>{e.setSliderValue(n[0]);},color:"primaryLight"}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(ui.Text.numeral,{color:"primaryLight",size:"2xs",dp:2,padding:!1,rule:"percentages",children:`${o??0}`}),jsxRuntime.jsxs(ui.Flex,{gap:1,children:[jsxRuntime.jsx(ui.Text,{size:"2xs",color:"primaryLight",children:"Max"}),jsxRuntime.jsx(ui.Text.numeral,{intensity:54,size:"2xs",dp:e.base_dp,children:e.maxQty})]})]})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",gap:3,mt:2,children:[jsxRuntime.jsx(ui.Button,{fullWidth:!0,color:"secondary",onClick:n=>{e.onClose();},children:"Cancel"}),jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,onClick:n=>{n.stopPropagation(),n.preventDefault(),e.onSheetConfirm();},loading:e.submitting,disabled:!e.isChanged,children:"Confirm"})]})]}),jsxRuntime.jsx(ui.SimpleDialog,{open:e.dialogOpen,onOpenChange:e.setDialogOpen,title:"Edit order",size:"xs",actions:{primary:{label:"Confirm",onClick:e.onDialogConfirm,loading:e.submitting,fullWidth:!0},secondary:{label:"Cancel",onClick:e.onCloseDialog,fullWidth:!0}},classNames:{content:"oui-pb-4",body:"oui-p-0",footer:"oui-pt-3 oui-pb-0"},children:jsxRuntime.jsx(go,{...e})})]})};var zt=e=>{let {state:t,editAlgoOrder:r,editOrder:o,autoCheckInput:i=!0}=e,{item:n}=t,{hide:a}=ui.useModal(),[s,d]=react.useState(!1),l=n?.algo_order_id!==void 0&&n.algo_type!==types.AlgoOrderRootType.BRACKET,g=n?.type==="MARKET"&&l;g||n?.type==="MARKET";let [O,w]=react.useState(!1),h=react.useMemo(()=>l&&n.algo_type!==types.AlgoOrderRootType.BRACKET?`STOP_${n.type}`:n.type,[n,l]),[I,_]=hooks.useLocalStorage("orderly_order_confirm",!0),{base_dp:v,base_tick:A}=e.state,{formattedOrder:C,setValue:x,symbolInfo:F,markPrice:D,errors:K,validate:f,maxQty:S}=Wn({order:n,orderType:h}),U=()=>{f().then(p=>{I?d(!0):L(C);},p=>{p?.total?.message&&ui.toast.error(p?.total.message);}).catch(p=>{});},le=react.useCallback(()=>{d(!1);},[]),E=()=>C?L(C):Promise.reject(),P=react.useCallback(()=>{a();},[]),L=react.useCallback(async p=>{let k,ie=n.visible_quantity!==void 0?n.visible_quantity===0:n.visible!==void 0?n.visible===0:!1;if(n.algo_order_id!==void 0){if(g&&"order_price"in p){let{order_price:he,...Re}=p;p=Re;}k=r(n.algo_order_id.toString(),{...p});}else k=o(n.order_id.toString(),{...p,...ie?{visible_quantity:0}:{}});try{w(!0);let he=await k;P();}catch(he){ui.toast.error(he?.message??`${he}`);}finally{w(!1);}},[r,o]),J=react.useMemo(()=>{let p=C.order_quantity;return p&&Number(p)!==0&&S!==0?new utils.Decimal(p).div(S).mul(100).toDecimalPlaces(2,utils.Decimal.ROUND_DOWN).toNumber():0},[C.order_quantity,S]),oe=n.price!=C.order_price||n.quantity!=C.order_quantity||n.trigger_price!=C.trigger_price,Ce=hooks.useThrottledCallback(p=>{let k=new utils.Decimal(p).div(100).mul(S).toDecimalPlaces(v,utils.Decimal.ROUND_DOWN).toNumber();x("order_quantity",hooks.utils.formatNumber(k,A));},50,{}),m=(p,k)=>{x(p,k);};return {...t,curMarkPrice:D,isAlgoOrder:l,isStopMarket:g,price:C.order_price,setPrice:p=>m("order_price",p),priceEdit:!g,triggerPrice:C.trigger_price,setTriggerPrice:p=>m("trigger_price",p),quantity:C.order_quantity,setQuantity:p=>{m("order_quantity",p);},maxQty:S,sliderValue:J,setSliderValue:Ce,onClose:P,onSheetConfirm:U,errors:K,orderType:h,isChanged:oe,baseTick:A,dialogOpen:s,setDialogOpen:d,onDialogConfirm:E,onCloseDialog:le,submitting:O,orderConfirm:I,setOrderConfirm:_}},Wn=e=>{let{order:t,orderType:r}=e,[o,i]=react.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:n}=t,{position:a}=z(),s=a?.position_qty,d=hooks.useMaxQty(t.symbol,t.side,t.reduce_only),l=react.useMemo(()=>n?Math.abs(s??0):t.quantity+Math.abs(d),[t.quantity,d,n,s]),{symbolInfo:g,markPrice:u,errors:O,validate:w}=hooks.useOrderEntity({...o,symbol:t.symbol},{maxQty:l});return {symbolInfo:g,markPrice:u,errors:O,validate:w,setValue:(I,_)=>{i(v=>({...v,[I]:_}));},formattedOrder:o,maxQty:l}};var Qt=e=>{let t=zt(e);return jsxRuntime.jsx(Bt,{...t})};var $t=e=>{let{state:t}=e,{editAlgoOrder:r,editOrder:o}=H(),{order:i,position:n}=z(),a=react.useCallback(()=>{e.state.type==="tp_sl"?ui.modal.sheet({title:"TP/SL",content:jsxRuntime.jsx(uiTpsl.PositionTPSLSheet,{isEditing:!0,order:e.state.item,position:n,symbolInfo:e.state.origin})}).catch(s=>{}):ui.modal.sheet({title:"Edit order",classNames:{content:"oui-bg-base-8"},content:jsxRuntime.jsx(Qt,{state:t,editAlgoOrder:r,editOrder:o})}).catch(s=>{});},[t]);return {...t,onShowEditSheet:a}};var Kt=e=>{let t=$t(e);return jsxRuntime.jsx(At,{...t})};var Ht=e=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Button,{variant:"outlined",fullWidth:!0,color:"secondary",size:"sm",className:"oui-border-base-contrast-36",onClick:t=>e.setOpen(!0),children:"Cancel"}),e.open&&jsxRuntime.jsx(ui.SimpleDialog,{size:"xs",open:e.open,onOpenChange:e.setOpen,title:"Cancel order",actions:{primary:{label:"Confirm",loading:e.isLoading,fullWidth:!0,size:"md",onClick:t=>{e.onCancel(t);}},secondary:{label:"Cancel",fullWidth:!0,size:"md",onClick:()=>{e.onClose();}}},children:jsxRuntime.jsx(ui.Text,{size:"2xs",intensity:54,children:"Are you sure you want to cancel your pending order."})})]});var Yt=e=>{let{state:t}=e,[r,o]=react.useState(!1),{onCancelOrder:i}=H(),[n,a]=react.useState(!1);return {...t,open:r,setOpen:o,onCancel:l=>i?(l?.preventDefault(),l?.stopPropagation(),a(!0),i(t.item).then(g=>{o(!1);},g=>{ui.toast.error(g.message);}).finally(()=>{a(!1);})):Promise.resolve(),onClose:()=>{o(!1);},isLoading:n}};var Gt=e=>{let t=Yt(e);return jsxRuntime.jsx(Ht,{...t})};var Zt=e=>!e.sl_trigger_price&&!e.tp_trigger_price?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(it,{classNames:{content:"oui-bg-base-6 oui-ml-2",arrow:"oui-fill-base-6"},content:jsxRuntime.jsxs(ui.Flex,{direction:"column",itemAlign:"start",gap:1,children:[typeof e.pnl?.tpPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"TP PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"buy",showIdentifier:!0,children:e.pnl?.tpPnL}),typeof e.pnl?.slPnL<"u"&&jsxRuntime.jsx(ui.Text.numeral,{prefix:jsxRuntime.jsx(ui.Text,{intensity:80,children:"SL PnL: \xA0"}),suffix:jsxRuntime.jsx(ui.Text,{intensity:20,children:" USDC"}),dp:e.quote_dp,color:"sell",children:e.pnl?.slPnL})]}),children:jsxRuntime.jsx("button",{onClick:()=>{e.setOpen(!e.open);},children:jsxRuntime.jsxs(ui.Flex,{gap:1,width:"1",children:[e.tp_trigger_price&&jsxRuntime.jsx(Po,{type:"TP",value:e.tp_trigger_price,quote_dp:e.quote_dp}),e.sl_trigger_price&&jsxRuntime.jsx(Po,{type:"SL",value:e.sl_trigger_price,quote_dp:e.quote_dp})]})})})}),Po=e=>{let{type:t,value:r,quote_dp:o}=e;return r?jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",className:ui.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:!1,rm:utils.Decimal.ROUND_DOWN,prefix:jsxRuntime.jsxs("span",{className:"oui-text-base-contrast-36",children:[`${t} `,":\xA0\xA0"]}),children:r},"tp"):jsxRuntime.jsx(jsxRuntime.Fragment,{})};var jt=e=>{let{item:t,quote_dp:r,base_dp:o}=e,[i,n]=react.useState(!1),{sl_trigger_price:a,tp_trigger_price:s}=react.useMemo(()=>!("algo_type"in t)||!Array.isArray(t.child_orders)?{}:hooks.utils.findTPSLFromOrder(t.child_orders[0]),[t]),{pnl:d,roi:l}=Ge(t);return {sl_trigger_price:a,tp_trigger_price:s,pnl:d,roi:l,quote_dp:r,open:i,setOpen:n}};var er=e=>{let t=jt(e);return jsxRuntime.jsx(Zt,{...t})};var tr=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",gap:2,itemAlign:"start",className:e.className,children:[jsxRuntime.jsx(na,{...e}),jsxRuntime.jsx(ui.Divider,{intensity:6,className:"oui-w-full"}),jsxRuntime.jsx(aa,{...e}),e.type==="pending"&&jsxRuntime.jsx(er,{...e}),e.type!=="orderHistory"&&jsxRuntime.jsx(sa,{...e})]}),na=e=>jsxRuntime.jsxs(ui.Flex,{direction:"column",gap:1,width:"100%",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",width:"100%",children:[jsxRuntime.jsx(Jr,{...e}),jsxRuntime.jsx(Zr,{...e})]}),jsxRuntime.jsxs(ui.Flex,{width:"100%",justify:"between",children:[jsxRuntime.jsx(Xr,{...e}),e.type==="orderHistory"&&jsxRuntime.jsx(jr,{...e})]})]}),aa=e=>jsxRuntime.jsx(ui.Grid,{cols:3,rows:2,width:"100%",gap:1,children:la(e)}),sa=e=>jsxRuntime.jsxs(ui.Grid,{cols:3,rows:1,width:"100%",gap:2,children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx(Kt,{state:e}),jsxRuntime.jsx(Gt,{state:e})]});function la(e){switch(e.type){case"all":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case"pending":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(vt,{...e}),jsxRuntime.jsx(Et,{...e}),jsxRuntime.jsx(eo,{...e}),jsxRuntime.jsx(It,{...e}),jsxRuntime.jsx(ro,{...e}),jsxRuntime.jsx(to,{...e})]});case"tp_sl":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(oo,{...e}),jsxRuntime.jsx(no,{...e}),jsxRuntime.jsx(so,{...e}),jsxRuntime.jsx(io,{...e}),jsxRuntime.jsx(ao,{...e})]});case"filled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case"cancelled":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case"rejected":return jsxRuntime.jsx(jsxRuntime.Fragment,{});case"orderHistory":return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(vt,{...e}),jsxRuntime.jsx(Et,{...e}),jsxRuntime.jsx(It,{...e,align:"end"}),jsxRuntime.jsx(lo,{...e}),jsxRuntime.jsx(uo,{...e}),jsxRuntime.jsx(co,{...e})]})}}var rr=e=>{let t=B();return {...e,...t}};var or=e=>{let{className:t,...r}=e,o=rr(r);return jsxRuntime.jsx(tr,{...o,className:t})};var ir=e=>{let t=Vr({_type:e.type,onSymbolChange:e.onSymbolChange,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision});return jsxRuntime.jsx(gt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Flex,{direction:"column",width:"100%",height:"100%",itemAlign:"start",children:[e.filterItems.length>0&&jsxRuntime.jsx(ui.DataFilter,{items:e.filterItems,onFilter:r=>{e.onFilter(r);},trailing:["pending","tp_sl"].includes(e.type)&&jsxRuntime.jsx(ba,{...e})}),jsxRuntime.jsx(uiConnector.AuthGuardTableView,{columns:t,loading:e.isLoading,dataSource:e.dataSource,bordered:!0,ignoreLoadingCheck:!0,classNames:{header:"oui-h-[38px]",root:"oui-items-start !oui-h-[calc(100%_-_49px)]"},onRow:(r,o)=>({className:ui.cn("oui-h-[48px]",j(r)?"oui-text-base-contrast-20":"oui-text-base-contrast-80")}),generatedRowKey:(r,o)=>`${e.type}${o}${r.order_id||r.algo_order_id}_index${o}`,renderRowContainer:(r,o,i)=>((e.type==="tp_sl"||e.type==="pending")&&(i=jsxRuntime.jsx(yt,{order:r,children:i})),jsxRuntime.jsx(mt,{symbol:r.symbol,children:i})),pagination:e.pagination,manualPagination:e.manualPagination})]})})},nr=e=>jsxRuntime.jsx(gt,{cancelOrder:e.cancelOrder,editOrder:e.updateOrder,cancelAlgoOrder:e.cancelAlgoOrder,editAlgoOrder:e.updateAlgoOrder,children:jsxRuntime.jsxs(ui.Grid,{cols:1,rows:2,className:"oui-grid-rows-[auto,1fr] oui-w-full",gap:2,children:[e.showFilter?jsxRuntime.jsx(ui.Flex,{gap:2,p:2,className:"oui-bg-base-9 oui-rounded-b-xl",children:e.filterItems.map(t=>t.type!=="select"?jsxRuntime.jsx(jsxRuntime.Fragment,{}):jsxRuntime.jsx(ui.Picker,{options:t.options,size:"sm",value:t.value,className:"oui-text-2xs oui-text-base-contrast-54 ",placeholder:t.name==="side"?"All sides":t.name==="status"?"All status":"",onValueChange:r=>{e.onFilter?.({name:t.name,value:r});}}))}):jsxRuntime.jsx("div",{}),jsxRuntime.jsx(ui.ListView,{className:e.classNames?.root,contentClassName:e.classNames?.content,dataSource:e.dataSource,loadMore:e.loadMore,isLoading:e.isLoading,renderItem:(t,r)=>{let o=jsxRuntime.jsx(or,{item:t,index:r,className:e.classNames?.cell,type:e.type,onSymbolChange:e.onSymbolChange});return e.type==="tp_sl"&&(o=jsxRuntime.jsx(yt,{order:t,children:o})),jsxRuntime.jsx(mt,{symbol:t.symbol,children:o})}})]})}),ba=e=>jsxRuntime.jsx(ui.Button,{variant:"outlined",color:"secondary",size:"xs",disabled:(e.dataSource?.length??0)==0,className:"disabled:oui-bg-transport",onClick:t=>e.onCancelAll(),children:"Cancel all"});var No=e=>react.useMemo(()=>{let r=[];for(let o=0;o<e.length;o++){let i=e[o];if(i.algo_type===types.AlgoOrderRootType.POSITIONAL_TP_SL||i.algo_type===types.AlgoOrderRootType.TP_SL)if(i.algo_status!==types.OrderStatus.FILLED&&i.algo_status!==types.OrderStatus.PARTIAL_FILLED)for(let n=0;n<i.child_orders.length;n++){let a=i.child_orders[n];!a.is_activated||!a.trigger_price||(a.parent_algo_type=i.algo_type,r.push(a));}else for(let n=0;n<i.child_orders.length;n++){let a=i.child_orders[n];a&&(a.algo_status===types.OrderStatus.FILLED||a.algo_status===types.OrderStatus.PARTIAL_FILLED)&&(a.parent_algo_type=i.algo_type,r.push(a));}else r.push(i);}return r},[e]);var ut=e=>{let{ordersStatus:t,type:r,enableLoadMore:o=!1,onSymbolChange:i,filterConfig:n,pnlNotionalDecimalPrecision:a}=e,s=react.useMemo(()=>t!==types.OrderStatus.INCOMPLETE,[t]),d=50,{page:l,pageSize:g,setPage:u,setPageSize:O,parseMeta:w}=ui.usePagination({pageSize:d}),{orderStatus:h,ordersSide:I,dateRange:_,filterItems:v,onFilter:A}=va(r,{ordersStatus:t,setPage:u,filterConfig:n}),C=react.useMemo(()=>{if(r==="tp_sl")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),x=react.useMemo(()=>{if(r==="pending")return [types.AlgoOrderRootType.POSITIONAL_TP_SL,types.AlgoOrderRootType.TP_SL]},[r]),[F,{isLoading:D,loadMore:K,cancelOrder:f,updateOrder:S,cancelAlgoOrder:U,updateAlgoOrder:le,cancelAllOrders:E,cancelAllTPSLOrders:P,meta:L,refresh:J}]=hooks.useOrderStream({symbol:e.symbol,status:h,side:I,page:o||!s?void 0:l,size:s?g:500,dateRange:_,includes:C,excludes:x}),oe=`orderly_${r}_pageSize`,[Ce,m]=hooks.useLocalStorage(oe,d);react.useEffect(()=>{Ce!==g&&m(g);},[g,Ce]);let p=react.useCallback(()=>{let Re=e.type==="pending"?"Cancel all pending orders":e.type==="tp_sl"?"Cancel all TP/SL orders":"",Io="Are you sure you want to cancel all of your pending orders?";ui.modal.confirm({title:Re,content:jsxRuntime.jsx(ui.Text,{size:"sm",children:Io}),onCancel:async()=>{},onOk:async()=>{try{return r==="tp_sl"?await P():await E(),J(),Promise.resolve(!0)}catch(sr){return sr?.message!==void 0&&toast.error(sr.message),Promise.resolve(!1)}finally{Promise.resolve();}}});},[r]),k=No(F??[]),ie=reactApp.useDataTap(r!=="tp_sl"?k:F)??void 0,he=react.useMemo(()=>{let Re=s?L:{total:ie?.length,current_page:l,records_per_page:g};return {...w(Re),onPageChange:u,onPageSizeChange:O}},[L,u,O,s,l,g,ie]);return {type:r,dataSource:ie,isLoading:D,loadMore:K,cancelOrder:f,updateOrder:S,cancelAlgoOrder:U,updateAlgoOrder:le,page:l,pageSize:g,setPage:u,setPageSize:O,meta:w(L),pagination:he,manualPagination:s,pnlNotionalDecimalPrecision:a,onFilter:A,filterItems:v,onCancelAll:p,onSymbolChange:i}},va=(e,t)=>{let[r,o]=react.useState(t.ordersStatus??"all"),[i,n]=react.useState(t.filterConfig?.side??"all"),a=t.filterConfig?.range??(e==="all"||e==="orderHistory"?wo({to:new Date,from:Lo(dateFns.subDays(new Date,7))}):{}),[s,d]=react.useState(a),l=u=>{u.name==="side"&&(n(u.value),t.setPage(1)),u.name==="status"&&(o(u.value),t.setPage(1)),u.name==="dateRange"&&(d(wo(u.value)),t.setPage(1));};return {filterItems:react.useMemo(()=>{let u={type:"select",name:"side",options:[{label:"All sides",value:"all"},{label:"Buy",value:"BUY"},{label:"Sell",value:"SELL"}],value:i},O={type:"range",name:"dateRange",value:s},w={type:"select",name:"status",options:[{label:"All status",value:"all"},{label:"Pending",value:types.OrderStatus.INCOMPLETE},{label:"Filled",value:types.OrderStatus.FILLED},{label:"Partial filled",value:types.OrderStatus.PARTIAL_FILLED},{label:"Canceled",value:types.OrderStatus.CANCELLED},{label:"Rejected",value:types.OrderStatus.REJECTED}],value:r};switch(e){case"all":return [u,w,O];case"pending":return [u];case"tp_sl":return [u];case"filled":return [u];case"cancelled":return [u];case"rejected":return [u];case"orderHistory":return [u,w,O]}},[e,i,r,s]),onFilter:l,ordersSide:i==="all"?void 0:i,dateRange:s,orderStatus:r==="all"?void 0:r}};function Ea(e){if(e==null)return e;let t=new Date(e);return t.setHours(0,0,0,0),t}function Lo(e){if(e==null)return e;let t=new Date(e);return t.setHours(23,59,59,999),t}var wo=e=>({from:Ea(e.from),to:Lo(e.to)});var fe=e=>{let t=ut(e);return jsxRuntime.jsx(ir,{...t})},Aa=e=>{let t=ut({...e,enableLoadMore:!0});return jsxRuntime.jsx(nr,{...t,classNames:e.classNames,showFilter:e.showFilter})};var Eo=e=>jsxRuntime.jsxs(ui.Tabs,{defaultValue:e.current||"all",variant:"contained",className:"oui-h-full",classNames:{tabsContent:"oui-h-[calc(100%_-_28px)]"},children:[jsxRuntime.jsx(ui.TabPanel,{value:"all",title:"All",children:jsxRuntime.jsx(fe,{type:"all",pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"pending",title:"Pending",children:jsxRuntime.jsx(fe,{type:"pending",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"tp_sl",title:"TP/SL",children:jsxRuntime.jsx(fe,{type:"tp_sl",ordersStatus:types.OrderStatus.INCOMPLETE,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"filled",title:"Filled",children:jsxRuntime.jsx(fe,{type:"filled",ordersStatus:types.OrderStatus.FILLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"cancelled",title:"Cancelled",children:jsxRuntime.jsx(fe,{type:"cancelled",ordersStatus:types.OrderStatus.CANCELLED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})}),jsxRuntime.jsx(ui.TabPanel,{value:"rejected",title:"Rejected",children:jsxRuntime.jsx(fe,{type:"rejected",ordersStatus:types.OrderStatus.REJECTED,pnlNotionalDecimalPrecision:e.pnlNotionalDecimalPrecision})})]});var ce=(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))(ce||{}),ka=e=>{let t=ct(e);return jsxRuntime.jsx(Eo,{...t})};
13
15
 
14
- exports.OrderList = Te;
15
- exports.OrderListWidget = q;
16
- exports.OrdersWidget = Jr;
17
- exports.TabType = X;
18
- exports.useOrderListScript = Ae;
19
- exports.useOrdersScript = ye;
16
+ exports.DesktopOrderList = ir;
17
+ exports.DesktopOrderListWidget = fe;
18
+ exports.MobileOrderList = nr;
19
+ exports.MobileOrderListWidget = Aa;
20
+ exports.OrdersWidget = ka;
21
+ exports.TabType = ce;
22
+ exports.useOrderListScript = ut;
23
+ exports.useOrdersScript = ct;
20
24
  //# sourceMappingURL=out.js.map
21
25
  //# sourceMappingURL=index.js.map