From 26eed1c0ddbd78b24f9385b5c97b5956da1f1e74 Mon Sep 17 00:00:00 2001 From: sirpy Date: Wed, 11 Dec 2024 11:31:16 +0200 Subject: [PATCH] fix: isDonating loading state --- .../app/src/components/DonateComponent.tsx | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/packages/app/src/components/DonateComponent.tsx b/packages/app/src/components/DonateComponent.tsx index 8145e93..8ae5b6a 100644 --- a/packages/app/src/components/DonateComponent.tsx +++ b/packages/app/src/components/DonateComponent.tsx @@ -309,39 +309,46 @@ const DonateComponent = ({ collective }: DonateComponentProps) => { const handleDonate = useCallback(async () => { let isApproveSuccess = isRequireApprove === false || currency.startsWith('G$'); - if (isRequireApprove && currency.startsWith('G$') === false) { - const txHash = await handleApproveToken?.(); - if (txHash === undefined) { - return; - } - let txReceipt: TransactionReceipt | undefined; - try { - txReceipt = await waitForTransaction({ - chainId: chain?.id, - confirmations: 1, - hash: txHash, - timeout: 1000 * 60 * 5, - }); - isApproveSuccess = txReceipt?.status === 'success'; - } catch (error) { - setErrorMessage( - 'Something went wrong: Your token approval transaction was not confirmed within the timeout period.' - ); + setIsDonating(true); + try { + if (isRequireApprove && currency.startsWith('G$') === false) { + const txHash = await handleApproveToken?.(); + if (txHash === undefined) { + return; + } + let txReceipt: TransactionReceipt | undefined; + try { + txReceipt = await waitForTransaction({ + chainId: chain?.id, + confirmations: 1, + hash: txHash, + timeout: 1000 * 60 * 5, + }); + isApproveSuccess = txReceipt?.status === 'success'; + } catch (error) { + setErrorMessage( + 'Something went wrong: Your token approval transaction was not confirmed within the timeout period.' + ); + } } - } - if (!isApproveSuccess) { - return; - } + if (!isApproveSuccess) { + return; + } - if (frequency === Frequency.OneTime) { - if (currency.startsWith('G$')) { - return await supportSingleTransferAndCall(); + if (frequency === Frequency.OneTime) { + if (currency.startsWith('G$')) { + return await supportSingleTransferAndCall(); + } else { + return await supportSingleWithSwap(); + } } else { - return await supportSingleWithSwap(); + handleStreamingWarning(); } - } else { - handleStreamingWarning(); + } catch (e) { + console.error('donation error:', e); + } finally { + setIsDonating(false); } }, [ chain?.id, @@ -631,7 +638,6 @@ const DonateComponent = ({ collective }: DonateComponentProps) => { priceImpact: isUnacceptablePriceImpact, balance: isInsufficientBalance, noAmount: !isNonZeroDonation, - noWallet: !address, invalidChain: isInvalidChain, }[key] ?? isInsufficientLiquidity; return whichWarning ? (