Skip to content

Commit 284c401

Browse files
committed
chore: remove code
1 parent 45d61ce commit 284c401

File tree

1 file changed

+44
-67
lines changed

1 file changed

+44
-67
lines changed

web/src/pages/MyTransactions/TransactionDetails/PreviewCardButtons/RaiseDisputeButton.tsx

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ const RaiseDisputeButton: React.FC<IRaiseDisputeButton> = ({ toggleModal, button
2626
const isBuyer = useMemo(() => address?.toLowerCase() === buyer?.toLowerCase(), [address, buyer]);
2727
const refetchQuery = useQueryRefetch();
2828

29-
const { data: payArbitrationFeeByBuyerConfig, error: simulateBuyerError } =
29+
const { data: payArbitrationFeeByBuyerConfig, isLoading: isPreparingBuyerConfig } =
3030
useSimulateEscrowUniversalPayArbitrationFeeByBuyer({
31+
query: {
32+
enabled: isBuyer,
33+
},
3134
args: [BigInt(id)],
3235
value: arbitrationCost,
3336
});
3437

35-
const { data: payArbitrationFeeBySellerConfig, error: simulateSellerError } =
38+
const { data: payArbitrationFeeBySellerConfig, isLoading: isPreparingSellerConfig } =
3639
useSimulateEscrowUniversalPayArbitrationFeeBySeller({
40+
query: {
41+
enabled: !isBuyer,
42+
},
3743
args: [BigInt(id)],
3844
value: arbitrationCost,
3945
});
@@ -45,76 +51,47 @@ const RaiseDisputeButton: React.FC<IRaiseDisputeButton> = ({ toggleModal, button
4551
);
4652

4753
const handleRaiseDispute = () => {
48-
if (isBuyer) {
49-
if (simulateBuyerError) {
50-
console.log({simulateBuyerError});
51-
let errorMessage = "An error occurred during simulation.";
52-
if (simulateBuyerError.message.includes("insufficient funds")) {
53-
errorMessage = "You don't have enough balance to raise a dispute.";
54-
}
55-
// Use wrapWithToast to display the error
56-
wrapWithToast(() => Promise.reject(new Error(errorMessage)), publicClient);
57-
return;
58-
}
59-
60-
if (isUndefined(payArbitrationFeeByBuyerConfig)) {
61-
console.log({ payArbitrationFeeByBuyerConfig });
62-
console.log({ simulateBuyerError });
63-
wrapWithToast(() => Promise.reject(new Error("Unable to prepare transaction.")), publicClient);
64-
return;
65-
}
66-
67-
if (!isUndefined(payArbitrationFeeByBuyer)) {
68-
setIsSending(true);
69-
wrapWithToast(() => payArbitrationFeeByBuyer(payArbitrationFeeByBuyerConfig.request), publicClient)
70-
.then((wrapResult) => {
54+
if (isBuyer && !isUndefined(payArbitrationFeeByBuyer)) {
55+
setIsSending(true);
56+
wrapWithToast(async () => await payArbitrationFeeByBuyer(payArbitrationFeeByBuyerConfig.request), publicClient)
57+
.then((wrapResult) => {
58+
if (wrapResult.status) {
59+
toggleModal && toggleModal();
60+
refetchQuery([["refetchOnBlock", "useTransactionDetailsQuery"]]);
61+
} else {
7162
setIsSending(false);
72-
if (wrapResult.status) {
73-
toggleModal && toggleModal();
74-
refetchQuery([["refetchOnBlock", "useTransactionDetailsQuery"]]);
75-
}
76-
})
77-
.catch((error) => {
78-
console.error("Error raising dispute as buyer:", error);
63+
}
64+
})
65+
.catch((error) => {
66+
console.error("Error raising dispute as buyer:", error);
67+
setIsSending(false);
68+
});
69+
} else if (!isBuyer && !isUndefined(payArbitrationFeeBySeller)) {
70+
setIsSending(true);
71+
wrapWithToast(async () => await payArbitrationFeeBySeller(payArbitrationFeeBySellerConfig.request), publicClient)
72+
.then((wrapResult) => {
73+
if (wrapResult.status) {
74+
toggleModal && toggleModal();
75+
refetchQuery([["refetchOnBlock", "useTransactionDetailsQuery"]]);
76+
} else {
7977
setIsSending(false);
80-
});
81-
}
82-
} else {
83-
if (simulateSellerError) {
84-
let errorMessage = "An error occurred during simulation.";
85-
if (simulateSellerError.message.includes("insufficient funds")) {
86-
errorMessage = "You don't have enough balance to raise a dispute.";
87-
}
88-
wrapWithToast(() => Promise.reject(new Error(errorMessage)), publicClient);
89-
return;
90-
}
91-
92-
if (isUndefined(payArbitrationFeeBySellerConfig)) {
93-
console.log({ payArbitrationFeeBySellerConfig });
94-
console.log({ simulateSellerError });
95-
wrapWithToast(() => Promise.reject(new Error("Unable to prepare transaction.")), publicClient);
96-
return;
97-
}
98-
99-
if (!isUndefined(payArbitrationFeeBySeller)) {
100-
setIsSending(true);
101-
wrapWithToast(() => payArbitrationFeeBySeller(payArbitrationFeeBySellerConfig.request), publicClient)
102-
.then((wrapResult) => {
103-
setIsSending(false);
104-
if (wrapResult.status) {
105-
toggleModal && toggleModal();
106-
refetchQuery([["refetchOnBlock", "useTransactionDetailsQuery"]]);
107-
}
108-
})
109-
.catch((error) => {
110-
console.error("Error raising dispute as seller:", error);
111-
setIsSending(false);
112-
});
113-
}
78+
}
79+
})
80+
.catch((error) => {
81+
console.error("Error raising dispute as seller:", error);
82+
setIsSending(false);
83+
});
11484
}
11585
};
11686

117-
return <Button isLoading={isSending} disabled={isSending} text={buttonText} onClick={handleRaiseDispute} />;
87+
return (
88+
<Button
89+
isLoading={isSending || isPreparingBuyerConfig || isPreparingSellerConfig}
90+
disabled={isSending || isPreparingBuyerConfig || isPreparingSellerConfig}
91+
text={buttonText}
92+
onClick={handleRaiseDispute}
93+
/>
94+
);
11895
};
11996

12097
export default RaiseDisputeButton;

0 commit comments

Comments
 (0)