diff --git a/apps/voting/app/src/app-state-reducer.js b/apps/voting/app/src/app-state-reducer.js index 84566361a7..49de0ca4b9 100644 --- a/apps/voting/app/src/app-state-reducer.js +++ b/apps/voting/app/src/app-state-reducer.js @@ -8,7 +8,13 @@ function appStateReducer(state) { return { ...state, ready } } - const { pctBase, tokenDecimals, voteTime, votes } = state + const { + pctBase, + tokenDecimals, + voteTime, + votes, + connectedAccountVotes, + } = state const pctBaseNum = parseInt(pctBase, 10) const tokenDecimalsNum = parseInt(tokenDecimals, 10) @@ -26,6 +32,8 @@ function appStateReducer(state) { tokenDecimals: tokenDecimalsNum, }, + connectedAccountVotes: connectedAccountVotes || {}, + // Transform the vote data for the frontend votes: votes ? votes.map(vote => { diff --git a/apps/voting/app/src/script.js b/apps/voting/app/src/script.js index 0e00a363ff..f22d233c84 100644 --- a/apps/voting/app/src/script.js +++ b/apps/voting/app/src/script.js @@ -167,10 +167,12 @@ async function updateConnectedAccount(state, { account }) { return { ...state, // fetch all the votes casted by the connected account - connectedAccountVotes: await getAccountVotes({ - connectedAccount: account, - votes: state.votes, - }), + connectedAccountVotes: state.votes + ? await getAccountVotes({ + connectedAccount: account, + votes: state.votes, + }) + : {}, } } @@ -221,8 +223,8 @@ async function startVote(state, { creator, metadata, voteId }) { * Helpers * * * ***********************/ - -async function getAccountVotes({ connectedAccount, votes }) { +// Default votes to an empty array to prevent errors on initial load +async function getAccountVotes({ connectedAccount, votes = [] }) { const connectedAccountVotes = await Promise.all( votes.map(({ voteId }) => getVoterState({ connectedAccount, voteId })) )