Skip to content

Commit

Permalink
Handle new ElectionState variant structs (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkplug0025 authored Dec 16, 2021
1 parent cef3c48 commit 0de0fde
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/webapp/src/elections/api/eden-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export const getCurrentElection = async () => {
if (devUseFixtureData) return fixtureCurrentElection;

const rawRows = await getTableRawRows<any>(CONTRACT_CURRENT_ELECTION_TABLE);
const electionState = rawRows[0][0];
const electionState = convertElectionState(rawRows[0][0]);

const rows = rawRows.map((row) => row[1]);

Expand All @@ -287,6 +287,22 @@ export const getCurrentElection = async () => {
return { electionState, ...rows[0] };
};

const convertElectionState = (variantName: string) => {
switch (variantName) {
case "current_election_state_registration_v0":
case "current_election_state_registration_v1":
return "current_election_state_registration";
case "current_election_state_seeding_v0":
case "current_election_state_seeding_v1":
return "current_election_state_seeding";
case "current_election_state_init_voters_v0":
case "current_election_state_init_voters_v1":
return "current_election_state_init_voters";
default:
return variantName;
}
};

export const getElectionState = async () => {
if (devUseFixtureData) return fixtureElectionState;

Expand Down

0 comments on commit 0de0fde

Please sign in to comment.