diff --git a/screens/Trading/components/ClosePositionMobile.tsx b/screens/Trading/components/ClosePositionMobile.tsx index 098f73ec..68b133dd 100644 --- a/screens/Trading/components/ClosePositionMobile.tsx +++ b/screens/Trading/components/ClosePositionMobile.tsx @@ -49,7 +49,8 @@ const ClosePositionMobile: React.FC = ({ const [showFeeModal, setShowFeeModal] = useState(false); const [selectedCollateralType, setSelectedCollateralType] = useState(DEFAULT_POSITION); const [tokenInAmount, setTokenInAmount] = useState(null); - const [isDisabled, setIsDisabled] = useState(false); + const [isProcessingTx, setIsProcessingTx] = useState(false); + const [isEstimating, setIsEstimating] = useState(false); const [forceUpdate, setForceUpdate] = useState(0); const [swapUnSecurity, setSwapUnSecurity] = useState(false); const positionType = getPositionType(item.token_d_info.token_id); @@ -124,9 +125,8 @@ const ClosePositionMobile: React.FC = ({ }, 20_000); return () => clearInterval(intervalRef.current); }, []); - useEffect(() => { - setIsDisabled(!estimateData?.swap_indication || !estimateData?.min_amount_out); + setIsEstimating(!estimateData?.min_amount_out); }, [estimateData]); const Fee = useMemo(() => { @@ -157,14 +157,12 @@ const ClosePositionMobile: React.FC = ({ ).mul(assetD.price?.usd || 0); const saft_p_value = regular_p_value.mul(1 - marginConfig.max_slippage_rate / 10000); - if (regular_d_min_value.lte(saft_p_value)) { - setIsDisabled(false); + setIsProcessingTx(false); setSwapUnSecurity(true); return; } - - setIsDisabled(true); + setIsProcessingTx(true); setSwapUnSecurity(false); try { @@ -182,9 +180,7 @@ const ClosePositionMobile: React.FC = ({ token_p_amount: expandToken(tokenInAmount || "0", assetP.config.extra_decimals, 0), isMeme: isMemeStream, }); - onClose(); - if (res) { const transactionHashes = res.map((item) => { if (!item?.transaction?.hash) { @@ -200,7 +196,7 @@ const ClosePositionMobile: React.FC = ({ errorMessage: error instanceof Error ? error.message : JSON.stringify(error), }); } finally { - setIsDisabled(false); + setIsProcessingTx(false); } }; @@ -265,6 +261,8 @@ const ClosePositionMobile: React.FC = ({ if (!value) return "0"; return value.toFixed(6).replace(/\.?0+$/, ""); }; + const isLoading = isEstimating || isProcessingTx; + const isDisabled = isLoading || swapUnSecurity; return ( = ({ )} - - {/*
-
Close
-
*/} {swapUnSecurity && (
@@ -392,24 +381,24 @@ const ClosePositionMobile: React.FC = ({ {actionShowRedColor ? ( { localStorage.setItem("marginPopType", "Long"); handleCloseOpsitionEvt(); }} > - {isDisabled ? : `Close`} + {isLoading ? : `Close`} ) : ( { localStorage.setItem("marginPopType", "Short"); handleCloseOpsitionEvt(); }} > - {isDisabled ? : `Close`} + {isLoading ? : `Close`} )} diff --git a/screens/Trading/components/Table.tsx b/screens/Trading/components/Table.tsx index 24acb47a..4a4a07f9 100644 --- a/screens/Trading/components/Table.tsx +++ b/screens/Trading/components/Table.tsx @@ -670,8 +670,6 @@ const TradingTable = ({ { - // e.preventDefault(); - // e.stopPropagation(); setIsClosePositionMobileOpen(false); }} extraProps={closePositionModalProps}