Sha256: 9464470747487a7c2a83d5d1cbf29f7c95b42cf8051324f7c1b59ae6420fd975

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

/* eslint-disable require-jsdoc */

import { VoteComponent } from "@codegram/decidim-bulletin_board";

import * as VotingSchemesDummy from "@codegram/voting_schemes-dummy";
const DummyVoterWrapperAdapter = VotingSchemesDummy.VoterWrapperAdapter;
import * as VotingSchemesElectionGuard from "@codegram/voting_schemes-electionguard";
const ElectionGuardVoterWrapperAdapter = VotingSchemesElectionGuard.VoterWrapperAdapter;

export default function setupVoteComponent($voteWrapper) {
  // Data
  const bulletinBoardClientParams = {
    apiEndpointUrl: $voteWrapper.data("apiEndpointUrl")
  };
  const electionUniqueId = $voteWrapper.data("electionUniqueId");
  const authorityPublicKeyJSON = JSON.stringify(
    $voteWrapper.data("authorityPublicKey")
  );
  const voterUniqueId = $voteWrapper.data("voterId");
  const schemeName = $voteWrapper.data("schemeName");

  // Use the correct voter wrapper adapter
  let voterWrapperAdapter = null;

  if (schemeName === "dummy") {
    voterWrapperAdapter = new DummyVoterWrapperAdapter({
      voterId: voterUniqueId
    });
  } else if (schemeName === "electionguard") {
    voterWrapperAdapter = new ElectionGuardVoterWrapperAdapter({
      voterId: voterUniqueId,
      workerUrl: "/assets/electionguard/webworker.js"
    });
  } else {
    throw new Error(`Voting scheme ${schemeName} not supported.`);
  }

  // Returns the vote component
  return new VoteComponent({
    bulletinBoardClientParams,
    authorityPublicKeyJSON,
    electionUniqueId,
    voterUniqueId,
    voterWrapperAdapter
  });
}

window.Decidim = window.Decidim || {};
window.Decidim.setupVoteComponent = setupVoteComponent;

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.25.2 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.1 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.0 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.0.rc4 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.0.rc3 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.0.rc2 app/packs/src/decidim/elections/voter/setup-vote.js
decidim-elections-0.25.0.rc1 app/packs/src/decidim/elections/voter/setup-vote.js