From e44d9a5911bd2eb5457ff057fbde7ce89b899a3d Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Mon, 30 May 2022 18:10:19 +0200 Subject: [PATCH] refactor: reset loading state if service is not enabled on Send page --- src/components/Send.jsx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/Send.jsx b/src/components/Send.jsx index 2ee1d8332..9d4ea236b 100644 --- a/src/components/Send.jsx +++ b/src/components/Send.jsx @@ -181,14 +181,8 @@ export default function Send() { const isCoinjoinInProgress = useMemo(() => serviceInfo && serviceInfo.coinjoinInProgress, [serviceInfo]) const isMakerRunning = useMemo(() => serviceInfo && serviceInfo.makerRunning, [serviceInfo]) - const waitForTakerToFinish = useMemo(() => isCoinjoinInProgress, [isCoinjoinInProgress]) - const isOperationDisabled = useMemo( - () => isCoinjoinInProgress || isMakerRunning, - [isCoinjoinInProgress, isMakerRunning] - ) const [alert, setAlert] = useState(null) - const [isLoading, setIsLoading] = useState(!isOperationDisabled) const [isSending, setIsSending] = useState(false) const [isCoinjoin, setIsCoinjoin] = useState(IS_COINJOIN_DEFAULT_VAL) const [minNumCollaborators, setMinNumCollaborators] = useState(MINIMUM_MAKERS_DEFAULT_VAL) @@ -198,6 +192,12 @@ export default function Send() { const [paymentSuccessfulInfoAlert, setPaymentSuccessfulInfoAlert] = useState(null) const [takerStartedInfoAlert, setTakerStartedInfoAlert] = useState(null) + const isOperationDisabled = useMemo( + () => isCoinjoinInProgress || isMakerRunning || waitForUtxosToBeSpent.length > 0, + [isCoinjoinInProgress, isMakerRunning, waitForUtxosToBeSpent] + ) + const [isLoading, setIsLoading] = useState(!isOperationDisabled) + useEffect(() => { setTakerStartedInfoAlert((current) => (isCoinjoinInProgress ? current : null)) }, [isCoinjoinInProgress]) @@ -263,7 +263,6 @@ export default function Send() { useEffect(() => { if (waitForUtxosToBeSpent.length === 0) return - setIsLoading(true) const abortCtrl = new AbortController() // Delaying the poll requests gives the wallet some time to synchronize @@ -279,7 +278,6 @@ export default function Send() { const outputs = data.data.utxos.utxos.map((it) => it.utxo) const utxosStillPresent = waitForUtxosToBeSpent.filter((it) => outputs.includes(it)) setWaitForUtxosToBeSpent([...utxosStillPresent]) - setIsLoading(utxosStillPresent.length > 0) }) .catch((err) => { if (abortCtrl.signal.aborted) return @@ -287,7 +285,6 @@ export default function Send() { // Stop waiting for wallet synchronization on errors, but inform // the user that loading the wallet info failed setWaitForUtxosToBeSpent([]) - setIsLoading(false) const message = err.message || t('send.error_loading_wallet_failed') setAlert({ variant: 'danger', message }) @@ -301,8 +298,10 @@ export default function Send() { }, [waitForUtxosToBeSpent, reloadCurrentWalletInfo, t]) useEffect(() => { - if (waitForTakerToFinish) return - if (waitForUtxosToBeSpent.length > 0) return + if (isOperationDisabled) { + setIsLoading(false) + return + } const abortCtrl = new AbortController() @@ -339,7 +338,7 @@ export default function Send() { ) return () => abortCtrl.abort() - }, [waitForTakerToFinish, waitForUtxosToBeSpent, wallet, reloadCurrentWalletInfo, reloadServiceInfo, t]) + }, [isOperationDisabled, wallet, reloadCurrentWalletInfo, reloadServiceInfo, t]) const sendPayment = async (account, destination, amount_sats) => { setAlert(null)