Skip to content

Commit

Permalink
fix: isDonating loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Dec 11, 2024
1 parent b87b7f7 commit 26eed1c
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions packages/app/src/components/DonateComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -631,7 +638,6 @@ const DonateComponent = ({ collective }: DonateComponentProps) => {
priceImpact: isUnacceptablePriceImpact,
balance: isInsufficientBalance,
noAmount: !isNonZeroDonation,
noWallet: !address,
invalidChain: isInvalidChain,
}[key] ?? isInsufficientLiquidity;
return whichWarning ? (
Expand Down

0 comments on commit 26eed1c

Please sign in to comment.