Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/ballot-verifier/src/screens/ConfirmationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
StyledButton,
PlaintextVoteContest,
} from "@sequentech/ui-essentials"
import {sortContestList} from "@sequentech/ui-core"
import {keyBy} from "lodash"
import {useElectionClassName} from "./hooks/useElectionClassName"
import {SettingsContext} from "../providers/SettingsContextProvider"
Expand Down Expand Up @@ -249,6 +250,26 @@ const VerifySelectionsSection: React.FC<VerifySelectionsSectionProps> = ({
const [verifySelectionsHelp, setVerifySelectionsHelp] = useState(false)
const plaintextVoteQuestions = confirmationBallot?.decoded_questions || []
const questionsMap = keyBy(confirmationBallot?.election_config.contests || [], "id")
const contestsOrderType = confirmationBallot?.election_config.election_presentation?.contests_order
const sortedPlaintextVoteQuestions = useMemo(() => {
if (!plaintextVoteQuestions.length) {
return []
}

const sortedContests = sortContestList(
confirmationBallot?.election_config.contests || [],
contestsOrderType
)
const contestIndexMap = new Map(
sortedContests.map((contest, index) => [contest.id, index] as const)
)

return [...plaintextVoteQuestions].sort((a, b) => {
const firstIndex = contestIndexMap.get(a.contest_id) ?? Number.MAX_SAFE_INTEGER
const secondIndex = contestIndexMap.get(b.contest_id) ?? Number.MAX_SAFE_INTEGER
return firstIndex - secondIndex
})
}, [confirmationBallot?.election_config.contests, contestsOrderType, plaintextVoteQuestions])
const {globalSettings} = useContext(SettingsContext)

return (
Expand Down Expand Up @@ -304,7 +325,7 @@ const VerifySelectionsSection: React.FC<VerifySelectionsSectionProps> = ({
</>
) : (
<>
{plaintextVoteQuestions.map((voteQuestion) => (
{sortedPlaintextVoteQuestions.map((voteQuestion) => (
<PlaintextVoteContest
questionPlaintext={voteQuestion}
question={questionsMap[voteQuestion.contest_id] ?? null}
Expand Down