Skip to content

Commit e0ef942

Browse files
committed
fixup! feat(web-ui): add optional ballot text summary
1 parent 58cc85d commit e0ef942

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

packages/web-ui/src/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
});
3434
3535
function maybeUpdateSummary() {
36-
ballotSummary = shouldSummarize ? (async () => {
36+
ballotSummary = shouldSummarize && ballot ? (async () => {
3737
// Lazy-loading as the summary is only a nice-to-have.
3838
const { getSummarizedBallot } = await import("./ballotSummary.ts");
3939
return getSummarizedBallot(ballot);
@@ -43,7 +43,7 @@
4343
encryptDataPromise = (async () => {
4444
const { encryptedSecret, saltedCiphertext } = await encryptData(
4545
textEncoder.encode(ballotContent) as Uint8Array,
46-
await fetchedPublicKey
46+
await publicKey
4747
);
4848
return JSON.stringify({
4949
encryptedSecret: uint8ArrayToBase64(new Uint8Array(encryptedSecret)),

packages/web-ui/src/FillBallotForm.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{#await fetchedPublicKey}
3232
<button type="submit" disabled>Loading public key…</button>
3333
{:then}
34-
<button type="submit">Encrypt ballot</button>
34+
<button type="submit">Next</button>
3535
{/await}
3636
</form>
3737
{:catch error}

packages/web-ui/src/ballotSummary.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66

77
export function getSummarizedBallot(ballotStr: string) {
88
const ballot = yaml.load(ballotStr) as { preferences: Array<{title: string, score: number}> };
9+
if (!Array.isArray(ballot?.preferences)) {
10+
throw new Error('Ballot does not contain a list of preferences');
11+
}
912
return summarizeCondorcetBallotForVoter(
1013
_getSummarizedBallot({
1114
voter: {},

0 commit comments

Comments
 (0)