@orderly.network/ui-transfer 2.8.13-rc.0 → 2.8.13
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 +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +93 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/index.d.mts
CHANGED
|
@@ -51,6 +51,7 @@ 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;
|
|
54
55
|
customDeposit?: () => Promise<any>;
|
|
55
56
|
enableCustomDeposit?: boolean;
|
|
56
57
|
};
|
|
@@ -67,7 +68,7 @@ type Options = {
|
|
|
67
68
|
};
|
|
68
69
|
declare function useInputStatus(options: Options): {
|
|
69
70
|
inputStatus: InputStatus;
|
|
70
|
-
hintMessage: string
|
|
71
|
+
hintMessage: string;
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
type DepositFormScriptReturn = ReturnType<typeof useDepositFormScript>;
|
|
@@ -106,8 +107,8 @@ declare const useDepositFormScript: (options: DepositFormScriptOptions) => {
|
|
|
106
107
|
maxDepositAmount: string;
|
|
107
108
|
indexPrice: number;
|
|
108
109
|
onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
|
|
109
|
-
hintMessage: string
|
|
110
|
-
inputStatus:
|
|
110
|
+
hintMessage: string;
|
|
111
|
+
inputStatus: "default" | "error" | "warning" | "success";
|
|
111
112
|
chains: API.NetworkInfos[];
|
|
112
113
|
currentChain: CurrentChain | null;
|
|
113
114
|
settingChain: boolean;
|
|
@@ -318,7 +319,7 @@ declare const useSwapDepositFormScript: (options: UseSwapDepositFormScriptOption
|
|
|
318
319
|
maxQuantity: string;
|
|
319
320
|
swapQuantity: string;
|
|
320
321
|
onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
|
|
321
|
-
hintMessage: string
|
|
322
|
+
hintMessage: string;
|
|
322
323
|
inputStatus: InputStatus;
|
|
323
324
|
chains: API.NetworkInfos[];
|
|
324
325
|
currentChain: CurrentChain | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ 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;
|
|
54
55
|
customDeposit?: () => Promise<any>;
|
|
55
56
|
enableCustomDeposit?: boolean;
|
|
56
57
|
};
|
|
@@ -67,7 +68,7 @@ type Options = {
|
|
|
67
68
|
};
|
|
68
69
|
declare function useInputStatus(options: Options): {
|
|
69
70
|
inputStatus: InputStatus;
|
|
70
|
-
hintMessage: string
|
|
71
|
+
hintMessage: string;
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
type DepositFormScriptReturn = ReturnType<typeof useDepositFormScript>;
|
|
@@ -106,8 +107,8 @@ declare const useDepositFormScript: (options: DepositFormScriptOptions) => {
|
|
|
106
107
|
maxDepositAmount: string;
|
|
107
108
|
indexPrice: number;
|
|
108
109
|
onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
|
|
109
|
-
hintMessage: string
|
|
110
|
-
inputStatus:
|
|
110
|
+
hintMessage: string;
|
|
111
|
+
inputStatus: "default" | "error" | "warning" | "success";
|
|
111
112
|
chains: API.NetworkInfos[];
|
|
112
113
|
currentChain: CurrentChain | null;
|
|
113
114
|
settingChain: boolean;
|
|
@@ -318,7 +319,7 @@ declare const useSwapDepositFormScript: (options: UseSwapDepositFormScriptOption
|
|
|
318
319
|
maxQuantity: string;
|
|
319
320
|
swapQuantity: string;
|
|
320
321
|
onQuantityChange: react.Dispatch<react.SetStateAction<string>>;
|
|
321
|
-
hintMessage: string
|
|
322
|
+
hintMessage: string;
|
|
322
323
|
inputStatus: InputStatus;
|
|
323
324
|
chains: API.NetworkInfos[];
|
|
324
325
|
currentChain: CurrentChain | null;
|
package/dist/index.js
CHANGED
|
@@ -4415,6 +4415,7 @@ 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);
|
|
4418
4419
|
if (knownErrorMessage) {
|
|
4419
4420
|
ui.toast.error(
|
|
4420
4421
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
@@ -4431,7 +4432,7 @@ function useDepositAction(options2) {
|
|
|
4431
4432
|
ui.toast.error(err.message || t("common.somethingWentWrong"));
|
|
4432
4433
|
}
|
|
4433
4434
|
}
|
|
4434
|
-
}, [deposit, onSuccess, t]);
|
|
4435
|
+
}, [deposit, onSuccess, t, ee, options2.onError]);
|
|
4435
4436
|
const onDeposit = react.useCallback(async () => {
|
|
4436
4437
|
const num = Number(quantity);
|
|
4437
4438
|
if (isNaN(num) || num <= 0) {
|
|
@@ -4478,24 +4479,19 @@ function useDepositAction(options2) {
|
|
|
4478
4479
|
function useInputStatus(options2) {
|
|
4479
4480
|
const { quantity, maxQuantity } = options2;
|
|
4480
4481
|
const { t } = i18n.useTranslation();
|
|
4481
|
-
|
|
4482
|
-
const [hintMessage, setHintMessage] = react.useState();
|
|
4483
|
-
react.useEffect(() => {
|
|
4482
|
+
return react.useMemo(() => {
|
|
4484
4483
|
if (!quantity) {
|
|
4485
|
-
|
|
4486
|
-
setHintMessage("");
|
|
4487
|
-
return;
|
|
4484
|
+
return { inputStatus: "default", hintMessage: "" };
|
|
4488
4485
|
}
|
|
4489
4486
|
const qty = new utils.Decimal(quantity);
|
|
4490
4487
|
if (qty.gt(maxQuantity)) {
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
setHintMessage("");
|
|
4488
|
+
return {
|
|
4489
|
+
inputStatus: "error",
|
|
4490
|
+
hintMessage: t("transfer.insufficientBalance")
|
|
4491
|
+
};
|
|
4496
4492
|
}
|
|
4497
|
-
|
|
4498
|
-
|
|
4493
|
+
return { inputStatus: "default", hintMessage: "" };
|
|
4494
|
+
}, [quantity, maxQuantity, t]);
|
|
4499
4495
|
}
|
|
4500
4496
|
var retryInterval2 = 3e3;
|
|
4501
4497
|
function useNativeBalance(options2) {
|
|
@@ -4707,10 +4703,12 @@ var useDepositFormScript = (options2) => {
|
|
|
4707
4703
|
needSwap,
|
|
4708
4704
|
needCrossSwap
|
|
4709
4705
|
});
|
|
4706
|
+
const [depositExceedLimitDetected, setDepositExceedLimitDetected] = react.useState(false);
|
|
4710
4707
|
const cleanData = react.useCallback(() => {
|
|
4711
4708
|
setQuantity("");
|
|
4712
4709
|
cleanTransactionInfo();
|
|
4713
|
-
|
|
4710
|
+
setDepositExceedLimitDetected(false);
|
|
4711
|
+
}, [setQuantity, cleanTransactionInfo]);
|
|
4714
4712
|
const onSuccess = react.useCallback(() => {
|
|
4715
4713
|
cleanData();
|
|
4716
4714
|
options2.close?.();
|
|
@@ -4722,38 +4720,57 @@ var useDepositFormScript = (options2) => {
|
|
|
4722
4720
|
deposit,
|
|
4723
4721
|
enableCustomDeposit: needSwap || needCrossSwap,
|
|
4724
4722
|
customDeposit: onSwapDeposit,
|
|
4725
|
-
onSuccess
|
|
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
|
+
}
|
|
4726
4734
|
});
|
|
4727
|
-
|
|
4728
|
-
if (
|
|
4729
|
-
|
|
4735
|
+
react.useEffect(() => {
|
|
4736
|
+
if (depositExceedLimitDetected) {
|
|
4737
|
+
setDepositExceedLimitDetected(false);
|
|
4730
4738
|
}
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
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
|
-
);
|
|
4739
|
+
}, [quantity, sourceToken, currentChain?.id]);
|
|
4740
|
+
const globalMaxQtyMessage = react.useMemo(() => {
|
|
4741
|
+
if (sourceToken?.symbol === "USDC" || sourceToken?.symbol !== targetToken?.symbol || !sourceToken?.is_collateral || !depositExceedLimitDetected) {
|
|
4742
|
+
return "";
|
|
4754
4743
|
}
|
|
4755
|
-
return
|
|
4756
|
-
|
|
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
|
+
]);
|
|
4757
4774
|
const loading = submitting || depositFeeRevalidating;
|
|
4758
4775
|
const nativeSymbol = react.useMemo(() => {
|
|
4759
4776
|
return currentChain?.info?.nativeToken?.symbol;
|
|
@@ -4792,13 +4809,6 @@ var useDepositFormScript = (options2) => {
|
|
|
4792
4809
|
react.useEffect(() => {
|
|
4793
4810
|
cleanData();
|
|
4794
4811
|
}, [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]);
|
|
4802
4812
|
react.useEffect(() => {
|
|
4803
4813
|
if (quantity && Number(quantity) > 0 && depositFee === 0n && !depositFeeRevalidating && account2.walletAdapter?.chainNamespace !== types.ChainNamespace.solana) {
|
|
4804
4814
|
setFeeWarningMessage(t("transfer.deposit.feeUnavailable"));
|
|
@@ -4812,6 +4822,28 @@ var useDepositFormScript = (options2) => {
|
|
|
4812
4822
|
}
|
|
4813
4823
|
return false;
|
|
4814
4824
|
}, [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]);
|
|
4815
4847
|
const nativeBalance = useNativeBalance({
|
|
4816
4848
|
fetchBalance,
|
|
4817
4849
|
targetChain
|
|
@@ -4838,12 +4870,17 @@ var useDepositFormScript = (options2) => {
|
|
|
4838
4870
|
account2,
|
|
4839
4871
|
nativeBalance
|
|
4840
4872
|
]);
|
|
4841
|
-
const warningMessage = swapWarningMessage ||
|
|
4842
|
-
const
|
|
4843
|
-
|
|
4844
|
-
|
|
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;
|
|
4845
4882
|
const disabled = !quantity || Number(quantity) === 0 || !sourceToken || inputStatus === "error" || depositFeeRevalidating || swapRevalidating || // if exceed collateral cap, disable deposit
|
|
4846
|
-
|
|
4883
|
+
isExceedUserCapByInput || !!feeWarningMessage || !!insufficientNativeTotal || !!insufficientGasMessage;
|
|
4847
4884
|
const targetQuantity = react.useMemo(() => {
|
|
4848
4885
|
if (needSwap) {
|
|
4849
4886
|
return swapQuantity ? new utils.Decimal(swapQuantity)?.todp(SWAP_USDC_PRECISION, utils.Decimal.ROUND_DOWN).toString() : swapQuantity;
|