@orderly.network/ui-order-entry 2.8.5 → 2.8.6-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,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import react__default, { FC } from 'react';
3
- import * as _orderly_network_hooks from '@orderly.network/hooks';
4
3
  import * as _orderly_network_types from '@orderly.network/types';
5
4
  import { OrderSide, OrderType, OrderLevel, OrderlyOrder, API } from '@orderly.network/types';
5
+ import * as _orderly_network_hooks from '@orderly.network/hooks';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
 
8
8
  declare enum InputType {
@@ -39,6 +39,7 @@ type OrderEntryScriptInputs = {
39
39
  };
40
40
  type OrderEntryScriptReturn = ReturnType<typeof useOrderEntryScript>;
41
41
  declare const useOrderEntryScript: (inputs: OrderEntryScriptInputs) => {
42
+ slPriceError: _orderly_network_hooks.OrderValidationResult | undefined;
42
43
  side: OrderSide;
43
44
  type: OrderType;
44
45
  level: OrderLevel;
@@ -86,7 +87,7 @@ declare const useOrderEntryScript: (inputs: OrderEntryScriptInputs) => {
86
87
  estSlippage: number | null;
87
88
  helper: {
88
89
  validator: () => Promise<_orderly_network_hooks.OrderValidationResult | null>;
89
- validate: () => Promise<_orderly_network_hooks.OrderValidationResult | null>;
90
+ validate: (otherErrors?: _orderly_network_hooks.OrderValidationResult) => Promise<_orderly_network_hooks.OrderValidationResult | null>;
90
91
  };
91
92
  freeCollateral: number;
92
93
  metaState: {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import react__default, { FC } from 'react';
3
- import * as _orderly_network_hooks from '@orderly.network/hooks';
4
3
  import * as _orderly_network_types from '@orderly.network/types';
5
4
  import { OrderSide, OrderType, OrderLevel, OrderlyOrder, API } from '@orderly.network/types';
5
+ import * as _orderly_network_hooks from '@orderly.network/hooks';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
 
8
8
  declare enum InputType {
@@ -39,6 +39,7 @@ type OrderEntryScriptInputs = {
39
39
  };
40
40
  type OrderEntryScriptReturn = ReturnType<typeof useOrderEntryScript>;
41
41
  declare const useOrderEntryScript: (inputs: OrderEntryScriptInputs) => {
42
+ slPriceError: _orderly_network_hooks.OrderValidationResult | undefined;
42
43
  side: OrderSide;
43
44
  type: OrderType;
44
45
  level: OrderLevel;
@@ -86,7 +87,7 @@ declare const useOrderEntryScript: (inputs: OrderEntryScriptInputs) => {
86
87
  estSlippage: number | null;
87
88
  helper: {
88
89
  validator: () => Promise<_orderly_network_hooks.OrderValidationResult | null>;
89
- validate: () => Promise<_orderly_network_hooks.OrderValidationResult | null>;
90
+ validate: (otherErrors?: _orderly_network_hooks.OrderValidationResult) => Promise<_orderly_network_hooks.OrderValidationResult | null>;
90
91
  };
91
92
  freeCollateral: number;
92
93
  metaState: {
package/dist/index.js CHANGED
@@ -1052,6 +1052,7 @@ var LTVRiskTooltipWidget = () => {
1052
1052
  var Available = (props) => {
1053
1053
  const { canTrade, currentLtv, quote, freeCollateral } = props;
1054
1054
  const { t } = i18n.useTranslation();
1055
+ const { isMobile } = ui.useScreen();
1055
1056
  const showLTV = React3.useMemo(() => {
1056
1057
  return typeof currentLtv === "number" && !Number.isNaN(currentLtv) && currentLtv > 0;
1057
1058
  }, [currentLtv]);
@@ -1091,7 +1092,8 @@ var Available = (props) => {
1091
1092
  color: "secondary",
1092
1093
  className: "oui-p-0 hover:oui-text-base-contrast-80",
1093
1094
  onClick: () => {
1094
- ui.modal.show("DepositAndWithdrawWithDialogId", {
1095
+ const handleDomId = isMobile ? "DepositAndWithdrawWithSheetId" : "DepositAndWithdrawWithDialogId";
1096
+ ui.modal.show(handleDomId, {
1095
1097
  activeTab: "deposit"
1096
1098
  });
1097
1099
  },
@@ -3775,8 +3777,10 @@ var OrderTPSL = (props) => {
3775
3777
  props.onSwitchChanged(false);
3776
3778
  }
3777
3779
  }, [props.orderType]);
3778
- if (props.orderType !== types.OrderType.LIMIT && props.orderType !== types.OrderType.MARKET || props.isReduceOnly)
3780
+ if (props.orderType !== types.OrderType.LIMIT && props.orderType !== types.OrderType.MARKET) {
3779
3781
  return null;
3782
+ }
3783
+ const isSlPriceWarning = props.errors?.["sl_trigger_price"]?.["type"] === hooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
3780
3784
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3781
3785
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { itemAlign: "center", justify: "between", children: [
3782
3786
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { itemAlign: "center", gapX: 1, children: [
@@ -3786,7 +3790,7 @@ var OrderTPSL = (props) => {
3786
3790
  id: "order_entry_tpsl",
3787
3791
  className: "oui-h-[14px]",
3788
3792
  checked: props.switchState,
3789
- disabled: props.orderType !== types.OrderType.LIMIT && props.orderType !== types.OrderType.MARKET || props.isReduceOnly,
3793
+ disabled: props.orderType !== types.OrderType.LIMIT && props.orderType !== types.OrderType.MARKET,
3790
3794
  onCheckedChange: (checked) => {
3791
3795
  props.onSwitchChanged(checked);
3792
3796
  }
@@ -3834,16 +3838,29 @@ var OrderTPSL = (props) => {
3834
3838
  setOrderValue: props.setOrderValue,
3835
3839
  onChange: props.onChange,
3836
3840
  values: props.values,
3837
- errors: props.errors,
3841
+ errors: isSlPriceWarning ? {} : props.errors,
3838
3842
  quote_dp: props.quote_dp,
3839
3843
  showTPSLAdvanced: props.showTPSLAdvanced,
3840
- isMobile
3844
+ isMobile,
3845
+ isSlPriceWarning
3841
3846
  }
3842
3847
  )
3843
3848
  }
3844
- )
3849
+ ),
3850
+ isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(TPSLPriceWarning, { errors: props.errors })
3845
3851
  ] });
3846
3852
  };
3853
+ var TPSLPriceWarning = (props) => {
3854
+ const { getErrorMsg } = reactApp.useOrderEntryFormErrorMsg(props.errors);
3855
+ return /* @__PURE__ */ jsxRuntime.jsx(
3856
+ ui.DotStatus,
3857
+ {
3858
+ color: "warning",
3859
+ size: "xs",
3860
+ label: getErrorMsg("sl_trigger_price")
3861
+ }
3862
+ );
3863
+ };
3847
3864
  var TPSLInputForm = React3__default.default.forwardRef((props, ref) => {
3848
3865
  const { getErrorMsg } = reactApp.useOrderEntryFormErrorMsg(props.errors);
3849
3866
  const { t } = i18n.useTranslation();
@@ -3896,6 +3913,9 @@ var TPSLInputForm = React3__default.default.forwardRef((props, ref) => {
3896
3913
  first: "oui-testid-orderEntry-tpsl-slPrice-input",
3897
3914
  second: "oui-testid-orderEntry-tpsl-slPnl-input",
3898
3915
  dropDown: "oui-testid-orderEntry-tpsl-sl-dropDown-trigger-button"
3916
+ },
3917
+ classNames: {
3918
+ root: props.isSlPriceWarning ? "oui-outline-warning-darken focus-within:oui-outline-warning-darken" : void 0
3899
3919
  }
3900
3920
  }
3901
3921
  ) })
@@ -4012,8 +4032,12 @@ var TPSLTriggerPriceInput = (props) => {
4012
4032
  value: innerValue,
4013
4033
  classNames: {
4014
4034
  additional: "oui-text-base-contrast-54",
4015
- root: "oui-pr-2 md:oui-pr-3",
4016
- prefix: "oui-pr-1 md:oui-pr-2"
4035
+ root: ui.cn("oui-pr-2 md:oui-pr-3", props.classNames?.root),
4036
+ prefix: ui.cn("oui-pr-1 md:oui-pr-2", props.classNames?.prefix),
4037
+ input: ui.cn(
4038
+ "oui-text-2xs placeholder:oui-text-2xs",
4039
+ props.classNames?.input
4040
+ )
4017
4041
  },
4018
4042
  onValueChange,
4019
4043
  formatters: [
@@ -4033,6 +4057,7 @@ var TPSLInputRow = (props) => {
4033
4057
  type: props.type,
4034
4058
  error: props.error,
4035
4059
  values: props.values ?? "",
4060
+ classNames: props.classNames,
4036
4061
  onChange: (event) => {
4037
4062
  props.onChange(
4038
4063
  props.type === "SL" ? "sl_trigger_price" : "tp_trigger_price",
@@ -4109,6 +4134,7 @@ var OrderEntry = (props) => {
4109
4134
  });
4110
4135
  const { notification } = hooks.useOrderlyContext();
4111
4136
  const soundAlertId = React3.useId();
4137
+ const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
4112
4138
  const { getErrorMsg } = reactApp.useOrderEntryFormErrorMsg(validated ? errors : null);
4113
4139
  const buttonLabel = React3.useMemo(() => {
4114
4140
  return side === types.OrderSide.BUY ? t("orderEntry.buyLong") : t("orderEntry.sellShort");
@@ -4152,7 +4178,8 @@ var OrderEntry = (props) => {
4152
4178
  }, [errorMsgVisible]);
4153
4179
  const onSubmit = hooks.useMemoizedFn(async () => {
4154
4180
  const isScaledOrder = formattedOrder.order_type === types.OrderType.SCALED;
4155
- helper.validate().then(
4181
+ const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
4182
+ helper.validate(isSlPriceError ? props.slPriceError : void 0).then(
4156
4183
  // validate success, it return the order
4157
4184
  // TODO: get order from other function
4158
4185
  (order) => {
@@ -4284,6 +4311,7 @@ var OrderEntry = (props) => {
4284
4311
  React3.useEffect(() => {
4285
4312
  setHasAdvancedTPSLResult(false);
4286
4313
  }, [props.symbol]);
4314
+ const showReduceOnlySection = isMobile && formattedOrder.order_type !== types.OrderType.LIMIT && formattedOrder.order_type !== types.OrderType.MARKET || !isMobile;
4287
4315
  const showSoundSection = Boolean(notification?.orderFilled?.media) && (notification?.orderFilled?.displayInOrderEntry ?? true);
4288
4316
  const additionalInfoProps = {
4289
4317
  pinned,
@@ -4428,8 +4456,7 @@ var OrderEntry = (props) => {
4428
4456
  switchState: props.tpslSwitch,
4429
4457
  onSwitchChanged: props.setTpslSwitch,
4430
4458
  orderType: formattedOrder.order_type,
4431
- errors: validated ? errors : null,
4432
- isReduceOnly: formattedOrder.reduce_only,
4459
+ errors: validated || isSlPriceWarning ? { ...errors, ...props.slPriceError } : null,
4433
4460
  setOrderValue,
4434
4461
  reduceOnlyChecked: formattedOrder.reduce_only ?? false,
4435
4462
  onReduceOnlyChange: (checked) => {
@@ -4458,7 +4485,7 @@ var OrderEntry = (props) => {
4458
4485
  }
4459
4486
  }
4460
4487
  ),
4461
- (isMobile && (formattedOrder.order_type !== types.OrderType.LIMIT && formattedOrder.order_type !== types.OrderType.MARKET || formattedOrder.reduce_only) || !isMobile) && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", itemAlign: "center", className: "oui-mt-2", children: [
4488
+ showReduceOnlySection && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "between", itemAlign: "center", className: "oui-mt-2", children: [
4462
4489
  /* @__PURE__ */ jsxRuntime.jsx(
4463
4490
  ReduceOnlySwitch,
4464
4491
  {
@@ -4889,8 +4916,24 @@ var useOrderEntryScript = (inputs) => {
4889
4916
  const { priceInputContainerRef, priceInputContainerWidth } = usePriceInputContainer({
4890
4917
  order_type_ext: formattedOrder.order_type_ext
4891
4918
  });
4919
+ const slPriceError = hooks.useTpslPriceChecker({
4920
+ slPrice: formattedOrder.sl_trigger_price,
4921
+ liqPrice: state.estLiqPrice,
4922
+ side: formattedOrder.side
4923
+ });
4924
+ React3.useEffect(() => {
4925
+ if (formattedOrder.reduce_only) {
4926
+ setTpslSwitch(false);
4927
+ }
4928
+ }, [formattedOrder.reduce_only]);
4929
+ React3.useEffect(() => {
4930
+ if (tpslSwitch) {
4931
+ setOrderValue("reduce_only", false);
4932
+ }
4933
+ }, [tpslSwitch]);
4892
4934
  return {
4893
4935
  ...state,
4936
+ slPriceError: slPriceError ?? void 0,
4894
4937
  side: formattedOrder.side,
4895
4938
  type: formattedOrder.order_type,
4896
4939
  level: formattedOrder.level,