@orderly.network/ui-orders 2.11.1 → 2.11.2-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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import React2, { forwardRef, useMemo, useEffect, useRef, useImperativeHandle, useCallback, useState, createContext, memo, useContext } from 'react';
2
2
  import { useSymbolsInfo, useOrderStream, useLocalStorage, utils, useThrottledCallback, useMutation, useSWRConfig, useAccount, unstable_serialize, useMemoizedFn, getMinNotional, findTPSLFromOrder, findTPSLOrderPriceFromOrder, useMaxQty, useConfig, useTpslPriceChecker, useOrderEntity, useReferralInfo, useLeverageBySymbol } from '@orderly.network/hooks';
3
3
  import { useTranslation, Trans, i18n } from '@orderly.network/i18n';
4
- import { OrderStatus, AlgoOrderRootType, AlgoOrderType, OrderSide, OrderType, MarginMode, EMPTY_LIST } from '@orderly.network/types';
4
+ import { OrderStatus, AlgoOrderRootType, MarginMode, AlgoOrderType, OrderSide, OrderType, EMPTY_LIST } from '@orderly.network/types';
5
5
  import { formatSymbol, Decimal, commify, commifyOptional, getTrailingStopPrice, formatNum } from '@orderly.network/utils';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import { usePagination, modal, Text, Button, ThrottledButton, CloseIcon, cn, Flex, Input, inputFormatter, Slider, DataFilter, TableFeatures, Grid, Picker, ListView, Tabs, TabPanel, Badge, Tooltip, EditIcon, toast as toast$1, Popover, PopoverRoot, PopoverTrigger, PopoverContent, Divider, ShareIcon, CheckIcon, Statistic, SimpleDialog, useModal, Checkbox } from '@orderly.network/ui';
@@ -41,67 +41,10 @@ var init_orders_script = __esm({
41
41
  }
42
42
  });
43
43
  function parseBadgesFor(record) {
44
- const orderType = record.type;
45
- const algoType = record.algo_type;
46
- if (typeof orderType !== "undefined") {
47
- const list = [];
48
- if (!!record.parent_algo_type) {
49
- if (algoType === AlgoOrderType.STOP_LOSS) {
50
- const types = orderType === OrderType.CLOSE_POSITION ? [i18n.t("common.position"), i18n.t("tpsl.sl")] : [i18n.t("tpsl.sl")];
51
- list.push(...types);
52
- }
53
- if (algoType === AlgoOrderType.TAKE_PROFIT) {
54
- const types = orderType === OrderType.CLOSE_POSITION ? [i18n.t("common.position"), i18n.t("tpsl.tp")] : [i18n.t("tpsl.tp")];
55
- list.push(...types);
56
- }
57
- return list;
58
- }
59
- const type = typeof orderType === "string" ? orderType.replace("_ORDER", "") : "";
60
- if ([OrderType.ASK, OrderType.BID].includes(orderType)) {
61
- return [i18n.t("orderEntry.orderType.limit")];
62
- }
63
- if (record.algo_order_id === void 0 || record.algo_order_id && algoType === "BRACKET") {
64
- const typeMap = {
65
- [OrderType.LIMIT]: i18n.t("orderEntry.orderType.limit"),
66
- [OrderType.MARKET]: i18n.t("orderEntry.orderType.market"),
67
- [OrderType.POST_ONLY]: i18n.t("orderEntry.orderType.postOnly"),
68
- [OrderType.IOC]: i18n.t("orderEntry.orderType.ioc"),
69
- [OrderType.FOK]: i18n.t("orderEntry.orderType.fok")
70
- };
71
- return [
72
- typeMap[type] || upperCaseFirstLetter(type)
73
- ];
74
- }
75
- if (algoType === AlgoOrderRootType.TRAILING_STOP) {
76
- return [i18n.t("orderEntry.orderType.trailingStop")];
77
- }
78
- if (type) {
79
- const typeMap = {
80
- [OrderType.LIMIT]: i18n.t("orderEntry.orderType.stopLimit"),
81
- [OrderType.MARKET]: i18n.t("orderEntry.orderType.stopMarket")
82
- };
83
- return [typeMap[type] || type];
84
- }
85
- }
86
- if (typeof algoType !== "undefined") {
87
- const list = [];
88
- if (algoType === AlgoOrderRootType.POSITIONAL_TP_SL) {
89
- list.push(i18n.t("common.position"));
90
- }
91
- const tpOrder = record?.child_orders?.find(
92
- (order) => order.algo_type === AlgoOrderType.TAKE_PROFIT && !!order.trigger_price
93
- );
94
- const slOrder = record?.child_orders?.find(
95
- (order) => order.algo_type === AlgoOrderType.STOP_LOSS && !!order.trigger_price
96
- );
97
- if (tpOrder || slOrder) {
98
- list.push(
99
- tpOrder && slOrder ? i18n.t("common.tpsl") : tpOrder ? i18n.t("tpsl.tp") : i18n.t("tpsl.sl")
100
- );
101
- }
102
- return list;
103
- }
104
- return void 0;
44
+ const orderTypeBadges = getOrderTypeBadges(record);
45
+ const marginModeBadges = getMarginModeBadges(record);
46
+ const badges = [...orderTypeBadges, ...marginModeBadges];
47
+ return badges.length ? badges : void 0;
105
48
  }
