Skip to content

Commit a62ab94

Browse files
feat: add error modal
1 parent ec52238 commit a62ab94

File tree

2 files changed

+73
-11
lines changed

2 files changed

+73
-11
lines changed

packages/common/src/allo/backends/allo-v2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,12 @@ export class AlloV2 implements Allo {
14801480
});
14811481

14821482
if (approvalTx.type === "error") {
1483-
return approvalTx;
1483+
const result = new AlloError(
1484+
"Failed to approve token transfer",
1485+
approvalTx.error
1486+
);
1487+
emit("tokenApprovalStatus", error(result));
1488+
return error(result);
14841489
}
14851490
try {
14861491
const receipt = await this.transactionSender.wait(approvalTx.value);

packages/grant-explorer/src/features/projects/ViewProject.tsx

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import { useConnectModal } from "@rainbow-me/rainbowkit";
5454
import { getBalance } from "@wagmi/core";
5555
import { config } from "../../app/wagmi";
5656
import { ethers } from "ethers";
57+
import { useNavigate } from "react-router-dom";
58+
import { Logger } from "ethers/lib/utils";
5759

5860
const CalendarIcon = (props: React.SVGProps<SVGSVGElement>) => {
5961
return (
@@ -83,6 +85,10 @@ export default function ViewProject() {
8385
const [showDirectAllocationModal, setShowDirectAllocationModal] =
8486
useState<boolean>(false);
8587
const [openProgressModal, setOpenProgressModal] = useState(false);
88+
const [openErrorModal, setOpenErrorModal] = useState(false);
89+
const [errorModalSubHeading, setErrorModalSubHeading] = useState<
90+
string | undefined
91+
>();
8692
const [directDonationAmount, setDirectDonationAmount] = useState<string>("");
8793

8894
const payoutTokenOptions: TToken[] = getVotingTokenOptions(
@@ -120,6 +126,7 @@ export default function ViewProject() {
120126

121127
const [hasClickedSubmit, setHasClickedSubmit] = useState(false);
122128
const [isEmptyInput, setIsEmptyInput] = useState(false);
129+
const [transactionReplaced, setTransactionReplaced] = useState(false);
123130

124131
useEffect(() => {
125132
if (directDonationAmount === "" || Number(directDonationAmount) === 0) {
@@ -133,6 +140,7 @@ export default function ViewProject() {
133140

134141
const dataLayer = useDataLayer();
135142
const allo = useAllo();
143+
const navigate = useNavigate();
136144

137145
const {
138146
data: projectData,
@@ -156,8 +164,13 @@ export default function ViewProject() {
156164
dataLayer
157165
);
158166

159-
const { directAllocation, tokenApprovalStatus, fundStatus, indexingStatus } =
160-
useDirectAllocation();
167+
const {
168+
directAllocation,
169+
tokenApprovalStatus,
170+
fundStatus,
171+
indexingStatus,
172+
txHash,
173+
} = useDirectAllocation();
161174

162175
const pastRroundApplications = projectApplications?.filter(
163176
(projectApplication) =>
@@ -166,6 +179,50 @@ export default function ViewProject() {
166179

167180
const project = projectData?.project;
168181

182+
useEffect(() => {
183+
if (
184+
tokenApprovalStatus === ProgressStatus.IS_ERROR ||
185+
fundStatus === ProgressStatus.IS_ERROR
186+
) {
187+
setTimeout(() => {
188+
setOpenProgressModal(false);
189+
setErrorModalSubHeading(
190+
transactionReplaced
191+
? "Transaction cancelled. Please try again."
192+
: "There was an error during the funding process. Please try again."
193+
);
194+
setOpenErrorModal(true);
195+
}, errorModalDelayMs);
196+
}
197+
198+
if (indexingStatus === ProgressStatus.IS_ERROR) {
199+
setTimeout(() => {
200+
// refresh
201+
navigate(0);
202+
}, 5000);
203+
}
204+
205+
if (
206+
tokenApprovalStatus === ProgressStatus.IS_SUCCESS &&
207+
fundStatus === ProgressStatus.IS_SUCCESS &&
208+
txHash !== ""
209+
) {
210+
setTimeout(() => {
211+
setOpenProgressModal(false);
212+
// refresh
213+
navigate(0);
214+
}, errorModalDelayMs);
215+
}
216+
}, [
217+
navigate,
218+
tokenApprovalStatus,
219+
fundStatus,
220+
indexingStatus,
221+
txHash,
222+
transactionReplaced,
223+
projectId,
224+
]);
225+
169226
const breadCrumbs = [
170227
{
171228
name: "Explorer Home",
@@ -440,12 +497,12 @@ export default function ViewProject() {
440497
subheading={"Please hold while we donate your funds to the project."}
441498
steps={progressSteps}
442499
/>
443-
{/* <ErrorModal
500+
<ErrorModal
444501
isOpen={openErrorModal}
445502
setIsOpen={setOpenErrorModal}
446-
tryAgainFn={handleSubmitFund}
503+
onTryAgain={handleDonate}
447504
subheading={errorModalSubHeading}
448-
/> */}
505+
/>
449506
</>
450507
);
451508
}
@@ -465,10 +522,6 @@ export default function ViewProject() {
465522
setOpenProgressModal(true);
466523

467524
try {
468-
setTimeout(() => {
469-
setOpenProgressModal(true);
470-
}, errorModalDelayMs);
471-
472525
let requireTokenApproval = false;
473526

474527
const poolId = getDirectAllocationPoolId(chainId ?? 1)?.toString();
@@ -507,7 +560,11 @@ export default function ViewProject() {
507560
requireTokenApproval,
508561
});
509562
} catch (error) {
510-
console.error("handleDonation - project", projectId, error);
563+
if (error === Logger.errors.TRANSACTION_REPLACED) {
564+
setTransactionReplaced(true);
565+
} else {
566+
console.error("handleDonation - project", projectId, error);
567+
}
511568
}
512569
}
513570
}

0 commit comments

Comments
 (0)