@orderly.network/ui-transfer 2.8.3 → 2.8.4
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 +132 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -104
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +13 -13
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useTranslation, i18n, Trans } from '@orderly.network/i18n';
|
|
2
2
|
import { modal, useScreen, useModal, SimpleSheet, SimpleDialog, registerSimpleDialog, registerSimpleSheet, Tabs, TabPanel, ArrowDownSquareFillIcon, ArrowUpSquareFillIcon, toast, Box, ExtensionSlot, ExtensionPositionEnum, textVariants, Flex, Text, Button, cn, Divider, Spinner, Select, Input, inputFormatter, AlertDialog, EditIcon, Icon, TokenIcon, WalletIcon, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, ScrollArea, Tooltip, ExclamationFillIcon, CloseCircleFillIcon, CheckedCircleFillIcon, ChainIcon, Badge, CloseIcon } from '@orderly.network/ui';
|
|
3
3
|
import { forwardRef, useState, useMemo, useEffect, useCallback, useRef, createElement } from 'react';
|
|
4
|
-
import { useEventEmitter, useConfig, useWalletConnector, useLocalStorage, useConvert, useOdosQuote, useComputedLTV, useBoolean, useAccountInstance, useAccount, useAppStore, useTransfer, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useTokensInfo, usePositionStream, useIndexPricesStream, useDeposit, useAssetsHistory, useChains,
|
|
4
|
+
import { useEventEmitter, useConfig, useWalletConnector, useLocalStorage, useConvert, useOdosQuote, useComputedLTV, useBoolean, useAccountInstance, useAccount, useAppStore, useTransfer, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useTokensInfo, usePositionStream, useIndexPricesStream, useDeposit, useAssetsHistory, useChains, useWithdraw, useMemoizedFn, useWalletTopic, useQuery, 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
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
|
-
import { AuthGuard } from '@orderly.network/ui-connector';
|
|
8
|
+
import { AuthGuard, useAuthGuard } 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';
|
|
11
11
|
import { account } from '@orderly.network/perp';
|
|
@@ -339,7 +339,7 @@ var TransferVerticalIcon = (props) => /* @__PURE__ */ jsx(
|
|
|
339
339
|
}
|
|
340
340
|
);
|
|
341
341
|
var ChainSelect = (props) => {
|
|
342
|
-
const { chains, value, wrongNetwork, loading } = props;
|
|
342
|
+
const { chains, value, wrongNetwork, loading, disabled } = props;
|
|
343
343
|
const [open, setOpen] = useState(false);
|
|
344
344
|
const { t } = useTranslation();
|
|
345
345
|
const selectable = wrongNetwork || chains?.length > 1;
|
|
@@ -370,7 +370,7 @@ var ChainSelect = (props) => {
|
|
|
370
370
|
intensity: 500,
|
|
371
371
|
className: cn(
|
|
372
372
|
"oui-rounded-t-xl oui-rounded-b-sm oui-border oui-border-line",
|
|
373
|
-
selectable ? "oui-cursor-pointer" : "oui-cursor-auto"
|
|
373
|
+
disabled ? "oui-cursor-not-allowed" : selectable ? "oui-cursor-pointer" : "oui-cursor-auto"
|
|
374
374
|
),
|
|
375
375
|
height: 54,
|
|
376
376
|
px: 3,
|
|
@@ -426,7 +426,7 @@ var ChainSelect = (props) => {
|
|
|
426
426
|
);
|
|
427
427
|
});
|
|
428
428
|
return /* @__PURE__ */ jsxs(DropdownMenuRoot, { open: selectable ? open : false, onOpenChange: setOpen, children: [
|
|
429
|
-
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: trigger }),
|
|
429
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { disabled, asChild: true, children: trigger }),
|
|
430
430
|
/* @__PURE__ */ jsx(DropdownMenuPortal, { children: /* @__PURE__ */ jsx(
|
|
431
431
|
DropdownMenuContent,
|
|
432
432
|
{
|
|
@@ -4665,6 +4665,7 @@ var useDepositFormScript = (options2) => {
|
|
|
4665
4665
|
quantity,
|
|
4666
4666
|
maxQuantity
|
|
4667
4667
|
});
|
|
4668
|
+
const isLoggedIn = useAuthGuard();
|
|
4668
4669
|
const {
|
|
4669
4670
|
collateralRatio: collateralRatio2,
|
|
4670
4671
|
collateralContributionQuantity,
|
|
@@ -4817,7 +4818,8 @@ var useDepositFormScript = (options2) => {
|
|
|
4817
4818
|
warningMessage,
|
|
4818
4819
|
targetQuantity,
|
|
4819
4820
|
targetQuantityLoading,
|
|
4820
|
-
tokenBalances
|
|
4821
|
+
tokenBalances,
|
|
4822
|
+
isLoggedIn
|
|
4821
4823
|
};
|
|
4822
4824
|
};
|
|
4823
4825
|
function useDepositFee(options2) {
|
|
@@ -5025,7 +5027,8 @@ var DepositForm = (props) => {
|
|
|
5025
5027
|
value: currentChain,
|
|
5026
5028
|
onValueChange: onChainChange,
|
|
5027
5029
|
wrongNetwork,
|
|
5028
|
-
loading: settingChain
|
|
5030
|
+
loading: settingChain,
|
|
5031
|
+
disabled: !props.isLoggedIn
|
|
5029
5032
|
}
|
|
5030
5033
|
),
|
|
5031
5034
|
/* @__PURE__ */ jsx(
|
|
@@ -5043,7 +5046,8 @@ var DepositForm = (props) => {
|
|
|
5043
5046
|
hintMessage,
|
|
5044
5047
|
fetchBalance,
|
|
5045
5048
|
tokenBalances: props.tokenBalances,
|
|
5046
|
-
"data-testId": "oui-testid-deposit-dialog-quantity-input"
|
|
5049
|
+
"data-testId": "oui-testid-deposit-dialog-quantity-input",
|
|
5050
|
+
disabled: !props.isLoggedIn
|
|
5047
5051
|
}
|
|
5048
5052
|
)
|
|
5049
5053
|
] }),
|
|
@@ -5079,7 +5083,8 @@ var DepositForm = (props) => {
|
|
|
5079
5083
|
loading: targetQuantityLoading,
|
|
5080
5084
|
classNames: {
|
|
5081
5085
|
root: "oui-mt-3 oui-border-transparent focus-within:oui-outline-transparent"
|
|
5082
|
-
}
|
|
5086
|
+
},
|
|
5087
|
+
disabled: !props.isLoggedIn
|
|
5083
5088
|
}
|
|
5084
5089
|
),
|
|
5085
5090
|
renderContent()
|
|
@@ -5181,11 +5186,13 @@ var TextAreaInput = (props) => {
|
|
|
5181
5186
|
"oui-border oui-border-line focus:oui-border-primary-light",
|
|
5182
5187
|
status === "error" && "oui-border-danger-light focus-within:oui-border-danger-light focus:oui-border-danger-light",
|
|
5183
5188
|
status === "warning" && "oui-border-warning-light focus-within:oui-border-warning-light focus:oui-border-warning-light",
|
|
5189
|
+
"disabled:oui-cursor-not-allowed",
|
|
5184
5190
|
props.className
|
|
5185
5191
|
),
|
|
5186
5192
|
rows: 1,
|
|
5187
5193
|
value,
|
|
5188
|
-
onChange: handleChange
|
|
5194
|
+
onChange: handleChange,
|
|
5195
|
+
disabled: props.disabled
|
|
5189
5196
|
}
|
|
5190
5197
|
),
|
|
5191
5198
|
hintMessage && message
|
|
@@ -5441,22 +5448,9 @@ var WithdrawAction = (props) => {
|
|
|
5441
5448
|
) });
|
|
5442
5449
|
};
|
|
5443
5450
|
var WithdrawWarningMessage = (props) => {
|
|
5444
|
-
const {
|
|
5445
|
-
chainVaultBalance,
|
|
5446
|
-
currentChain,
|
|
5447
|
-
crossChainTrans,
|
|
5448
|
-
tokenName,
|
|
5449
|
-
qtyGreaterThanMaxAmount,
|
|
5450
|
-
qtyGreaterThanVault
|
|
5451
|
-
} = props;
|
|
5451
|
+
const { crossChainTrans, qtyGreaterThanMaxAmount } = props;
|
|
5452
5452
|
const { t } = useTranslation();
|
|
5453
5453
|
const { state } = useAccount();
|
|
5454
|
-
const chainName = useMemo(() => {
|
|
5455
|
-
if (currentChain && currentChain.info && currentChain.info.network_infos) {
|
|
5456
|
-
return currentChain.info.network_infos.name;
|
|
5457
|
-
}
|
|
5458
|
-
return void 0;
|
|
5459
|
-
}, [currentChain]);
|
|
5460
5454
|
const renderContent = () => {
|
|
5461
5455
|
if (state.status === AccountStatusEnum.NotConnected) {
|
|
5462
5456
|
return null;
|
|
@@ -5467,13 +5461,6 @@ var WithdrawWarningMessage = (props) => {
|
|
|
5467
5461
|
if (qtyGreaterThanMaxAmount) {
|
|
5468
5462
|
return t("transfer.insufficientBalance");
|
|
5469
5463
|
}
|
|
5470
|
-
if (qtyGreaterThanVault) {
|
|
5471
|
-
return t("transfer.withdraw.vaultWarning", {
|
|
5472
|
-
tokenName,
|
|
5473
|
-
chainName,
|
|
5474
|
-
balance: chainVaultBalance
|
|
5475
|
-
});
|
|
5476
|
-
}
|
|
5477
5464
|
return props.message;
|
|
5478
5465
|
};
|
|
5479
5466
|
const content = renderContent();
|
|
@@ -5503,15 +5490,13 @@ var WithdrawForm = (props) => {
|
|
|
5503
5490
|
currentChain,
|
|
5504
5491
|
fee,
|
|
5505
5492
|
settingChain,
|
|
5506
|
-
chainVaultBalance,
|
|
5507
5493
|
crossChainTrans,
|
|
5508
5494
|
checkIsBridgeless,
|
|
5509
5495
|
withdrawTo,
|
|
5510
5496
|
sourceTokens,
|
|
5511
5497
|
onSourceTokenChange,
|
|
5512
5498
|
vaultBalanceList,
|
|
5513
|
-
qtyGreaterThanMaxAmount
|
|
5514
|
-
qtyGreaterThanVault
|
|
5499
|
+
qtyGreaterThanMaxAmount
|
|
5515
5500
|
} = props;
|
|
5516
5501
|
const { t } = useTranslation();
|
|
5517
5502
|
const internalWithdrawPanel = /* @__PURE__ */ jsxs(
|
|
@@ -5529,7 +5514,8 @@ var WithdrawForm = (props) => {
|
|
|
5529
5514
|
value: props.toAccountId,
|
|
5530
5515
|
onChange: props.setToAccountId,
|
|
5531
5516
|
status: props.toAccountIdInputStatus,
|
|
5532
|
-
hintMessage: props.toAccountIdHintMessage
|
|
5517
|
+
hintMessage: props.toAccountIdHintMessage,
|
|
5518
|
+
disabled: !props.isLoggedIn
|
|
5533
5519
|
}
|
|
5534
5520
|
),
|
|
5535
5521
|
/* @__PURE__ */ jsx(Box, { my: 2, children: /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 54, children: t("transfer.withdraw.accountId.tips") }) })
|
|
@@ -5556,7 +5542,8 @@ var WithdrawForm = (props) => {
|
|
|
5556
5542
|
hintMessage: props.hintMessage,
|
|
5557
5543
|
vaultBalanceList,
|
|
5558
5544
|
testId: "oui-testid-withdraw-dialog-quantity-input",
|
|
5559
|
-
displayType: "vaultBalance"
|
|
5545
|
+
displayType: "vaultBalance",
|
|
5546
|
+
disabled: !props.isLoggedIn
|
|
5560
5547
|
}
|
|
5561
5548
|
) }),
|
|
5562
5549
|
/* @__PURE__ */ jsx(
|
|
@@ -5598,7 +5585,7 @@ var WithdrawForm = (props) => {
|
|
|
5598
5585
|
TabPanel,
|
|
5599
5586
|
{
|
|
5600
5587
|
title: t("transfer.web3Wallet.my"),
|
|
5601
|
-
icon: /* @__PURE__ */ jsx(WalletIcon, { size: "xs", name: props.walletName ?? "" }),
|
|
5588
|
+
icon: props.walletName ? /* @__PURE__ */ jsx(WalletIcon, { size: "xs", name: props.walletName ?? "" }) : void 0,
|
|
5602
5589
|
value: "wallet" /* Wallet */,
|
|
5603
5590
|
children: [
|
|
5604
5591
|
/* @__PURE__ */ jsx(
|
|
@@ -5608,7 +5595,8 @@ var WithdrawForm = (props) => {
|
|
|
5608
5595
|
value: currentChain,
|
|
5609
5596
|
onValueChange: props.onChainChange,
|
|
5610
5597
|
wrongNetwork: props.wrongNetwork,
|
|
5611
|
-
loading: settingChain
|
|
5598
|
+
loading: settingChain,
|
|
5599
|
+
disabled: !props.isLoggedIn
|
|
5612
5600
|
}
|
|
5613
5601
|
),
|
|
5614
5602
|
/* @__PURE__ */ jsx(
|
|
@@ -5647,11 +5635,7 @@ var WithdrawForm = (props) => {
|
|
|
5647
5635
|
WithdrawWarningMessage,
|
|
5648
5636
|
{
|
|
5649
5637
|
checkIsBridgeless,
|
|
5650
|
-
chainVaultBalance,
|
|
5651
|
-
currentChain,
|
|
5652
5638
|
crossChainTrans,
|
|
5653
|
-
tokenName: sourceToken?.symbol,
|
|
5654
|
-
qtyGreaterThanVault,
|
|
5655
5639
|
qtyGreaterThanMaxAmount,
|
|
5656
5640
|
message: props.warningMessage
|
|
5657
5641
|
}
|
|
@@ -5716,6 +5700,87 @@ var useSettlePnl = (options2) => {
|
|
|
5716
5700
|
onSettlePnl
|
|
5717
5701
|
};
|
|
5718
5702
|
};
|
|
5703
|
+
var cctpSupportedChains = [43114, 1, 137, 42161, 10, 8453, 1329];
|
|
5704
|
+
var cctpSupportedTokens = ["USDC"];
|
|
5705
|
+
var useVaultBalance = (inputs) => {
|
|
5706
|
+
const {
|
|
5707
|
+
currentChain,
|
|
5708
|
+
sourceToken,
|
|
5709
|
+
withdrawTo,
|
|
5710
|
+
quantity,
|
|
5711
|
+
qtyGreaterThanMaxAmount
|
|
5712
|
+
} = inputs;
|
|
5713
|
+
const { t } = useTranslation();
|
|
5714
|
+
const { data: vaultBalanceData } = useQuery(
|
|
5715
|
+
`/v1/public/vault_balance`,
|
|
5716
|
+
{
|
|
5717
|
+
revalidateOnMount: true,
|
|
5718
|
+
errorRetryCount: 3
|
|
5719
|
+
}
|
|
5720
|
+
);
|
|
5721
|
+
const vaultBalanceList = useMemo(() => {
|
|
5722
|
+
if (withdrawTo === "accountId" /* Account */ || !currentChain || !Array.isArray(vaultBalanceData)) {
|
|
5723
|
+
return [];
|
|
5724
|
+
}
|
|
5725
|
+
return vaultBalanceData.filter(
|
|
5726
|
+
(item) => Number.parseInt(item.chain_id) === currentChain?.id
|
|
5727
|
+
);
|
|
5728
|
+
}, [vaultBalanceData, currentChain, withdrawTo]);
|
|
5729
|
+
const chainVaultBalance = useMemo(() => {
|
|
5730
|
+
const vaultBalance = vaultBalanceList?.find(
|
|
5731
|
+
(item) => item.token === sourceToken?.symbol
|
|
5732
|
+
);
|
|
5733
|
+
return vaultBalance?.balance;
|
|
5734
|
+
}, [vaultBalanceList, sourceToken]);
|
|
5735
|
+
const qtyGreaterThanVault = useMemo(() => {
|
|
5736
|
+
if (!quantity || Number.isNaN(quantity) || !chainVaultBalance || Number.isNaN(chainVaultBalance)) {
|
|
5737
|
+
return false;
|
|
5738
|
+
}
|
|
5739
|
+
return new Decimal(quantity).gt(chainVaultBalance);
|
|
5740
|
+
}, [quantity, chainVaultBalance, withdrawTo]);
|
|
5741
|
+
const crossChainWithdraw = useMemo(() => {
|
|
5742
|
+
const canCCTP = currentChain?.id && sourceToken?.symbol ? cctpSupportedChains.includes(currentChain?.id) && cctpSupportedTokens.includes(sourceToken?.symbol) : false;
|
|
5743
|
+
return qtyGreaterThanVault && canCCTP && !qtyGreaterThanMaxAmount;
|
|
5744
|
+
}, [qtyGreaterThanVault, qtyGreaterThanMaxAmount, currentChain, sourceToken]);
|
|
5745
|
+
const chainName = useMemo(() => {
|
|
5746
|
+
if (currentChain && currentChain.info && currentChain.info.network_infos) {
|
|
5747
|
+
return currentChain.info.network_infos.name;
|
|
5748
|
+
}
|
|
5749
|
+
return "";
|
|
5750
|
+
}, [currentChain]);
|
|
5751
|
+
const vaultBalanceMessage = useMemo(() => {
|
|
5752
|
+
if (qtyGreaterThanVault && !crossChainWithdraw && chainName) {
|
|
5753
|
+
return t("transfer.withdraw.vaultWarning", {
|
|
5754
|
+
tokenName: sourceToken?.symbol,
|
|
5755
|
+
chainName,
|
|
5756
|
+
balance: chainVaultBalance
|
|
5757
|
+
});
|
|
5758
|
+
}
|
|
5759
|
+
return "";
|
|
5760
|
+
}, [
|
|
5761
|
+
qtyGreaterThanVault,
|
|
5762
|
+
crossChainWithdraw,
|
|
5763
|
+
chainName,
|
|
5764
|
+
sourceToken,
|
|
5765
|
+
chainVaultBalance
|
|
5766
|
+
]);
|
|
5767
|
+
const vaultBalanceListFilterCCTP = useMemo(() => {
|
|
5768
|
+
if (cctpSupportedChains.includes(currentChain?.id)) {
|
|
5769
|
+
return vaultBalanceList?.filter(
|
|
5770
|
+
(item) => !cctpSupportedTokens.includes(item.token)
|
|
5771
|
+
);
|
|
5772
|
+
}
|
|
5773
|
+
return vaultBalanceList;
|
|
5774
|
+
}, [vaultBalanceList, currentChain]);
|
|
5775
|
+
return {
|
|
5776
|
+
vaultBalanceList: vaultBalanceListFilterCCTP,
|
|
5777
|
+
// chainVaultBalance,
|
|
5778
|
+
// if the token is cross chain withdraw supported, the qtyGreaterThanVault will be false
|
|
5779
|
+
qtyGreaterThanVault: qtyGreaterThanVault && !crossChainWithdraw,
|
|
5780
|
+
crossChainWithdraw,
|
|
5781
|
+
vaultBalanceMessage
|
|
5782
|
+
};
|
|
5783
|
+
};
|
|
5719
5784
|
function useWithdrawAccountId(options2) {
|
|
5720
5785
|
const { token, quantity, setQuantity, close, setLoading, decimals } = options2;
|
|
5721
5786
|
const { t } = useTranslation();
|
|
@@ -5930,19 +5995,13 @@ var useWithdrawFormScript = (options2) => {
|
|
|
5930
5995
|
filter: (chain) => chain.network_infos?.bridge_enable || chain.network_infos?.bridgeless
|
|
5931
5996
|
});
|
|
5932
5997
|
const [linkDeviceStorage] = useLocalStorage("orderly_link_device", {});
|
|
5933
|
-
const { data: vaultBalanceList } = useQuery(
|
|
5934
|
-
`/v1/public/vault_balance`,
|
|
5935
|
-
{
|
|
5936
|
-
revalidateOnMount: true,
|
|
5937
|
-
errorRetryCount: 3
|
|
5938
|
-
}
|
|
5939
|
-
);
|
|
5940
5998
|
const {
|
|
5941
5999
|
connectedChain,
|
|
5942
6000
|
wallet,
|
|
5943
6001
|
setChain: switchChain,
|
|
5944
6002
|
settingChain
|
|
5945
6003
|
} = useWalletConnector();
|
|
6004
|
+
const isLoggedIn = useAuthGuard();
|
|
5946
6005
|
const currentChain = useMemo(() => {
|
|
5947
6006
|
const chainId = connectedChain ? praseChainIdToNumber(connectedChain.id) : Number.parseInt(linkDeviceStorage?.chainId);
|
|
5948
6007
|
if (!chainId) {
|
|
@@ -5983,6 +6042,27 @@ var useWithdrawFormScript = (options2) => {
|
|
|
5983
6042
|
token: sourceToken?.symbol,
|
|
5984
6043
|
decimals: sourceToken?.token_decimal
|
|
5985
6044
|
});
|
|
6045
|
+
const qtyGreaterThanMaxAmount = useMemo(() => {
|
|
6046
|
+
if (!quantity || Number.isNaN(quantity)) {
|
|
6047
|
+
return false;
|
|
6048
|
+
}
|
|
6049
|
+
if (!maxAmount || Number.isNaN(maxAmount)) {
|
|
6050
|
+
return true;
|
|
6051
|
+
}
|
|
6052
|
+
return new Decimal(quantity).gt(maxAmount);
|
|
6053
|
+
}, [quantity, maxAmount]);
|
|
6054
|
+
const {
|
|
6055
|
+
vaultBalanceList,
|
|
6056
|
+
qtyGreaterThanVault,
|
|
6057
|
+
crossChainWithdraw,
|
|
6058
|
+
vaultBalanceMessage
|
|
6059
|
+
} = useVaultBalance({
|
|
6060
|
+
currentChain,
|
|
6061
|
+
sourceToken,
|
|
6062
|
+
withdrawTo,
|
|
6063
|
+
quantity,
|
|
6064
|
+
qtyGreaterThanMaxAmount
|
|
6065
|
+
});
|
|
5986
6066
|
const withdrawAccountIdState = useWithdrawAccountId({
|
|
5987
6067
|
token: sourceToken?.symbol,
|
|
5988
6068
|
decimals: sourceToken?.token_decimal,
|
|
@@ -6033,47 +6113,6 @@ var useWithdrawFormScript = (options2) => {
|
|
|
6033
6113
|
},
|
|
6034
6114
|
[currentChain, switchChain, findByChainId, t]
|
|
6035
6115
|
);
|
|
6036
|
-
const chainVaultBalance = useMemo(() => {
|
|
6037
|
-
if (!Array.isArray(vaultBalanceList) || !currentChain) {
|
|
6038
|
-
return null;
|
|
6039
|
-
}
|
|
6040
|
-
const vaultBalance = vaultBalanceList.find(
|
|
6041
|
-
(item) => Number.parseInt(item.chain_id) === currentChain?.id && item.token === sourceToken?.symbol
|
|
6042
|
-
);
|
|
6043
|
-
if (vaultBalance) {
|
|
6044
|
-
return vaultBalance.balance;
|
|
6045
|
-
}
|
|
6046
|
-
return null;
|
|
6047
|
-
}, [chains, currentChain, vaultBalanceList, sourceToken?.symbol]);
|
|
6048
|
-
const qtyGreaterThanMaxAmount = useMemo(() => {
|
|
6049
|
-
if (!quantity || Number.isNaN(quantity)) {
|
|
6050
|
-
return false;
|
|
6051
|
-
}
|
|
6052
|
-
if (!maxAmount || Number.isNaN(maxAmount)) {
|
|
6053
|
-
return true;
|
|
6054
|
-
}
|
|
6055
|
-
return new Decimal(quantity).gt(maxAmount);
|
|
6056
|
-
}, [quantity, maxAmount]);
|
|
6057
|
-
const qtyGreaterThanVault = useMemo(() => {
|
|
6058
|
-
if (withdrawTo === "accountId" /* Account */) {
|
|
6059
|
-
return false;
|
|
6060
|
-
}
|
|
6061
|
-
if (!quantity || Number.isNaN(quantity)) {
|
|
6062
|
-
return false;
|
|
6063
|
-
}
|
|
6064
|
-
if (!chainVaultBalance || Number.isNaN(chainVaultBalance)) {
|
|
6065
|
-
return true;
|
|
6066
|
-
}
|
|
6067
|
-
return new Decimal(quantity).gt(chainVaultBalance);
|
|
6068
|
-
}, [quantity, chainVaultBalance, withdrawTo]);
|
|
6069
|
-
const crossChainWithdraw = useMemo(() => {
|
|
6070
|
-
if (chainVaultBalance !== null) {
|
|
6071
|
-
const qtyNum = Number.parseFloat(quantity);
|
|
6072
|
-
const value = qtyNum > chainVaultBalance && qtyNum <= maxAmount;
|
|
6073
|
-
return value;
|
|
6074
|
-
}
|
|
6075
|
-
return false;
|
|
6076
|
-
}, [quantity, maxAmount, chainVaultBalance]);
|
|
6077
6116
|
const onWithdraw = async () => {
|
|
6078
6117
|
if (loading) {
|
|
6079
6118
|
return;
|
|
@@ -6155,7 +6194,6 @@ var useWithdrawFormScript = (options2) => {
|
|
|
6155
6194
|
}
|
|
6156
6195
|
}
|
|
6157
6196
|
}, [quantity, maxAmount, unsettledPnL, crossChainTrans]);
|
|
6158
|
-
const disabled = crossChainTrans || !quantity || Number(quantity) === 0 || ["error", "warning"].includes(inputStatus) || withdrawTo === "accountId" /* Account */ && !withdrawAccountIdState.toAccountId || qtyGreaterThanMaxAmount || qtyGreaterThanVault || !!minAmountWarningMessage;
|
|
6159
6197
|
useEffect(() => {
|
|
6160
6198
|
setCrossChainTrans(!!assetHistory?.length);
|
|
6161
6199
|
}, [assetHistory?.length]);
|
|
@@ -6177,15 +6215,8 @@ var useWithdrawFormScript = (options2) => {
|
|
|
6177
6215
|
token: sourceToken?.symbol,
|
|
6178
6216
|
quantity
|
|
6179
6217
|
});
|
|
6180
|
-
const
|
|
6181
|
-
const
|
|
6182
|
-
if (withdrawTo === "accountId" /* Account */) {
|
|
6183
|
-
return [];
|
|
6184
|
-
}
|
|
6185
|
-
return vaultBalanceList?.filter(
|
|
6186
|
-
(item) => Number.parseInt(item.chain_id) === currentChain?.id
|
|
6187
|
-
);
|
|
6188
|
-
}, [vaultBalanceList, currentChain, withdrawTo]);
|
|
6218
|
+
const disabled = crossChainTrans || !quantity || Number(quantity) === 0 || ["error", "warning"].includes(inputStatus) || withdrawTo === "accountId" /* Account */ && !withdrawAccountIdState.toAccountId || qtyGreaterThanMaxAmount || !!minAmountWarningMessage || qtyGreaterThanVault;
|
|
6219
|
+
const warningMessage = minAmountWarningMessage || ltvWarningMessage || vaultBalanceMessage;
|
|
6189
6220
|
return {
|
|
6190
6221
|
walletName,
|
|
6191
6222
|
address,
|
|
@@ -6208,7 +6239,6 @@ var useWithdrawFormScript = (options2) => {
|
|
|
6208
6239
|
currentChain,
|
|
6209
6240
|
onChainChange,
|
|
6210
6241
|
onWithdraw,
|
|
6211
|
-
chainVaultBalance,
|
|
6212
6242
|
fee,
|
|
6213
6243
|
crossChainWithdraw,
|
|
6214
6244
|
crossChainTrans,
|
|
@@ -6219,14 +6249,14 @@ var useWithdrawFormScript = (options2) => {
|
|
|
6219
6249
|
onSettlePnl,
|
|
6220
6250
|
brokerName,
|
|
6221
6251
|
qtyGreaterThanMaxAmount,
|
|
6222
|
-
|
|
6223
|
-
vaultBalanceList: filteredVaultBalanceList,
|
|
6252
|
+
vaultBalanceList,
|
|
6224
6253
|
...withdrawAccountIdState,
|
|
6225
6254
|
withdrawTo,
|
|
6226
6255
|
setWithdrawTo,
|
|
6227
6256
|
currentLTV,
|
|
6228
6257
|
nextLTV,
|
|
6229
|
-
warningMessage
|
|
6258
|
+
warningMessage,
|
|
6259
|
+
isLoggedIn
|
|
6230
6260
|
};
|
|
6231
6261
|
};
|
|
6232
6262
|
var WithdrawFormWidget = (props) => {
|