@orderly.network/ui-transfer 2.8.13-alpha.0 → 2.8.13-rc.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
@@ -51,7 +51,6 @@ type Options$1 = {
51
51
  approve: (quantity?: string) => Promise<any>;
52
52
  deposit: () => Promise<any>;
53
53
  onSuccess?: () => void;
54
- onError?: (err: unknown, knownErrorMessage?: string) => void;
55
54
  customDeposit?: () => Promise<any>;
56
55
  enableCustomDeposit?: boolean;
57
56
  };
@@ -68,7 +67,7 @@ type Options = {
68
67
  };
69
68
  declare function useInputStatus(options: Options): {
70
69
  inputStatus: InputStatus;
71
- hintMessage: string;
70
+ hintMessage: string | undefined;
72
71
  };
73
72
 
74
73
  type DepositFormScriptReturn = ReturnType<typeof useDepositFormScript>;
@@ -107,8 +106,8 @@ declare const useDepositFormScript: (options: DepositFormScriptOptions) => {
107
106
  maxDepositAmount: string;
108
107
  indexPrice: number;
109
108
  onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
110
- hintMessage: string;
111
- inputStatus: "default" | "error" | "warning" | "success";
109
+ hintMessage: string | undefined;
110
+ inputStatus: InputStatus;
112
111
  chains: API.NetworkInfos[];
113
112
  currentChain: CurrentChain | null;
114
113
  settingChain: boolean;
@@ -319,7 +318,7 @@ declare const useSwapDepositFormScript: (options: UseSwapDepositFormScriptOption
319
318
  maxQuantity: string;
320
319
  swapQuantity: string;
321
320
  onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
322
- hintMessage: string;
321
+ hintMessage: string | undefined;
323
322
  inputStatus: InputStatus;
324
323
  chains: API.NetworkInfos[];
325
324
  currentChain: CurrentChain | null;
package/dist/index.d.ts CHANGED
@@ -51,7 +51,6 @@ type Options$1 = {
51
51
  approve: (quantity?: string) => Promise<any>;
52
52
  deposit: () => Promise<any>;
53
53
  onSuccess?: () => void;
54
- onError?: (err: unknown, knownErrorMessage?: string) => void;
55
54
  customDeposit?: () => Promise<any>;
56
55
  enableCustomDeposit?: boolean;
57
56
  };
@@ -68,7 +67,7 @@ type Options = {
68
67
  };
69
68
  declare function useInputStatus(options: Options): {
70
69
  inputStatus: InputStatus;
71
- hintMessage: string;
70
+ hintMessage: string | undefined;
72
71
  };
73
72
 
74
73
  type DepositFormScriptReturn = ReturnType<typeof useDepositFormScript>;
@@ -107,8 +106,8 @@ declare const useDepositFormScript: (options: DepositFormScriptOptions) => {
107
106
  maxDepositAmount: string;
108
107
  indexPrice: number;
109
108
  onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
110
- hintMessage: string;
111
- inputStatus: "default" | "error" | "warning" | "success";
109
+ hintMessage: string | undefined;
110
+ inputStatus: InputStatus;
112
111
  chains: API.NetworkInfos[];
113
112
  currentChain: CurrentChain | null;
114
113
  settingChain: boolean;
@@ -319,7 +318,7 @@ declare const useSwapDepositFormScript: (options: UseSwapDepositFormScriptOption
319
318
  maxQuantity: string;
320
319
  swapQuantity: string;
321
320
  onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
322
- hintMessage: string;
321
+ hintMessage: string | undefined;
323
322
  inputStatus: InputStatus;
324
323
  chains: API.NetworkInfos[];
325
324
  currentChain: CurrentChain | null;
package/dist/index.js CHANGED
@@ -4415,7 +4415,6 @@ function useDepositAction(options2) {
4415
4415
  } catch (err) {
4416
4416
  console.error("deposit error", err);
4417
4417
  const knownErrorMessage = getDepositKnownErrorMessage(err.message);
4418
- options2.onError?.(err, knownErrorMessage);
4419
4418
  if (knownErrorMessage) {
4420
4419
  ui.toast.error(
4421
4420
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -4432,7 +4431,7 @@ function useDepositAction(options2) {
4432
4431
  ui.toast.error(err.message || t("common.somethingWentWrong"));
4433
4432
  }
4434
4433
  }
4435
- }, [deposit, onSuccess, t, ee, options2.onError]);
4434
+ }, [deposit, onSuccess, t]);
4436
4435
  const onDeposit = react.useCallback(async () => {
4437
4436
  const num = Number(quantity);
4438
4437
  if (isNaN(num) || num <= 0) {
@@ -4479,19 +4478,24 @@ function useDepositAction(options2) {
4479
4478
  function useInputStatus(options2) {
4480
4479
  const { quantity, maxQuantity } = options2;
4481
4480
  const { t } = i18n.useTranslation();
4482
- return react.useMemo(() => {
4481
+ const [inputStatus, setInputStatus] = react.useState("default");
4482
+ const [hintMessage, setHintMessage] = react.useState();
4483
+ react.useEffect(() => {
4483
4484
  if (!quantity) {
4484
- return { inputStatus: "default", hintMessage: "" };
4485
+ setInputStatus("default");
4486
+ setHintMessage("");
4487
+ return;
4485
4488
  }
4486
4489
  const qty = new utils.Decimal(quantity);
4487
4490
  if (qty.gt(maxQuantity)) {
4488
- return {
4489
- inputStatus: "error",
4490
- hintMessage: t("transfer.insufficientBalance")
4491
- };
4491
+ setInputStatus("error");
4492
+ setHintMessage(t("transfer.insufficientBalance"));
4493
+ } else {
4494
+ setInputStatus("default");
4495
+ setHintMessage("");
4492
4496
  }
4493
- return { inputStatus: "default", hintMessage: "" };
4494
- }, [quantity, maxQuantity, t]);
4497
+ }, [quantity, maxQuantity]);
4498
+ return { inputStatus, hintMessage };
4495
4499
  }
4496
4500
  var retryInterval2 = 3e3;
4497
4501
  function useNativeBalance(options2) {
@@ -4703,12 +4707,10 @@ var useDepositFormScript = (options2) => {
4703
4707
  needSwap,
4704
4708
  needCrossSwap
4705
4709
  });
4706
- const [depositExceedLimitDetected, setDepositExceedLimitDetected] = react.useState(false);
4707
4710
  const cleanData = react.useCallback(() => {
4708
4711
  setQuantity("");
4709
4712
  cleanTransactionInfo();
4710
- setDepositExceedLimitDetected(false);
4711
- }, [setQuantity, cleanTransactionInfo]);
4713
+ }, [setQuantity]);
4712
4714
  const onSuccess = react.useCallback(() => {
4713
4715
  cleanData();
4714
4716
  options2.close?.();
@@ -4720,57 +4722,38 @@ var useDepositFormScript = (options2) => {
4720
4722
  deposit,
4721
4723
  enableCustomDeposit: needSwap || needCrossSwap,
4722
4724
  customDeposit: onSwapDeposit,
4723
- onSuccess: () => {
4724
- setDepositExceedLimitDetected(false);
4725
- onSuccess();
4726
- },
4727
- onError: (err, knownErrorMessage) => {
4728
- const message = typeof err?.message === "string" ? err.message : "";
4729
- const isDepositExceedLimit = message.includes("0xd969df24") || message.includes("DepositExceedLimit") || (knownErrorMessage?.includes("DepositExceedLimit") ?? false);
4730
- if (isDepositExceedLimit) {
4731
- setDepositExceedLimitDetected(true);
4732
- }
4733
- }
4725
+ onSuccess
4734
4726
  });
4735
- react.useEffect(() => {
4736
- if (depositExceedLimitDetected) {
4737
- setDepositExceedLimitDetected(false);
4738
- }
4739
- }, [quantity, sourceToken, currentChain?.id]);
4740
- const globalMaxQtyMessage = react.useMemo(() => {
4741
- if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || !depositExceedLimitDetected) {
4727
+ const userMaxQtyMessage = react.useMemo(() => {
4728
+ if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || !quantity || isNaN(Number(quantity))) {
4742
4729
  return "";
4743
4730
  }
4744
- return /* @__PURE__ */ jsxRuntime.jsx(
4745
- i18n.Trans,
4746
- {
4747
- i18nKey: "transfer.deposit.globalMaxQty.error",
4748
- values: {
4749
- token: sourceToken?.symbol,
4750
- chain: currentChain?.info?.network_infos?.name || ""
4751
- },
4752
- components: [
4753
- /* @__PURE__ */ jsxRuntime.jsx(
4754
- "a",
4755
- {
4756
- href: "https://orderly.network/docs/introduction/trade-on-orderly/multi-collateral#max-deposits-global",
4757
- target: "_blank",
4758
- rel: "noopener noreferrer",
4759
- className: "oui-text-primary"
4760
- },
4761
- "0"
4762
- )
4763
- ]
4764
- }
4765
- );
4766
- }, [
4767
- depositExceedLimitDetected,
4768
- sourceToken?.symbol,
4769
- sourceToken?.is_collateral,
4770
- targetToken?.symbol,
4771
- currentChain,
4772
- t
4773
- ]);
4731
+ if (new utils.Decimal(quantity).gt(sourceToken?.user_max_qty)) {
4732
+ return /* @__PURE__ */ jsxRuntime.jsx(
4733
+ i18n.Trans,
4734
+ {
4735
+ i18nKey: "transfer.deposit.userMaxQty.error",
4736
+ values: {
4737
+ token: sourceToken?.symbol,
4738
+ chain: currentChain?.info?.network_infos?.name || ""
4739
+ },
4740
+ components: [
4741
+ /* @__PURE__ */ jsxRuntime.jsx(
4742
+ "a",
4743
+ {
4744
+ href: "https://orderly.network/docs/introduction/trade-on-orderly/multi-collateral#max-deposits-global",
4745
+ target: "_blank",
4746
+ rel: "noopener noreferrer",
4747
+ className: "oui-text-primary"
4748
+ },
4749
+ "0"
4750
+ )
4751
+ ]
4752
+ }
4753
+ );
4754
+ }
4755
+ return "";
4756
+ }, [sourceToken, targetToken, quantity, currentChain, t]);
4774
4757
  const loading = submitting || depositFeeRevalidating;
4775
4758
  const nativeSymbol = react.useMemo(() => {
4776
4759
  return currentChain?.info?.nativeToken?.symbol;
@@ -4809,6 +4792,13 @@ var useDepositFormScript = (options2) => {
4809
4792
  react.useEffect(() => {
4810
4793
  cleanData();
4811
4794
  }, [sourceToken, currentChain?.id]);
4795
+ const gasFeeMessage = react.useMemo(() => {
4796
+ if (isNativeToken && maxQuantity === quantity) {
4797
+ return t("transfer.deposit.gasFee.error", {
4798
+ token: sourceToken?.symbol
4799
+ });
4800
+ }
4801
+ }, [maxQuantity, quantity, sourceToken?.symbol, t]);
4812
4802
  react.useEffect(() => {
4813
4803
  if (quantity && Number(quantity) > 0 && depositFee === 0n && !depositFeeRevalidating && account2.walletAdapter?.chainNamespace !== types.ChainNamespace.solana) {
4814
4804
  setFeeWarningMessage(t("transfer.deposit.feeUnavailable"));
@@ -4822,28 +4812,6 @@ var useDepositFormScript = (options2) => {
4822
4812
  }
4823
4813
  return false;
4824
4814
  }, [quantity, maxQuantity]);
4825
- const insufficientNativeTotal = react.useMemo(() => {
4826
- if (!isNativeToken || !quantity || Number(quantity) <= 0 || depositFeeRevalidating || insufficientBalance) {
4827
- return false;
4828
- }
4829
- const estimatedGasFee = new utils.Decimal(fee.dstGasFee || 0);
4830
- const totalNeeded = new utils.Decimal(quantity).add(estimatedGasFee);
4831
- return totalNeeded.gt(maxQuantity || 0);
4832
- }, [
4833
- isNativeToken,
4834
- quantity,
4835
- depositFeeRevalidating,
4836
- insufficientBalance,
4837
- fee.dstGasFee,
4838
- maxQuantity
4839
- ]);
4840
- const gasFeeMessage = react.useMemo(() => {
4841
- if (insufficientNativeTotal) {
4842
- return t("transfer.deposit.gasFee.error", {
4843
- token: sourceToken?.symbol
4844
- });
4845
- }
4846
- }, [insufficientNativeTotal, sourceToken?.symbol, t]);
4847
4815
  const nativeBalance = useNativeBalance({
4848
4816
  fetchBalance,
4849
4817
  targetChain
@@ -4870,17 +4838,12 @@ var useDepositFormScript = (options2) => {
4870
4838
  account2,
4871
4839
  nativeBalance
4872
4840
  ]);
4873
- const warningMessage = swapWarningMessage || globalMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
4874
- const isExceedUserCapByInput = react.useMemo(() => {
4875
- if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || sourceToken?.user_max_qty === void 0 || sourceToken?.user_max_qty === -1 || !quantity || isNaN(Number(quantity))) {
4876
- return false;
4877
- }
4878
- return new utils.Decimal(quantity).gt(sourceToken.user_max_qty);
4879
- }, [sourceToken, targetToken, quantity]);
4880
- const finalInputStatus = inputStatus === "error" ? inputStatus : isExceedUserCapByInput ? "error" : inputStatus;
4881
- const finalHintMessage = inputStatus === "error" ? hintMessage : isExceedUserCapByInput ? t("transfer.deposit.exceedCap") : hintMessage;
4841
+ const warningMessage = swapWarningMessage || userMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
4842
+ const hasUserMaxQtyError = !!userMaxQtyMessage;
4843
+ const finalInputStatus = hasUserMaxQtyError ? "error" : inputStatus;
4844
+ const finalHintMessage = hasUserMaxQtyError ? t("transfer.deposit.exceedCap") : hintMessage;
4882
4845
  const disabled = !quantity || Number(quantity) === 0 || !sourceToken || inputStatus === "error" || depositFeeRevalidating || swapRevalidating || // if exceed collateral cap, disable deposit
4883
- isExceedUserCapByInput || !!feeWarningMessage || !!insufficientNativeTotal || !!insufficientGasMessage;
4846
+ !!userMaxQtyMessage || !!feeWarningMessage || !!insufficientGasMessage;
4884
4847
  const targetQuantity = react.useMemo(() => {
4885
4848
  if (needSwap) {
4886
4849
  return swapQuantity ? new utils.Decimal(swapQuantity)?.todp(SWAP_USDC_PRECISION, utils.Decimal.ROUND_DOWN).toString() : swapQuantity;