dappuniversity / election

A Decentralized Ethereum Voting Application Tutorial
563 stars 506 forks source link

Multiple render #20

Open Dhruv1107 opened 5 years ago

Dhruv1107 commented 5 years ago

What is the solution for multiple rendering? When i add a new account and reload the page the list of candidates is showing multiple times. I have tried modifying listenForEvents in app.js, but nothing seems to work. capture2

DtzMan commented 5 years ago

same problem for me too

moseley commented 5 years ago

See Issue #2

pchavan150 commented 5 years ago

change this fromBlock: 0, toBlock: 'latest' to fromBlock: 'latest', toBlock: 'latest'

in app.js file

9w6nuu commented 4 years ago

change this fromBlock: 0, toBlock: 'latest' to fromBlock: 'latest', toBlock: 'latest'

in app.js file

I did. something changed. but still I have some issue here. this time it shows not multiple but 2 times

loadWeb3: async function() { if(window.ethereum) { window.web3 = new Web3(window.ethereum); await ethereum.enable(); } else if(window.web3){ window.web3 = new Web3(web3.currentProvider); } else{ window.alert('Non-Ethereum brower detected. You should consider trying MetaMask!'); } return App.initContract(); }, is this because i changed this too? in app.js line 40 initContract: function() { $.getJSON("Election.json", function(election) { App.contracts.Election = TruffleContract(election); App.contracts.Election.setProvider(web3.currentProvider); App.listenForEvents(); return App.render(); }); },

pchavan150 commented 4 years ago

change this fromBlock: 0, toBlock: 'latest' to fromBlock: 'latest', toBlock: 'latest' in app.js file

I did. something changed. but still I have some issue here. this time it shows not multiple but 2 times

loadWeb3: async function() { if(window.ethereum) { window.web3 = new Web3(window.ethereum); await ethereum.enable(); } else if(window.web3){ window.web3 = new Web3(web3.currentProvider); } else{ window.alert('Non-Ethereum brower detected. You should consider trying MetaMask!'); } return App.initContract();},` is this because i changed this too? in app.js line 40 initContract: function() { $.getJSON("Election.json", function(election) { App.contracts.Election = TruffleContract(election); App.contracts.Election.setProvider(web3.currentProvider); App.listenForEvents(); return App.render(); }); },`

Yes I faced too so I removed event section...so it solved everything

Jadhoo commented 4 years ago

change this fromBlock: 0, toBlock: 'latest' to fromBlock: 'latest', toBlock: 'latest' in app.js file

I did. something changed. but still I have some issue here. this time it shows not multiple but 2 times loadWeb3: async function() { if(window.ethereum) { window.web3 = new Web3(window.ethereum); await ethereum.enable(); } else if(window.web3){ window.web3 = new Web3(web3.currentProvider); } else{ window.alert('Non-Ethereum brower detected. You should consider trying MetaMask!'); } return App.initContract();},` is this because i changed this too? in app.js line 40 initContract: function() { $.getJSON("Election.json", function(election) { App.contracts.Election = TruffleContract(election); App.contracts.Election.setProvider(web3.currentProvider); App.listenForEvents(); return App.render(); }); },`

Yes I faced too so I removed event section...so it solved everything

Yeah, removing the votedEvent in Election.sol solved the issue, but while performing 'truffle test', it fails to pass the 3rd condition👇 1) allows a voter to cast a vote

DLanzafamedelRio commented 4 months ago

So it actually works without any problems: instance.votedEvent({}, { fromBlock: 'latest', toBlock: 'latest' + 1 }).watch(function(error, event) {...});