@orderly.network/ui-transfer 2.8.12 → 2.8.13-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
@@ -4413,6 +4413,7 @@ function useDepositAction(options2) {
4413
4413
  } catch (err) {
4414
4414
  console.error("deposit error", err);
4415
4415
  const knownErrorMessage = getDepositKnownErrorMessage(err.message);
4416
+ options2.onError?.(err, knownErrorMessage);
4416
4417
  if (knownErrorMessage) {
4417
4418
  toast.error(
4418
4419
  /* @__PURE__ */ jsxs("div", { children: [
@@ -4429,7 +4430,7 @@ function useDepositAction(options2) {
4429
4430
  toast.error(err.message || t("common.somethingWentWrong"));
4430
4431
  }
4431
4432
  }
4432
- }, [deposit, onSuccess, t]);
4433
+ }, [deposit, onSuccess, t, ee, options2.onError]);
4433
4434
  const onDeposit = useCallback(async () => {
4434
4435
  const num = Number(quantity);
4435
4436
  if (isNaN(num) || num <= 0) {
@@ -4476,24 +4477,19 @@ function useDepositAction(options2) {
4476
4477
  function useInputStatus(options2) {
4477
4478
  const { quantity, maxQuantity } = options2;
4478
4479
  const { t } = useTranslation();
4479
- const [inputStatus, setInputStatus] = useState("default");
4480
- const [hintMessage, setHintMessage] = useState();
4481
- useEffect(() => {
4480
+ return useMemo(() => {
4482
4481
  if (!quantity) {
4483
- setInputStatus("default");
4484
- setHintMessage("");
4485
- return;
4482
+ return { inputStatus: "default", hintMessage: "" };
4486
4483
  }
4487
4484
  const qty = new Decimal(quantity);
4488
4485
  if (qty.gt(maxQuantity)) {
4489
- setInputStatus("error");
4490
- setHintMessage(t("transfer.insufficientBalance"));
4491
- } else {
4492
- setInputStatus("default");
4493
- setHintMessage("");
4486
+ return {
4487
+ inputStatus: "error",
4488
+ hintMessage: t("transfer.insufficientBalance")
4489
+ };
4494
4490
  }
4495
- }, [quantity, maxQuantity]);
4496
- return { inputStatus, hintMessage };
4491
+ return { inputStatus: "default", hintMessage: "" };
4492
+ }, [quantity, maxQuantity, t]);
4497
4493
  }
4498
4494
  var retryInterval2 = 3e3;
4499
4495
  function useNativeBalance(options2) {
@@ -4705,10 +4701,12 @@ var useDepositFormScript = (options2) => {
4705
4701
  needSwap,
4706
4702
  needCrossSwap
4707
4703
  });
4704
+ const [depositExceedLimitDetected, setDepositExceedLimitDetected] = useState(false);
4708
4705
  const cleanData = useCallback(() => {
4709
4706
  setQuantity("");
4710
4707
  cleanTransactionInfo();
4711
- }, [setQuantity]);
4708
+ setDepositExceedLimitDetected(false);
4709
+ }, [setQuantity, cleanTransactionInfo]);
4712
4710
  const onSuccess = useCallback(() => {
4713
4711
  cleanData();
4714
4712
  options2.close?.();
@@ -4720,38 +4718,57 @@ var useDepositFormScript = (options2) => {
4720
4718
  deposit,
4721
4719
  enableCustomDeposit: needSwap || needCrossSwap,
4722
4720
  customDeposit: onSwapDeposit,
4723
- onSuccess
4721
+ onSuccess: () => {
4722
+ setDepositExceedLimitDetected(false);
4723
+ onSuccess();
4724
+ },
4725
+ onError: (err, knownErrorMessage) => {
4726
+ const message = typeof err?.message === "string" ? err.message : "";
4727
+ const isDepositExceedLimit = message.includes("0xd969df24") || message.includes("DepositExceedLimit") || (knownErrorMessage?.includes("DepositExceedLimit") ?? false);
4728
+ if (isDepositExceedLimit) {
4729
+ setDepositExceedLimitDetected(true);
4730
+ }
4731
+ }
4724
4732
  });
4725
- const userMaxQtyMessage = useMemo(() => {
4726
- if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || !quantity || isNaN(Number(quantity))) {
4727
- return "";
4733
+ useEffect(() => {
4734
+ if (depositExceedLimitDetected) {
4735
+ setDepositExceedLimitDetected(false);
4728
4736
  }
4729
- if (new Decimal(quantity).gt(sourceToken?.user_max_qty)) {
4730
- return /* @__PURE__ */ jsx(
4731
- Trans,
4732
- {
4733
- i18nKey: "transfer.deposit.userMaxQty.error",
4734
- values: {
4735
- token: sourceToken?.symbol,
4736
- chain: currentChain?.info?.network_infos?.name || ""
4737
- },
4738
- components: [
4739
- /* @__PURE__ */ jsx(
4740
- "a",
4741
- {
4742
- href: "https://orderly.network/docs/introduction/trade-on-orderly/multi-collateral#max-deposits-global",
4743
- target: "_blank",
4744
- rel: "noopener noreferrer",
4745
- className: "oui-text-primary"
4746
- },
4747
- "0"
4748
- )
4749
- ]
4750
- }
4751
- );
4737
+ }, [quantity, sourceToken, currentChain?.id]);
4738
+ const globalMaxQtyMessage = useMemo(() => {
4739
+ if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || !depositExceedLimitDetected) {
4740
+ return "";
4752
4741
  }
4753
- return "";
4754
- }, [sourceToken, targetToken, quantity, currentChain, t]);
4742
+ return /* @__PURE__ */ jsx(
4743
+ Trans,
4744
+ {
4745
+ i18nKey: "transfer.deposit.globalMaxQty.error",
4746
+ values: {
4747
+ token: sourceToken?.symbol,
4748
+ chain: currentChain?.info?.network_infos?.name || ""
4749
+ },
4750
+ components: [
4751
+ /* @__PURE__ */ jsx(
4752
+ "a",
4753
+ {
4754
+ href: "https://orderly.network/docs/introduction/trade-on-orderly/multi-collateral#max-deposits-global",
4755
+ target: "_blank",
4756
+ rel: "noopener noreferrer",
4757
+ className: "oui-text-primary"
4758
+ },
4759
+ "0"
4760
+ )
4761
+ ]
4762
+ }
4763
+ );
4764
+ }, [
4765
+ depositExceedLimitDetected,
4766
+ sourceToken?.symbol,
4767
+ sourceToken?.is_collateral,
4768
+ targetToken?.symbol,
4769
+ currentChain,
4770
+ t
4771
+ ]);
4755
4772
  const loading = submitting || depositFeeRevalidating;
4756
4773
  const nativeSymbol = useMemo(() => {
4757
4774
  return currentChain?.info?.nativeToken?.symbol;
@@ -4790,13 +4807,6 @@ var useDepositFormScript = (options2) => {
4790
4807
  useEffect(() => {
4791
4808
  cleanData();
4792
4809
  }, [sourceToken, currentChain?.id]);
4793
- const gasFeeMessage = useMemo(() => {
4794
- if (isNativeToken && maxQuantity === quantity) {
4795
- return t("transfer.deposit.gasFee.error", {
4796
- token: sourceToken?.symbol
4797
- });
4798
- }
4799
- }, [maxQuantity, quantity, sourceToken?.symbol, t]);
4800
4810
  useEffect(() => {
4801
4811
  if (quantity && Number(quantity) > 0 && depositFee === 0n && !depositFeeRevalidating && account2.walletAdapter?.chainNamespace !== ChainNamespace.solana) {
4802
4812
  setFeeWarningMessage(t("transfer.deposit.feeUnavailable"));
@@ -4810,6 +4820,28 @@ var useDepositFormScript = (options2) => {
4810
4820
  }
4811
4821
  return false;
4812
4822
  }, [quantity, maxQuantity]);
4823
+ const insufficientNativeTotal = useMemo(() => {
4824
+ if (!isNativeToken || !quantity || Number(quantity) <= 0 || depositFeeRevalidating || insufficientBalance) {
4825
+ return false;
4826
+ }
4827
+ const estimatedGasFee = new Decimal(fee.dstGasFee || 0);
4828
+ const totalNeeded = new Decimal(quantity).add(estimatedGasFee);
4829
+ return totalNeeded.gt(maxQuantity || 0);
4830
+ }, [
4831
+ isNativeToken,
4832
+ quantity,
4833
+ depositFeeRevalidating,
4834
+ insufficientBalance,
4835
+ fee.dstGasFee,
4836
+ maxQuantity
4837
+ ]);
4838
+ const gasFeeMessage = useMemo(() => {
4839
+ if (insufficientNativeTotal) {
4840
+ return t("transfer.deposit.gasFee.error", {
4841
+ token: sourceToken?.symbol
4842
+ });
4843
+ }
4844
+ }, [insufficientNativeTotal, sourceToken?.symbol, t]);
4813
4845
  const nativeBalance = useNativeBalance({
4814
4846
  fetchBalance,
4815
4847
  targetChain
@@ -4836,12 +4868,17 @@ var useDepositFormScript = (options2) => {
4836
4868
  account2,
4837
4869
  nativeBalance
4838
4870
  ]);
4839
- const warningMessage = swapWarningMessage || userMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
4840
- const hasUserMaxQtyError = !!userMaxQtyMessage;
4841
- const finalInputStatus = hasUserMaxQtyError ? "error" : inputStatus;
4842
- const finalHintMessage = hasUserMaxQtyError ? t("transfer.deposit.exceedCap") : hintMessage;
4871
+ const warningMessage = swapWarningMessage || globalMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
4872
+ const isExceedUserCapByInput = useMemo(() => {
4873
+ 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))) {
4874
+ return false;
4875
+ }
4876
+ return new Decimal(quantity).gt(sourceToken.user_max_qty);
4877
+ }, [sourceToken, targetToken, quantity]);
4878
+ const finalInputStatus = inputStatus === "error" ? inputStatus : isExceedUserCapByInput ? "error" : inputStatus;
4879
+ const finalHintMessage = inputStatus === "error" ? hintMessage : isExceedUserCapByInput ? t("transfer.deposit.exceedCap") : hintMessage;
4843
4880
  const disabled = !quantity || Number(quantity) === 0 || !sourceToken || inputStatus === "error" || depositFeeRevalidating || swapRevalidating || // if exceed collateral cap, disable deposit
4844
- !!userMaxQtyMessage || !!feeWarningMessage || !!insufficientGasMessage;
4881
+ isExceedUserCapByInput || !!feeWarningMessage || !!insufficientNativeTotal || !!insufficientGasMessage;
4845
4882
  const targetQuantity = useMemo(() => {
4846
4883
  if (needSwap) {
4847
4884
  return swapQuantity ? new Decimal(swapQuantity)?.todp(SWAP_USDC_PRECISION, Decimal.ROUND_DOWN).toString() : swapQuantity;