@orderly.network/ui-tpsl 3.0.0-beta.0 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +43 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import { SDKError, MarginMode, PositionType, AlgoOrderRootType, OrderType, OrderSide, OrderStatus, AlgoOrderType } from '@orderly.network/types';
|
|
2
|
-
import { Flex, Input, inputFormatter, cn, Slider, Text, registerSimpleSheet, registerSimpleDialog, useScreen, ScrollArea, DotStatus, Grid, Button, ThrottledButton, Divider, Box, toast, TokenIcon,
|
|
2
|
+
import { Flex, Input, inputFormatter, cn, Slider, Text, registerSimpleSheet, registerSimpleDialog, useScreen, ScrollArea, DotStatus, Grid, Button, ThrottledButton, Divider, Box, toast, TokenIcon, modal, SymbolBadge as SymbolBadge$1, Tooltip, ExclamationFillIcon, Select, ChevronDownIcon, Badge, textVariants, Checkbox, SimpleDropdownMenu, CaretDownIcon, useModal } from '@orderly.network/ui';
|
|
3
3
|
import { memo, useRef, useState, useEffect, createContext, useMemo, useContext, Fragment as Fragment$1 } from 'react';
|
|
4
|
-
import { utils, useSymbolsInfo, useAccount, useEventEmitter, useLocalStorage, useMarginModeBySymbol, usePositionStream, useEstLiqPriceBySymbol, useTPSLOrder, useTpslPriceChecker, ERROR_MSG_CODES, useMemoizedFn, useOrderEntry, useGetEstLiqPrice, useOrderStream, useSubAccountAlgoOrderStream, findPositionTPSLFromOrders, useMutation, useMarkPrice, useIndexPrice, useLeverageBySymbol, useMaxQty, findTPSLFromOrder, findTPSLOrderPriceFromOrder } from '@orderly.network/hooks';
|
|
4
|
+
import { utils, useSymbolsInfo, useAccount, useEventEmitter, useLocalStorage, useMarginModeBySymbol, usePositionStream, useEstLiqPriceBySymbol, useTPSLOrder, useTpslPriceChecker, ERROR_MSG_CODES, useMemoizedFn, useOrderEntry, useGetEstLiqPrice, useOrderStream, useSubAccountAlgoOrderStream, findPositionTPSLFromOrders, useMutation, useMarkPrice, useIndexPrice, useLeverageBySymbol, useMaxQty, useBadgeBySymbol, useSymbolWithBroker, findTPSLFromOrder, findTPSLOrderPriceFromOrder } from '@orderly.network/hooks';
|
|
5
5
|
import { useTranslation, i18n, Trans } from '@orderly.network/i18n';
|
|
6
6
|
import { useOrderEntryFormErrorMsg } from '@orderly.network/react-app';
|
|
7
7
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
8
|
-
import { Decimal, checkIsNaN,
|
|
8
|
+
import { Decimal, checkIsNaN, getTPSLDirection, formatNum, todpIfNeed } from '@orderly.network/utils';
|
|
9
9
|
import { order, positions } from '@orderly.network/perp';
|
|
10
10
|
import { AuthGuardDataTable } from '@orderly.network/ui-connector';
|
|
11
11
|
|
|
12
12
|
// src/editorPopover.tsx
|
|
13
|
+
var SymbolBadge = (props) => {
|
|
14
|
+
const { brokerId, brokerName, brokerNameRaw } = useBadgeBySymbol(
|
|
15
|
+
props.symbol
|
|
16
|
+
);
|
|
17
|
+
const badge = brokerName ?? brokerId ?? void 0;
|
|
18
|
+
return /* @__PURE__ */ jsx(SymbolBadge$1, { badge, fullName: brokerNameRaw });
|
|
19
|
+
};
|
|
13
20
|
var OrderInfo = (props) => {
|
|
14
21
|
const { t } = useTranslation();
|
|
15
22
|
const { order: order2, symbolLeverage } = props;
|
|
16
23
|
const { symbol } = order2;
|
|
17
24
|
const markPrice = useMarkPrice(symbol);
|
|
18
25
|
const indexPrice = useIndexPrice(symbol);
|
|
26
|
+
const marginModeLabel = props.marginMode === MarginMode.ISOLATED ? t("marginMode.isolated") : props.marginMode === MarginMode.CROSS ? t("marginMode.cross") : void 0;
|
|
19
27
|
const leverage = useLeverageBySymbol(
|
|
20
28
|
symbolLeverage ? void 0 : symbol,
|
|
21
29
|
props.marginMode
|
|
@@ -44,20 +52,21 @@ var OrderInfo = (props) => {
|
|
|
44
52
|
{
|
|
45
53
|
className: "oui-whitespace-nowrap oui-break-normal",
|
|
46
54
|
rule: "symbol",
|
|
47
|
-
formatString: "base
|
|
55
|
+
formatString: "base",
|
|
48
56
|
size: "sm",
|
|
49
57
|
weight: "semibold",
|
|
50
58
|
intensity: 98,
|
|
59
|
+
suffix: /* @__PURE__ */ jsx(SymbolBadge, { symbol: symbol ?? "" }),
|
|
51
60
|
children: symbol
|
|
52
61
|
}
|
|
53
62
|
)
|
|
54
63
|
] }),
|
|
55
|
-
|
|
64
|
+
marginModeLabel && /* @__PURE__ */ jsx(
|
|
56
65
|
Text,
|
|
57
66
|
{
|
|
58
67
|
size: "2xs",
|
|
59
68
|
className: "oui-h-[18px] oui-rounded oui-bg-base-7 oui-px-2 oui-font-semibold oui-text-base-contrast-36",
|
|
60
|
-
children:
|
|
69
|
+
children: marginModeLabel
|
|
61
70
|
}
|
|
62
71
|
),
|
|
63
72
|
/* @__PURE__ */ jsxs(
|
|
@@ -253,6 +262,7 @@ var useTPSLInputRowScript = (props) => {
|
|
|
253
262
|
});
|
|
254
263
|
return roi2 * 100;
|
|
255
264
|
} catch (error) {
|
|
265
|
+
console.error("error", error);
|
|
256
266
|
return null;
|
|
257
267
|
}
|
|
258
268
|
}, [values, leverage, rootOrderPrice, type, side]);
|
|
@@ -829,10 +839,10 @@ var TPSLQuantity = memo((props) => {
|
|
|
829
839
|
tooltip: errorMsg,
|
|
830
840
|
color: errorMsg ? "danger" : void 0,
|
|
831
841
|
formatters: [
|
|
842
|
+
inputFormatter.decimalPointFormatter,
|
|
832
843
|
inputFormatter.dpFormatter(props.base_dp),
|
|
833
844
|
inputFormatter.numberFormatter,
|
|
834
|
-
inputFormatter.currencyFormatter
|
|
835
|
-
inputFormatter.decimalPointFormatter
|
|
845
|
+
inputFormatter.currencyFormatter
|
|
836
846
|
],
|
|
837
847
|
onValueChange: (value) => {
|
|
838
848
|
props.onQuantityChange?.(value);
|
|
@@ -1104,6 +1114,7 @@ var TPSL = (props) => {
|
|
|
1104
1114
|
props.close?.();
|
|
1105
1115
|
onComplete?.();
|
|
1106
1116
|
}).catch((err) => {
|
|
1117
|
+
console.log("--->>>cancel order", err);
|
|
1107
1118
|
});
|
|
1108
1119
|
},
|
|
1109
1120
|
children: t("common.confirm")
|
|
@@ -1182,21 +1193,25 @@ var PositionTPSLConfirm = (props) => {
|
|
|
1182
1193
|
);
|
|
1183
1194
|
};
|
|
1184
1195
|
const isPositionTPSL = _isPositionTPSL;
|
|
1196
|
+
const displaySymbol = useSymbolWithBroker(symbol);
|
|
1185
1197
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1186
|
-
isEditing && /* @__PURE__ */ jsx(Text, { as: "div", size: "2xs", intensity: 80, className: "oui-mb-3", children: t("tpsl.agreement", { symbol:
|
|
1198
|
+
isEditing && /* @__PURE__ */ jsx(Text, { as: "div", size: "2xs", intensity: 80, className: "oui-mb-3", children: t("tpsl.agreement", { symbol: displaySymbol }) }),
|
|
1187
1199
|
/* @__PURE__ */ jsxs(Flex, { pb: 4, children: [
|
|
1188
|
-
/* @__PURE__ */
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", itemAlign: "start", gap: 1, grow: true, children: [
|
|
1201
|
+
/* @__PURE__ */ jsx(Box, { grow: true, children: /* @__PURE__ */ jsx(
|
|
1202
|
+
Text.formatted,
|
|
1203
|
+
{
|
|
1204
|
+
rule: "symbol",
|
|
1205
|
+
formatString: "base",
|
|
1206
|
+
size: "base",
|
|
1207
|
+
showIcon: true,
|
|
1208
|
+
as: "div",
|
|
1209
|
+
intensity: 80,
|
|
1210
|
+
children: symbol
|
|
1211
|
+
}
|
|
1212
|
+
) }),
|
|
1213
|
+
/* @__PURE__ */ jsx(SymbolBadge, { symbol })
|
|
1214
|
+
] }),
|
|
1200
1215
|
/* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
|
|
1201
1216
|
isPositionTPSL && /* @__PURE__ */ jsx(Badge, { size: "xs", color: "primary", children: t("common.position") }),
|
|
1202
1217
|
/* @__PURE__ */ jsx(TPSLOrderType, { tpPrice, slPrice }),
|
|
@@ -1341,9 +1356,10 @@ var useTPSLBuilder = (options) => {
|
|
|
1341
1356
|
const [needConfirm] = useLocalStorage("orderly_order_confirm", true);
|
|
1342
1357
|
const { marginMode: symbolMarginMode } = useMarginModeBySymbol(symbol);
|
|
1343
1358
|
const [{ rows: positions }] = usePositionStream();
|
|
1344
|
-
const mainAccountPosition = positions.find(
|
|
1345
|
-
|
|
1346
|
-
|
|
1359
|
+
const mainAccountPosition = positions.find((item) => {
|
|
1360
|
+
const marginMode = options.position?.margin_mode ?? symbolMarginMode;
|
|
1361
|
+
return item.symbol === symbol && item.margin_mode === marginMode;
|
|
1362
|
+
});
|
|
1347
1363
|
const isSubAccount = options.position?.account_id && options.position?.account_id !== state.mainAccountId;
|
|
1348
1364
|
const position = isSubAccount ? options.position : mainAccountPosition;
|
|
1349
1365
|
const estLiqPrice = useEstLiqPriceBySymbol(
|
|
@@ -1951,6 +1967,8 @@ var useTPSLAdvanced = (props) => {
|
|
|
1951
1967
|
helper.validate(isSlPriceError ? slPriceError : void 0).then(() => {
|
|
1952
1968
|
props.onSubmit(formattedOrder);
|
|
1953
1969
|
}).catch((err) => {
|
|
1970
|
+
console.log("metaState", metaState);
|
|
1971
|
+
console.log("err", err);
|
|
1954
1972
|
});
|
|
1955
1973
|
};
|
|
1956
1974
|
return {
|
|
@@ -2616,6 +2634,7 @@ var TPSLDetailUI = (props) => {
|
|
|
2616
2634
|
symbolInfo
|
|
2617
2635
|
} = props;
|
|
2618
2636
|
const { estLiqPrice } = useTPSLDetailContext();
|
|
2637
|
+
console.log("----- position", position);
|
|
2619
2638
|
return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(ScrollArea, { className: cn(isMobile && "oui-h-[calc(100vh-100px)]"), children: [
|
|
2620
2639
|
/* @__PURE__ */ jsx(
|
|
2621
2640
|
OrderInfo,
|
|
@@ -2910,9 +2929,8 @@ registerSimpleSheet(TPSLDetailSheetId, TPSLDetailWidget, {
|
|
|
2910
2929
|
}
|
|
2911
2930
|
});
|
|
2912
2931
|
var useTPSLSimpleDialog = (options) => {
|
|
2913
|
-
const { type, triggerPrice, symbol } = options;
|
|
2932
|
+
const { type, triggerPrice, symbol, marginMode } = options;
|
|
2914
2933
|
const symbolInfo = useSymbolsInfo();
|
|
2915
|
-
const { marginMode } = useMarginModeBySymbol(symbol ?? "");
|
|
2916
2934
|
const [{ rows: positions }, positionsInfo] = usePositionStream(symbol);
|
|
2917
2935
|
const position = positions?.find((item) => item.margin_mode === marginMode);
|
|
2918
2936
|
useRef(AlgoOrderRootType.TP_SL);
|
|
@@ -3162,7 +3180,7 @@ var TPSLSimpleDialogUI = (props) => {
|
|
|
3162
3180
|
TPSLQuantity,
|
|
3163
3181
|
{
|
|
3164
3182
|
maxQty: props.maxQty,
|
|
3165
|
-
quantity:
|
|
3183
|
+
quantity: props.orderQuantity ?? props.maxQty,
|
|
3166
3184
|
baseTick: props.symbolInfo("base_tick"),
|
|
3167
3185
|
base_dp: props.symbolInfo("base_dp"),
|
|
3168
3186
|
base: props.symbolInfo("base"),
|
|
@@ -3631,6 +3649,7 @@ var EditBracketOrderUI = (props) => {
|
|
|
3631
3649
|
props.onSubmit().then(() => {
|
|
3632
3650
|
props.onClose?.();
|
|
3633
3651
|
}).catch((err) => {
|
|
3652
|
+
console.log("--->>>cancel order", err);
|
|
3634
3653
|
});
|
|
3635
3654
|
},
|
|
3636
3655
|
children: t("common.confirm")
|