);
diff --git a/packages/interface/src/components/Info.tsx b/packages/interface/src/components/Info.tsx
index 78ad4db8..100f56e9 100644
--- a/packages/interface/src/components/Info.tsx
+++ b/packages/interface/src/components/Info.tsx
@@ -73,7 +73,7 @@ export const Info = ({
];
return (
-
+
{showRoundInfo && }
diff --git a/packages/interface/src/contexts/Maci.tsx b/packages/interface/src/contexts/Maci.tsx
index 35544e58..b38857f8 100644
--- a/packages/interface/src/contexts/Maci.tsx
+++ b/packages/interface/src/contexts/Maci.tsx
@@ -275,14 +275,19 @@ export const MaciProvider: React.FC = ({ children }: MaciProv
// function to be used to vote on a poll
const onVote = useCallback(
- async (votes: IVoteArgs[], pollId: string, onError: () => Promise, onSuccess: () => Promise) => {
+ async (
+ votes: IVoteArgs[],
+ pollId: string,
+ onError: (err: string) => Promise,
+ onSuccess: () => Promise,
+ ) => {
if (!signer || !stateIndex) {
return;
}
if (!votes.length) {
- onError();
setError("No votes provided");
+ onError("No votes provided");
return;
}
@@ -307,7 +312,7 @@ export const MaciProvider: React.FC = ({ children }: MaciProv
.then(() => onSuccess())
.catch((err: Error) => {
setError(err.message);
- return onError();
+ return onError(err.message);
})
.finally(() => {
setIsLoading(false);
diff --git a/packages/interface/src/contexts/types.ts b/packages/interface/src/contexts/types.ts
index 98f7b86f..3ea83fae 100644
--- a/packages/interface/src/contexts/types.ts
+++ b/packages/interface/src/contexts/types.ts
@@ -26,7 +26,7 @@ export interface MaciContextType {
onVote: (
args: IVoteArgs[],
pollId: string,
- onError: () => void | Promise,
+ onError: (err: string) => void | Promise,
onSuccess: () => void | Promise,
) => Promise;
}
diff --git a/packages/interface/src/features/ballot/components/SubmitBallotButton.tsx b/packages/interface/src/features/ballot/components/SubmitBallotButton.tsx
index f3420cbe..b7b875d8 100644
--- a/packages/interface/src/features/ballot/components/SubmitBallotButton.tsx
+++ b/packages/interface/src/features/ballot/components/SubmitBallotButton.tsx
@@ -1,9 +1,9 @@
import { useRouter } from "next/router";
-import { useState, useCallback, useMemo } from "react";
+import { useCallback, useMemo } from "react";
import { toast } from "sonner";
import { Button } from "~/components/ui/Button";
-import { Dialog } from "~/components/ui/Dialog";
+import { Spinner } from "~/components/ui/Spinner";
import { useBallot } from "~/contexts/Ballot";
import { useMaci } from "~/contexts/Maci";
@@ -13,21 +13,22 @@ interface ISubmitBallotButtonProps {
export const SubmitBallotButton = ({ pollId }: ISubmitBallotButtonProps): JSX.Element => {
const router = useRouter();
- const [isOpen, setOpen] = useState(false);
const { onVote, isLoading, initialVoiceCredits } = useMaci();
const { getBallot, publishBallot, sumBallot } = useBallot();
- const onVotingError = useCallback(() => {
- toast.error("Voting error");
+ const onVotingError = useCallback((err: string) => {
+ toast.error(`Voting error: ${err}`);
}, []);
const ballot = useMemo(() => getBallot(pollId), [pollId, getBallot]);
- const ableToSubmit = useMemo(
- () => sumBallot(ballot.votes) <= initialVoiceCredits,
- [sumBallot, ballot, initialVoiceCredits],
- );
+ const sum = useMemo(() => sumBallot(ballot.votes), [ballot, sumBallot]);
+ const ableToSubmit = useMemo(() => sum <= initialVoiceCredits && sum > 0, [sum, initialVoiceCredits]);
const handleSubmitBallot = useCallback(async () => {
+ if (isLoading || !ableToSubmit) {
+ return;
+ }
+
const votes = ballot.votes.map(({ amount, projectId, projectIndex }) => ({
projectId,
voteOptionIndex: BigInt(projectIndex),
@@ -42,38 +43,17 @@ export const SubmitBallotButton = ({ pollId }: ISubmitBallotButtonProps): JSX.El
publishBallot(pollId);
router.push(`/rounds/${pollId}/ballot/confirmation`);
});
- }, [ballot, router, onVote, publishBallot, onVotingError, pollId, pollId]);
-
- const handleOpenDialog = useCallback(() => {
- setOpen(true);
- }, [setOpen]);
+ }, [ballot, router, onVote, publishBallot, onVotingError, pollId, isLoading, ableToSubmit]);
return (
- <>
-
+
);
};
diff --git a/packages/interface/src/layouts/DefaultLayout.tsx b/packages/interface/src/layouts/DefaultLayout.tsx
index 93b0a8d2..5225bd9b 100644
--- a/packages/interface/src/layouts/DefaultLayout.tsx
+++ b/packages/interface/src/layouts/DefaultLayout.tsx
@@ -104,7 +104,6 @@ export const LayoutWithSidebar = ({ ...props }: ILayoutProps): JSX.Element => {
return (