Skip to content

Commit

Permalink
Prefetch of the circuits for anon. voting. vocdoni/ui-scaffold#289
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeon committed Oct 10, 2023
1 parent d2d22c7 commit 2534049
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/react-providers/src/election/use-election-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ export const useElectionProvider = ({
}
}, [actions, client, election])

const fetchAnonCircuits = useCallback(() => {
const hasOverwriteEnabled =
typeof election !== 'undefined' &&
typeof election.voteType.maxVoteOverwrites !== 'undefined' &&
election.voteType.maxVoteOverwrites > 0

const votable = state.isAbleToVote || (hasOverwriteEnabled && state.isInCensus && state.voted)

if (votable && election?.census.type === CensusType.ANONYMOUS) {
client.anonymousService.fetchCircuits()
}
}, [election, state.isAbleToVote, state.isInCensus, state.voted, client.anonymousService])

// pre-fetches circuits needed for voting in anonymous elections
useEffect(() => {
if (!fetchCensus || !election || loading.census || !client.wallet) return
fetchAnonCircuits()
}, [fetchAnonCircuits, client.wallet, election, loading.census, fetchCensus])

// CSP OAuth flow
// As vote setting and voting token are async, we need to wait for both to be set
useEffect(() => {
Expand Down

0 comments on commit 2534049

Please sign in to comment.