@orderly.network/ui-transfer 2.8.2 → 2.8.3-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 +47 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -4423,6 +4423,39 @@ function useInputStatus(options2) {
|
|
|
4423
4423
|
}, [quantity, maxQuantity]);
|
|
4424
4424
|
return { inputStatus, hintMessage };
|
|
4425
4425
|
}
|
|
4426
|
+
var retryInterval2 = 3e3;
|
|
4427
|
+
function useNativeBalance(options2) {
|
|
4428
|
+
const { fetchBalance, targetChain } = options2;
|
|
4429
|
+
const [balance, setBalance] = react.useState();
|
|
4430
|
+
const timeoutRef = react.useRef();
|
|
4431
|
+
const loopGetTokenBalance = async (timeout = 0) => {
|
|
4432
|
+
const decimal = targetChain?.network_infos?.currency_decimal;
|
|
4433
|
+
if (typeof fetchBalance !== "function" || !decimal) {
|
|
4434
|
+
return;
|
|
4435
|
+
}
|
|
4436
|
+
if (timeoutRef.current) {
|
|
4437
|
+
clearTimeout(timeoutRef.current);
|
|
4438
|
+
}
|
|
4439
|
+
timeoutRef.current = setTimeout(async () => {
|
|
4440
|
+
fetchBalance(types.nativeTokenAddress, decimal).then((balance2) => {
|
|
4441
|
+
console.log("native balance", balance2);
|
|
4442
|
+
setBalance(balance2);
|
|
4443
|
+
}).catch((error) => {
|
|
4444
|
+
console.error("fetch native balance error", error);
|
|
4445
|
+
loopGetTokenBalance(retryInterval2);
|
|
4446
|
+
});
|
|
4447
|
+
}, timeout);
|
|
4448
|
+
};
|
|
4449
|
+
react.useEffect(() => {
|
|
4450
|
+
loopGetTokenBalance(0);
|
|
4451
|
+
return () => {
|
|
4452
|
+
if (timeoutRef.current) {
|
|
4453
|
+
clearTimeout(timeoutRef.current);
|
|
4454
|
+
}
|
|
4455
|
+
};
|
|
4456
|
+
}, []);
|
|
4457
|
+
return balance;
|
|
4458
|
+
}
|
|
4426
4459
|
var useToken = (currentChain, filter = () => true) => {
|
|
4427
4460
|
const [sourceToken, setSourceToken] = react.useState();
|
|
4428
4461
|
const [targetToken, setTargetToken] = react.useState();
|
|
@@ -4540,7 +4573,8 @@ var useDepositFormScript = (options2) => {
|
|
|
4540
4573
|
isNativeToken,
|
|
4541
4574
|
balanceRevalidating,
|
|
4542
4575
|
fetchBalance,
|
|
4543
|
-
fetchBalances
|
|
4576
|
+
fetchBalances,
|
|
4577
|
+
targetChain
|
|
4544
4578
|
} = hooks.useDeposit({
|
|
4545
4579
|
address: sourceToken?.address,
|
|
4546
4580
|
decimals: sourceToken?.decimals,
|
|
@@ -4672,12 +4706,15 @@ var useDepositFormScript = (options2) => {
|
|
|
4672
4706
|
}
|
|
4673
4707
|
return false;
|
|
4674
4708
|
}, [quantity, maxQuantity]);
|
|
4709
|
+
const nativeBalance = useNativeBalance({
|
|
4710
|
+
fetchBalance,
|
|
4711
|
+
targetChain
|
|
4712
|
+
});
|
|
4675
4713
|
const insufficientGasMessage = react.useMemo(() => {
|
|
4676
4714
|
if (nativeSymbol && quantity && Number(quantity) > 0 && // when insufficient balance, the input status is error, so we don't need to check gas balance
|
|
4677
|
-
!insufficientBalance && !depositFeeRevalidating &&
|
|
4678
|
-
const
|
|
4679
|
-
const
|
|
4680
|
-
const isNotSolBalance = Number(fee.dstGasFee) === 0 && Number(nativeTokenBalance) == Number(fee.dstGasFee);
|
|
4715
|
+
!insufficientBalance && !depositFeeRevalidating && (account2.walletAdapter?.chainNamespace === types.ChainNamespace.solana || fee.dstGasFee) || nativeBalance === void 0) {
|
|
4716
|
+
const notEnoughGas = new utils.Decimal(nativeBalance || 0).lt(fee.dstGasFee);
|
|
4717
|
+
const isNotSolBalance = Number(fee.dstGasFee) === 0 && Number(nativeBalance) == Number(fee.dstGasFee);
|
|
4681
4718
|
if (notEnoughGas || isNotSolBalance) {
|
|
4682
4719
|
return t("transfer.deposit.notEnoughGas", {
|
|
4683
4720
|
token: nativeSymbol
|
|
@@ -4692,7 +4729,8 @@ var useDepositFormScript = (options2) => {
|
|
|
4692
4729
|
t,
|
|
4693
4730
|
nativeSymbol,
|
|
4694
4731
|
insufficientBalance,
|
|
4695
|
-
account2
|
|
4732
|
+
account2,
|
|
4733
|
+
nativeBalance
|
|
4696
4734
|
]);
|
|
4697
4735
|
const warningMessage = swapWarningMessage || userMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
|
|
4698
4736
|
const disabled = !quantity || Number(quantity) === 0 || !sourceToken || inputStatus === "error" || depositFeeRevalidating || swapRevalidating || // if exceed collateral cap, disable deposit
|
|
@@ -7215,17 +7253,17 @@ var findChainInfo = (tokenInfo) => {
|
|
|
7215
7253
|
const nativeTokenChainInfo = tokenInfo.chain_details.find(
|
|
7216
7254
|
(item) => !item.contract_address
|
|
7217
7255
|
);
|
|
7218
|
-
const
|
|
7256
|
+
const nativeTokenAddress3 = "0x0000000000000000000000000000000000000000";
|
|
7219
7257
|
if (arbitrumChainInfo) {
|
|
7220
7258
|
return {
|
|
7221
|
-
contract_address: arbitrumChainInfo.contract_address ||
|
|
7259
|
+
contract_address: arbitrumChainInfo.contract_address || nativeTokenAddress3,
|
|
7222
7260
|
quoteChainId: arbitrumChainInfo.chain_id,
|
|
7223
7261
|
decimals: arbitrumChainInfo.decimals
|
|
7224
7262
|
};
|
|
7225
7263
|
}
|
|
7226
7264
|
if (nativeTokenChainInfo) {
|
|
7227
7265
|
return {
|
|
7228
|
-
contract_address:
|
|
7266
|
+
contract_address: nativeTokenAddress3,
|
|
7229
7267
|
quoteChainId: nativeTokenChainInfo.chain_id,
|
|
7230
7268
|
decimals: nativeTokenChainInfo.decimals
|
|
7231
7269
|
};
|