@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.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { forwardRef, useState, useMemo, useEffect, useCallback, useRef, createEl
|
|
|
4
4
|
import { useEventEmitter, useConfig, useWalletConnector, useLocalStorage, useConvert, useOdosQuote, useComputedLTV, useBoolean, useAccountInstance, useAccount, useAppStore, useTransfer, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useTokensInfo, usePositionStream, useIndexPricesStream, useDeposit, useAssetsHistory, useChains, useQuery, useWithdraw, useMemoizedFn, useWalletTopic, useTokenInfo, useIndexPrice, useInternalTransfer, useDebouncedCallback, useTransferHistory, useBalanceTopic } from '@orderly.network/hooks';
|
|
5
5
|
import { Decimal, zero, praseChainIdToNumber, int2hex, toNonExponential, isSolana } from '@orderly.network/utils';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
-
import { WS_WalletStatusEnum, AccountStatusEnum, ChainNamespace, AssetHistoryStatusEnum, AssetHistorySideEnum, Arbitrum, isNativeTokenChecker as isNativeTokenChecker$1, ABSTRACT_CHAIN_ID_MAP } from '@orderly.network/types';
|
|
7
|
+
import { WS_WalletStatusEnum, AccountStatusEnum, ChainNamespace, AssetHistoryStatusEnum, AssetHistorySideEnum, Arbitrum, isNativeTokenChecker as isNativeTokenChecker$1, ABSTRACT_CHAIN_ID_MAP, nativeTokenAddress as nativeTokenAddress$1 } from '@orderly.network/types';
|
|
8
8
|
import { AuthGuard } from '@orderly.network/ui-connector';
|
|
9
9
|
import { useAppContext, useAppConfig } from '@orderly.network/react-app';
|
|
10
10
|
import { ChainSelectorDialogId } from '@orderly.network/ui-chain-selector';
|
|
@@ -4421,6 +4421,39 @@ function useInputStatus(options2) {
|
|
|
4421
4421
|
}, [quantity, maxQuantity]);
|
|
4422
4422
|
return { inputStatus, hintMessage };
|
|
4423
4423
|
}
|
|
4424
|
+
var retryInterval2 = 3e3;
|
|
4425
|
+
function useNativeBalance(options2) {
|
|
4426
|
+
const { fetchBalance, targetChain } = options2;
|
|
4427
|
+
const [balance, setBalance] = useState();
|
|
4428
|
+
const timeoutRef = useRef();
|
|
4429
|
+
const loopGetTokenBalance = async (timeout = 0) => {
|
|
4430
|
+
const decimal = targetChain?.network_infos?.currency_decimal;
|
|
4431
|
+
if (typeof fetchBalance !== "function" || !decimal) {
|
|
4432
|
+
return;
|
|
4433
|
+
}
|
|
4434
|
+
if (timeoutRef.current) {
|
|
4435
|
+
clearTimeout(timeoutRef.current);
|
|
4436
|
+
}
|
|
4437
|
+
timeoutRef.current = setTimeout(async () => {
|
|
4438
|
+
fetchBalance(nativeTokenAddress$1, decimal).then((balance2) => {
|
|
4439
|
+
console.log("native balance", balance2);
|
|
4440
|
+
setBalance(balance2);
|
|
4441
|
+
}).catch((error) => {
|
|
4442
|
+
console.error("fetch native balance error", error);
|
|
4443
|
+
loopGetTokenBalance(retryInterval2);
|
|
4444
|
+
});
|
|
4445
|
+
}, timeout);
|
|
4446
|
+
};
|
|
4447
|
+
useEffect(() => {
|
|
4448
|
+
loopGetTokenBalance(0);
|
|
4449
|
+
return () => {
|
|
4450
|
+
if (timeoutRef.current) {
|
|
4451
|
+
clearTimeout(timeoutRef.current);
|
|
4452
|
+
}
|
|
4453
|
+
};
|
|
4454
|
+
}, []);
|
|
4455
|
+
return balance;
|
|
4456
|
+
}
|
|
4424
4457
|
var useToken = (currentChain, filter = () => true) => {
|
|
4425
4458
|
const [sourceToken, setSourceToken] = useState();
|
|
4426
4459
|
const [targetToken, setTargetToken] = useState();
|
|
@@ -4538,7 +4571,8 @@ var useDepositFormScript = (options2) => {
|
|
|
4538
4571
|
isNativeToken,
|
|
4539
4572
|
balanceRevalidating,
|
|
4540
4573
|
fetchBalance,
|
|
4541
|
-
fetchBalances
|
|
4574
|
+
fetchBalances,
|
|
4575
|
+
targetChain
|
|
4542
4576
|
} = useDeposit({
|
|
4543
4577
|
address: sourceToken?.address,
|
|
4544
4578
|
decimals: sourceToken?.decimals,
|
|
@@ -4670,12 +4704,15 @@ var useDepositFormScript = (options2) => {
|
|
|
4670
4704
|
}
|
|
4671
4705
|
return false;
|
|
4672
4706
|
}, [quantity, maxQuantity]);
|
|
4707
|
+
const nativeBalance = useNativeBalance({
|
|
4708
|
+
fetchBalance,
|
|
4709
|
+
targetChain
|
|
4710
|
+
});
|
|
4673
4711
|
const insufficientGasMessage = useMemo(() => {
|
|
4674
4712
|
if (nativeSymbol && quantity && Number(quantity) > 0 && // when insufficient balance, the input status is error, so we don't need to check gas balance
|
|
4675
|
-
!insufficientBalance && !depositFeeRevalidating &&
|
|
4676
|
-
const
|
|
4677
|
-
const
|
|
4678
|
-
const isNotSolBalance = Number(fee.dstGasFee) === 0 && Number(nativeTokenBalance) == Number(fee.dstGasFee);
|
|
4713
|
+
!insufficientBalance && !depositFeeRevalidating && (account2.walletAdapter?.chainNamespace === ChainNamespace.solana || fee.dstGasFee) || nativeBalance === void 0) {
|
|
4714
|
+
const notEnoughGas = new Decimal(nativeBalance || 0).lt(fee.dstGasFee);
|
|
4715
|
+
const isNotSolBalance = Number(fee.dstGasFee) === 0 && Number(nativeBalance) == Number(fee.dstGasFee);
|
|
4679
4716
|
if (notEnoughGas || isNotSolBalance) {
|
|
4680
4717
|
return t("transfer.deposit.notEnoughGas", {
|
|
4681
4718
|
token: nativeSymbol
|
|
@@ -4690,7 +4727,8 @@ var useDepositFormScript = (options2) => {
|
|
|
4690
4727
|
t,
|
|
4691
4728
|
nativeSymbol,
|
|
4692
4729
|
insufficientBalance,
|
|
4693
|
-
account2
|
|
4730
|
+
account2,
|
|
4731
|
+
nativeBalance
|
|
4694
4732
|
]);
|
|
4695
4733
|
const warningMessage = swapWarningMessage || userMaxQtyMessage || gasFeeMessage || feeWarningMessage || insufficientGasMessage;
|
|
4696
4734
|
const disabled = !quantity || Number(quantity) === 0 || !sourceToken || inputStatus === "error" || depositFeeRevalidating || swapRevalidating || // if exceed collateral cap, disable deposit
|
|
@@ -7213,17 +7251,17 @@ var findChainInfo = (tokenInfo) => {
|
|
|
7213
7251
|
const nativeTokenChainInfo = tokenInfo.chain_details.find(
|
|
7214
7252
|
(item) => !item.contract_address
|
|
7215
7253
|
);
|
|
7216
|
-
const
|
|
7254
|
+
const nativeTokenAddress3 = "0x0000000000000000000000000000000000000000";
|
|
7217
7255
|
if (arbitrumChainInfo) {
|
|
7218
7256
|
return {
|
|
7219
|
-
contract_address: arbitrumChainInfo.contract_address ||
|
|
7257
|
+
contract_address: arbitrumChainInfo.contract_address || nativeTokenAddress3,
|
|
7220
7258
|
quoteChainId: arbitrumChainInfo.chain_id,
|
|
7221
7259
|
decimals: arbitrumChainInfo.decimals
|
|
7222
7260
|
};
|
|
7223
7261
|
}
|
|
7224
7262
|
if (nativeTokenChainInfo) {
|
|
7225
7263
|
return {
|
|
7226
|
-
contract_address:
|
|
7264
|
+
contract_address: nativeTokenAddress3,
|
|
7227
7265
|
quoteChainId: nativeTokenChainInfo.chain_id,
|
|
7228
7266
|
decimals: nativeTokenChainInfo.decimals
|
|
7229
7267
|
};
|