106
49
  function grayCell(record) {
107
50
  return record.status === OrderStatus.CANCELLED || record.algo_status === OrderStatus.CANCELLED;
@@ -205,7 +148,7 @@ function convertApiOrderTypeToOrderEntryType(order) {
205
148
  }
206
149
  return order.type;
207
150
  }
208
- var upperCaseFirstLetter;
151
+ var upperCaseFirstLetter, normalizeMarginMode, getMarginModeBadges, getOrderTypeBadges;
209
152
  var init_util = __esm({
210
153
  "src/utils/util.ts"() {
211
154
  upperCaseFirstLetter = (str) => {
@@ -214,6 +157,88 @@ var init_util = __esm({
214
157
  if (str.length === 1) return str.charAt(0).toUpperCase();
215
158
  return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
216
159
  };
160
+ normalizeMarginMode = (value) => {
161
+ if (value === 1 || value === MarginMode.ISOLATED) {
162
+ return MarginMode.ISOLATED;
163
+ }
164
+ if (value === 0 || value === MarginMode.CROSS) {
165
+ return MarginMode.CROSS;
166
+ }
167
+ return void 0;
168
+ };
169
+ getMarginModeBadges = (record) => {
170
+ const marginMode = normalizeMarginMode(record?.margin_mode);
171
+ if (marginMode === MarginMode.ISOLATED) {
172
+ return [i18n.t("marginMode.isolated")];
173
+ }
174
+ if (marginMode === MarginMode.CROSS) {
175
+ return [i18n.t("marginMode.cross")];
176
+ }
177
+ return [];
178
+ };
179
+ getOrderTypeBadges = (record) => {
180
+ const orderType = record.type;
181
+ const algoType = record.algo_type;
182
+ if (typeof orderType !== "undefined") {
183
+ const list = [];
184
+ if (!!record.parent_algo_type) {
185
+ if (algoType === AlgoOrderType.STOP_LOSS) {
186
+ const types = orderType === OrderType.CLOSE_POSITION ? [i18n.t("common.position"), i18n.t("tpsl.sl")] : [i18n.t("tpsl.sl")];
187
+ list.push(...types);
188
+ }
189
+ if (algoType === AlgoOrderType.TAKE_PROFIT) {
190
+ const types = orderType === OrderType.CLOSE_POSITION ? [i18n.t("common.position"), i18n.t("tpsl.tp")] : [i18n.t("tpsl.tp")];
191
+ list.push(...types);
192
+ }
193
+ return list;
194
+ }
195
+ const type = typeof orderType === "string" ? orderType.replace("_ORDER", "") : "";
196
+ if ([OrderType.ASK, OrderType.BID].includes(orderType)) {
197
+ return [i18n.t("orderEntry.orderType.limit")];
198
+ }
199
+ if (record.algo_order_id === void 0 || record.algo_order_id && algoType === "BRACKET") {
200
+ const typeMap = {
201
+ [OrderType.LIMIT]: i18n.t("orderEntry.orderType.limit"),
202
+ [OrderType.MARKET]: i18n.t("orderEntry.orderType.market"),
203
+ [OrderType.POST_ONLY]: i18n.t("orderEntry.orderType.postOnly"),
204
+ [OrderType.IOC]: i18n.t("orderEntry.orderType.ioc"),
205
+ [OrderType.FOK]: i18n.t("orderEntry.orderType.fok")
206
+ };
207
+ return [
208
+ typeMap[type] || upperCaseFirstLetter(type)
209
+ ];
210
+ }
211
+ if (algoType === AlgoOrderRootType.TRAILING_STOP) {
212
+ return [i18n.t("orderEntry.orderType.trailingStop")];
213
+ }
214
+ if (type) {
215
+ const typeMap = {
216
+ [OrderType.LIMIT]: i18n.t("orderEntry.orderType.stopLimit"),
217
+ [OrderType.MARKET]: i18n.t("orderEntry.orderType.stopMarket")
218
+ };
219
+ return [typeMap[type] || type];
220
+ }
221
+ }
222
+ if (typeof algoType !== "undefined") {
223
+ const list = [];
224
+ if (algoType === AlgoOrderRootType.POSITIONAL_TP_SL) {
225
+ list.push(i18n.t("common.position"));
226
+ }
227
+ const tpOrder = record?.child_orders?.find(
228
+ (order) => order.algo_type === AlgoOrderType.TAKE_PROFIT && !!order.trigger_price
229
+ );
230
+ const slOrder = record?.child_orders?.find(
231
+ (order) => order.algo_type === AlgoOrderType.STOP_LOSS && !!order.trigger_price
232
+ );
233
+ if (tpOrder || slOrder) {
234
+ list.push(
235
+ tpOrder && slOrder ? i18n.t("common.tpsl") : tpOrder ? i18n.t("tpsl.tp") : i18n.t("tpsl.sl")
236
+ );
237
+ }
238
+ return list;
239
+ }
240
+ return [];
241
+ };
217
242
  }
218
243
  });
219
244
  var SymbolContext, useSymbolContext;
@@ -1143,10 +1168,10 @@ var init_tpslOrderRowContext = __esm({
1143
1168
  }
1144
1169
  );
1145
1170
  const getRelatedPosition = useMemoizedFn(
1146
- (symbol) => {
1171
+ (symbol, marginMode) => {
1147
1172
  const positions = config.cache.get(positionKey);
1148
1173
  return positions?.data?.rows?.find(
1149
- (p) => p.symbol === symbol
1174
+ (p) => p.symbol === symbol && (p.margin_mode ?? MarginMode.CROSS) === (marginMode ?? MarginMode.CROSS)
1150
1175
  );
1151
1176
  }
1152
1177
  );
@@ -1164,12 +1189,12 @@ var init_tpslOrderRowContext = __esm({
1164
1189
  });
1165
1190
  useEffect(() => {
1166
1191
  if ("algo_type" in order || (order?.reduce_only ?? false)) {
1167
- const position2 = getRelatedPosition(order.symbol);
1192
+ const position2 = getRelatedPosition(order.symbol, order.margin_mode);
1168
1193
  if (position2) {
1169
1194
  setPosition(position2);
1170
1195
  }
1171
1196
  }
1172
- }, [order.symbol]);
1197
+ }, [getRelatedPosition, order.margin_mode, order.symbol]);
1173
1198
  const memoizedValue = useMemo(() => {
1174
1199
  return {
1175
1200
  order,
@@ -2355,7 +2380,7 @@ function instrument(option) {
2355
2380
  },
2356
2381
  render: (value, record) => {
2357
2382
  const showGray = grayCell(record);
2358
- return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
2383
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, className: "oui-py-1", children: [
2359
2384
  /* @__PURE__ */ jsx(
2360
2385
  "div",
2361
2386
  {
@@ -2365,7 +2390,7 @@ function instrument(option) {
2365
2390
  )
2366
2391
  }
2367
2392
  ),
2368
- /* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", children: [
2393
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", gap: 1, children: [
2369
2394
  /* @__PURE__ */ jsx(
2370
2395
  Text.formatted,
2371
2396
  {
@@ -2379,7 +2404,7 @@ function instrument(option) {
2379
2404
  children: `${value.split("_")[1]}-PERP`
2380
2405
  }
2381
2406
  ),
2382
- option?.showType && /* @__PURE__ */ jsx(Flex, { direction: "row", gap: 1, children: parseBadgesFor(record)?.map((e, index) => /* @__PURE__ */ jsx(
2407
+ option?.showType && /* @__PURE__ */ jsx(Flex, { direction: "row", gap: 1, wrap: "wrap", children: parseBadgesFor(record)?.map((e, index) => /* @__PURE__ */ jsx(
2383
2408
  Badge,
2384
2409
  {
2385
2410
  color: e.toLocaleLowerCase() === "position" ? showGray ? "neutral" : "primary" : "neutral",
@@ -2925,7 +2950,7 @@ var init_useColumn = __esm({
2925
2950
  case "all" /* all */:
2926
2951
  return [
2927
2952
  instrument({
2928
- width: 130,
2953
+ width: 174,
2929
2954
  showType: true,
2930
2955
  onSymbolChange,
2931
2956
  enableSort: false
@@ -3005,7 +3030,7 @@ var init_useColumn = __esm({
3005
3030
  return [
3006
3031
  instrument({
3007
3032
  showType: true,
3008
- width: 154,
3033
+ width: 166,
3009
3034
  onSymbolChange
3010
3035
  }),
3011
3036
  // type({ width: 124 }),
@@ -3087,7 +3112,7 @@ var init_useColumn = __esm({
3087
3112
  return [
3088
3113
  instrument({
3089
3114
  showType: true,
3090
- width: 154,
3115
+ width: 160,
3091
3116
  onSymbolChange
3092
3117
  }),
3093
3118
  // side({ width: 124 }),
@@ -5391,15 +5416,21 @@ var init_useFormatOrderHistory = __esm({
5391
5416
  if (!e.is_activated || !e.trigger_price) {
5392
5417
  continue;
5393
5418
  }
5394
- e.parent_algo_type = element.algo_type;
5395
- _data.push(e);
5419
+ _data.push({
5420
+ ...e,
5421
+ parent_algo_type: element.algo_type,
5422
+ margin_mode: e.margin_mode ?? element.margin_mode
5423
+ });
5396
5424
  }
5397
5425
  } else {
5398
5426
  for (let j = 0; j < element.child_orders.length; j++) {
5399
5427
  const e = element.child_orders[j];
5400
5428
  if (!!e && (e.algo_status === OrderStatus.FILLED || e.algo_status === OrderStatus.PARTIAL_FILLED)) {
5401
- e.parent_algo_type = element.algo_type;
5402
- _data.push(e);
5429
+ _data.push({
5430
+ ...e,
5431
+ parent_algo_type: element.algo_type,
5432
+ margin_mode: e.margin_mode ?? element.margin_mode
5433
+ });
5403
5434
  }
5404
5435
  }
5405
5436
  }