Skip to content

Commit 2e8da23

Browse files
authored
Merge pull request #265 from dedis/239-verifiability-show-vote-hash-after-casting-a-vote
Issue #239 Verifiability of a vote
2 parents 92df6d6 + 4fbadd4 commit 2e8da23

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

web/frontend/src/language/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"alreadyVoted2": "on this form.",
161161
"changeVote": "You can change your vote by simply casting a new vote.",
162162
"pickCandidate": "Pick a candidate:",
163-
"voteSuccess": "Your vote was successfully submitted!",
163+
"voteSuccess": "Your vote was successfully submitted! VoteID:",
164164
"voteSuccessful": "Vote successful",
165165
"errorTitle": "Error",
166166
"actionChange": "Action Change",

web/frontend/src/mocks/handlers.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,15 @@ export const handlers = [
170170
Voters,
171171
});
172172

173-
return res(ctx.status(200), ctx.json({ Status: 0, Token: fakeToken }));
173+
const BallotID = uid();
174+
175+
return res(
176+
ctx.status(200),
177+
ctx.json({
178+
BallotID: BallotID,
179+
Ballot: Ballot,
180+
})
181+
);
174182
}),
175183

176184
rest.put(endpoints.editForm(':FormID'), async (req, res, ctx) => {

web/frontend/src/pages/ballot/Show.tsx

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useEffect, useState } from 'react';
1+
import { FC, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useParams } from 'react-router-dom';
44
import kyber from '@dedis/kyber';
@@ -10,7 +10,6 @@ import { MailIcon } from '@heroicons/react/outline';
1010
import { useNavigate } from 'react-router';
1111

1212
import useForm from 'components/utils/useForm';
13-
import usePostCall from 'components/utils/usePostCall';
1413
import * as endpoints from 'components/utils/Endpoints';
1514
import { encryptVote } from './components/VoteEncrypt';
1615
import { voteEncode } from './components/VoteEncode';
@@ -33,29 +32,13 @@ const Ballot: FC = () => {
3332

3433
const [userErrors, setUserErrors] = useState('');
3534
const edCurve = kyber.curve.newCurve('edwards25519');
36-
const [postError, setPostError] = useState('');
3735
const [showModal, setShowModal] = useState(false);
3836
const [modalText, setModalText] = useState(t('voteSuccess') as string);
3937
const [modalTitle, setModalTitle] = useState('');
4038
const [castVoteLoading, setCastVoteLoading] = useState(false);
41-
const sendFetchRequest = usePostCall(setPostError);
4239

4340
const navigate = useNavigate();
4441

45-
useEffect(() => {
46-
if (postError !== null) {
47-
if (postError.includes('ECONNREFUSED')) {
48-
setModalText(t('errorServerDown'));
49-
} else {
50-
setModalText(t('voteFailure'));
51-
}
52-
setModalTitle(t('errorTitle'));
53-
} else {
54-
setModalText(t('voteSuccess'));
55-
setModalTitle(t('voteSuccessful'));
56-
}
57-
}, [postError, t]);
58-
5942
const hexToBytes = (hex: string) => {
6043
const bytes: number[] = [];
6144
for (let c = 0; c < hex.length; c += 2) {
@@ -89,7 +72,26 @@ const Ballot: FC = () => {
8972
'Content-Type': 'Application/json',
9073
},
9174
};
92-
await sendFetchRequest(endpoints.newFormVote(formID.toString()), newRequest, setShowModal);
75+
try {
76+
const response = await fetch(endpoints.newFormVote(formID.toString()), newRequest);
77+
if (!response.ok) {
78+
const txt = await response.text();
79+
throw new Error(txt);
80+
}
81+
const res = await response.json();
82+
const id = res.BallotID || 'Not Implemented Yet, see issue 240';
83+
setModalText(`${t('voteSuccess')} ${id}`);
84+
setModalTitle(t('voteSuccessful'));
85+
} catch (error) {
86+
if (error.message.includes('ECONNREFUSED')) {
87+
setModalText(t('errorServerDown'));
88+
} else {
89+
setModalText(t('voteFailure'));
90+
}
91+
setModalTitle(t('errorTitle'));
92+
}
93+
94+
setShowModal((prev) => !prev);
9395
} catch (e) {
9496
console.log(e);
9597
setModalText(t('ballotFailure'));

0 commit comments

Comments
 (0)