From 4afc2ad92c5633eeb7545f716c46703ff42193ab Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Wed, 17 Apr 2019 18:50:01 +0200 Subject: [PATCH 1/2] Voting: fix bug with votes not loading initially --- apps/voting/app/src/app-state-reducer.js | 10 +++++++++- apps/voting/app/src/script.js | 12 +++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) 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..7d3832249e 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, + }) + : {}, } } @@ -222,7 +224,7 @@ async function startVote(state, { creator, metadata, voteId }) { * * ***********************/ -async function getAccountVotes({ connectedAccount, votes }) { +async function getAccountVotes({ connectedAccount, votes = [] }) { const connectedAccountVotes = await Promise.all( votes.map(({ voteId }) => getVoterState({ connectedAccount, voteId })) ) From 23cdc538a95a5a978dc754db9fa60301664c3f89 Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Wed, 17 Apr 2019 18:58:24 +0200 Subject: [PATCH 2/2] Add comment --- apps/voting/app/src/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/voting/app/src/script.js b/apps/voting/app/src/script.js index 7d3832249e..f22d233c84 100644 --- a/apps/voting/app/src/script.js +++ b/apps/voting/app/src/script.js @@ -223,7 +223,7 @@ async function startVote(state, { creator, metadata, voteId }) { * Helpers * * * ***********************/ - +// 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 }))