@orderly.network/ui-order-entry 2.12.1 → 2.12.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.js CHANGED
@@ -4764,10 +4764,19 @@ var usePnlInputContext = () => {
4764
4764
  };
4765
4765
 
4766
4766
  // src/components/pnlInput/useBuilder.script.ts
4767
+ function normalizeSlPnlForStore(raw) {
4768
+ const v = `${raw}`.replace(/,/g, "").trim();
4769
+ if (v === "" || v === "-") return v;
4770
+ const withoutTrailingDot = v.replace(/\.$/, "");
4771
+ const num = Number(withoutTrailingDot);
4772
+ if (!isNaN(num) && num === 0) return "0";
4773
+ if (v.startsWith("-")) return v;
4774
+ return `-${v}`;
4775
+ }
4767
4776
  var usePNLInputBuilder = (props) => {
4768
4777
  const { type, values, quote_dp } = props;
4769
4778
  const { t } = i18n.useTranslation();
4770
- const [focus, setFocus] = React3.useState(true);
4779
+ const [, setFocus] = React3.useState(true);
4771
4780
  const { mode, setMode, tipsEle } = usePnlInputContext();
4772
4781
  const [tipVisible, setTipVisible] = React3.useState(false);
4773
4782
  const [isFocused, setIsFocused] = React3.useState(false);
@@ -4780,7 +4789,7 @@ var usePNLInputBuilder = (props) => {
4780
4789
  default:
4781
4790
  return `${type.toLowerCase()}_pnl`;
4782
4791
  }
4783
- }, [mode]);
4792
+ }, [mode, type]);
4784
4793
  const [innerValue, setInnerValue] = React3.useState(
4785
4794
  values[mode]
4786
4795
  );
@@ -4819,7 +4828,8 @@ var usePNLInputBuilder = (props) => {
4819
4828
  const percentageSuffix = React3.useRef("");
4820
4829
  const onValueChange = (value) => {
4821
4830
  setInnerValue(value);
4822
- props.onChange(key, value);
4831
+ const outgoing = key === "sl_pnl" ? normalizeSlPnlForStore(value) : value;
4832
+ props.onChange(key, outgoing);
4823
4833
  };
4824
4834
  const onFocus = () => {
4825
4835
  setTipVisible(true);
@@ -4828,17 +4838,16 @@ var usePNLInputBuilder = (props) => {
4828
4838
  const onBlur = () => {
4829
4839
  setTipVisible(false);
4830
4840
  setIsFocused(false);
4831
- props.onChange(key, innerValue);
4841
+ const outgoing = key === "sl_pnl" ? normalizeSlPnlForStore(innerValue) : innerValue;
4842
+ props.onChange(key, outgoing);
4832
4843
  };
4833
4844
  const formatter = (options2) => {
4834
4845
  const { dp = 2 } = options2;
4835
4846
  return {
4836
4847
  onRenderBefore: (value, options3) => {
4837
4848
  value = `${value}`;
4838
- if (focus) {
4839
- if (type === "SL" && mode === "PnL" /* PnL */) {
4840
- value = value.startsWith("-") ? value : "-" + value;
4841
- }
4849
+ if (type === "SL" && mode === "PnL" /* PnL */) {
4850
+ value = value.startsWith("-") ? value : "-" + value;
4842
4851
  }
4843
4852
  if (value === "" || value === "-") return "";
4844
4853
  if (mode === "Offset%" /* PERCENTAGE */) {
@@ -4875,7 +4884,7 @@ var usePNLInputBuilder = (props) => {
4875
4884
  value = new utils.Decimal(value).div(100).toString();
4876
4885
  value = `${value}${percentageSuffix.current}`;
4877
4886
  }
4878
- } else if (mode === "PnL" /* PnL */ && type === "SL" && focus) {
4887
+ } else if (mode === "PnL" /* PnL */ && type === "SL") {
4879
4888
  value = value.startsWith("-") ? value : "-" + value;
4880
4889
  } else {
4881
4890
  value = utils.todpIfNeed(value, dp);
@@ -6342,6 +6351,7 @@ var useOrderEntryScript = (inputs) => {
6342
6351
  slPrice: formattedOrder.sl_trigger_price,
6343
6352
  liqPrice: state.estLiqPrice,
6344
6353
  side: formattedOrder.side,
6354
+ markPrice: state.markPrice,
6345
6355
  currentPosition: state.currentPosition,
6346
6356
  orderQuantity: Number(formattedOrder.order_quantity)
6347
6357
  });