Skip to content

Commit bcf527a

Browse files
committed
feat: reload page after finalize
1 parent 6dc9fdd commit bcf527a

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

plugins/maciVoting/components/finalize/finalizeAction.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { useMemo } from "react";
1+
import { useCallback, useMemo } from "react";
22
import { useCoordinator } from "../../hooks/useCoordinator";
33
import { Button } from "@aragon/ods";
44
import { PleaseWaitSpinner } from "@/components/please-wait";
55
import { If } from "@/components/if";
6+
import { useRouter } from "next/router";
67

78
interface IFinalizeActionProps {
89
pollId: number;
910
}
1011

1112
export const FinalizeAction: React.FC<IFinalizeActionProps> = ({ pollId }) => {
13+
const router = useRouter();
1214
const { finalizeStatus, finalizeProposal } = useCoordinator();
1315

1416
const finalizationMessage = useMemo(() => {
@@ -28,13 +30,18 @@ export const FinalizeAction: React.FC<IFinalizeActionProps> = ({ pollId }) => {
2830
}
2931
}, [finalizeStatus]);
3032

33+
const onClickFinalize = useCallback(async () => {
34+
await finalizeProposal(pollId);
35+
router.reload();
36+
}, [finalizeProposal, pollId, router]);
37+
3138
return (
3239
<div className="overflow-hidden rounded-xl bg-neutral-0 pb-2 shadow-neutral">
3340
<If condition={finalizeStatus !== "submitted"}>
3441
<div className="flex flex-col gap-y-2 px-4 py-4 md:gap-y-3 md:px-6 md:py-6">
3542
<div className="flex justify-between gap-x-2 gap-y-2">
3643
<p className="text-xl leading-tight text-neutral-800 md:text-2xl">Finalize Poll</p>
37-
<Button size="md" disabled={finalizeStatus !== "notStarted"} onClick={() => finalizeProposal(pollId)}>
44+
<Button size="md" disabled={finalizeStatus !== "notStarted"} onClick={onClickFinalize}>
3845
Finalize
3946
</Button>
4047
</div>

plugins/maciVoting/hooks/useResults.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,28 @@ export const useResults = (pollId?: bigint) => {
1717
return;
1818
}
1919

20-
const { endDate } = await getPoll({
21-
maciAddress: PUBLIC_MACI_ADDRESS,
22-
pollId,
23-
signer,
24-
});
25-
const now = Math.round(Date.now() / 1000);
20+
try {
21+
const { endDate } = await getPoll({
22+
maciAddress: PUBLIC_MACI_ADDRESS,
23+
pollId,
24+
signer,
25+
});
26+
const now = Math.round(Date.now() / 1000);
27+
const voteEnded = Number(endDate) < now;
28+
if (!voteEnded) {
29+
setTallied(false);
30+
return;
31+
}
2632

27-
const voteEnded = Number(endDate) < now;
28-
if (!voteEnded) {
29-
setTallied(false);
33+
const isTallied = await checkIsTallied(Number(pollId));
34+
setTallied(isTallied);
35+
} catch (error) {
36+
// eslint-disable-next-line no-console
37+
console.log(error);
38+
// TODO: handle error if poll does not exist
39+
//console.log(error.message);
3040
return;
3141
}
32-
33-
const isTallied = await checkIsTallied(Number(pollId));
34-
setTallied(isTallied);
3542
})();
3643
}, [checkIsTallied, pollId, signer]);
3744

0 commit comments

Comments
 (0)