diff --git a/src/js/app.js b/src/js/app.js index 7fd83d7..64614b3 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,12 +1,11 @@ -var phaseEnum; // for changing phases of voting +var phaseEnum; // For changing phases of voting App = { web3Provider: null, contracts: {}, - account:0x0, + account: '0x0', init: async function() { - // Load pets. - + // Initialize web3 and contract return await App.initWeb3(); }, @@ -14,10 +13,10 @@ App = { if (window.ethereum) { try { const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); - setAccounts(accounts); + App.account = accounts[0]; } catch (error) { if (error.code === 4001) { - // User rejected request + console.error("User rejected the request."); } } } @@ -26,242 +25,201 @@ App = { }, initContract: function() { - - $.getJSON("Contest.json",function(contest){ - App.contracts.Contest=TruffleContract(contest); - + $.getJSON("Contest.json", function(contest) { + App.contracts.Contest = TruffleContract(contest); App.contracts.Contest.setProvider(web3.currentProvider); - return App.render(); }); }, - render: function(){ - + render: function() { var contestInstance; - var loader=$("#loader"); - var content=$("#content"); + var loader = $("#loader"); + var content = $("#content"); loader.show(); content.hide(); $("#after").hide(); - web3.eth.getCoinbase(function(err,account){ - if(err===null){ - App.account=account; - $("#accountAddress").html("Your account: "+account); + web3.eth.getCoinbase(function(err, account) { + if (err === null) { + App.account = account; + $("#accountAddress").html("Your account: " + account); } }); - - - // ------------- fetching candidates to front end from blockchain code------------- - App.contracts.Contest.deployed().then(function(instance){ - contestInstance=instance; + // Fetching candidates to front end from blockchain + App.contracts.Contest.deployed().then(function(instance) { + contestInstance = instance; return contestInstance.contestantsCount(); - }).then(function(contestantsCount){ - // var contestantsResults=$("#contestantsResults"); - // contestantsResults.empty(); - - // var contestantSelect=$("#contestantSelect"); - // contestantSelect.empty(); - - // for(var i=1; i<=contestantsCount; i++){ - // contestInstance.contestants(i).then(function(contestant){ - // var id=contestant[0]; - // var name=contestant[1]; - // var voteCount=contestant[2]; - // var fetchedParty=contestant[3]; - // var fetchedAge = contestant[4]; - // var fetchedQualification = contestant[5] - - // var contestantTemplate="