Skip to content
Snippets Groups Projects
Commit cc42398d authored by Miguel Braidot's avatar Miguel Braidot
Browse files

El formulario de votación envía la transacción al SC

parent b47c83b4
No related branches found
No related tags found
No related merge requests found
......@@ -496,6 +496,39 @@ async function ver_votacion2(addr, code) {
}
}
async function votar(addr, proposal){
await access_accounts();
return new Promise (function (resolve, reject) {
window.web3.eth.getCode(addr, function (err, code) {
if (err) {
reject('No es posible obtener el bytecode del contrato: ' + err + '');
}
if (code == '0x') {
reject('No existe un contrato con esa dirección');
}
var contract = setup_existing_instance(abiBallot, addr);
if (!contract){
reject("No existe un contrato en esa dirección");
}
contract.vote.sendTransaction(proposal, { gas: 2111000 }, function (error, result) {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
});
}
///////////////////////////////////////////////////////////
// UTILS for ballot form creation
///////////////////////////////////////////////////////////
......@@ -517,7 +550,7 @@ async function getBallotVoteStarts(err, rcpt){
}else{
$('#comienza_votacion').text(getDateFromTimestamp(rcpt));
var today = new Date();
if(rcpt > today.getTime()){
if(rcpt > today.getTime()/1000){
$("#form_votacion :input").prop("disabled", true);
alertar("La votación no ha comenzado aún.");
}
......@@ -529,7 +562,7 @@ async function getBallotVoteBefore(err, rcpt){
}else{
$('#termina_votacion').text(getDateFromTimestamp(rcpt));
var today = new Date();
if(rcpt < today.getTime()){
if(rcpt < today.getTime()/1000){
$("#form_votacion :input").prop("disabled", true);
alertar("La votación ha finalizado.");
}
......@@ -551,7 +584,7 @@ async function getProposalList(err, rcpt){
}else{
var num = $('#proposals div').length;
var element = '<div class="radio"> \
<input type="radio" name="votacion" id="vote_'+num+'" required="required" aria-required="true"> \
<input type="radio" name="votacion" id="vote_'+num+'" value="'+num+'" required="required" aria-required="true"> \
<label for="vote_'+num+'">'+hex2ascii(rcpt)+'</label> \
</div>';
$('#proposals').append(element);
......
......@@ -180,6 +180,36 @@
ver_votacion(input_address);
}
async function sendVotacion(){
$("#voterow :input").attr("disabled", true);
$("#voterow .btn").hide();
try{
if(typeof input_address != "undefined" && input_address != ""){
var proposal = $("input[name='votacion']:checked").val();
let resultado = await votar(input_address, proposal);
console.log("resultado: ");
console.log(resultado.toString(10));
alertarSuccess('¡Votaste con éxito!');
$("form").hide();
$(".resultados").show();
$(".votar legend").text('Tu voto');
}else{
alertar('Ocurrió un error');
$("#voterow .btn").show();
}
}catch (error){
alertar(error);
$("#voterow .btn").show();
return false;
}
}
$("form").validate({
focusInvalid: false,
errorContainer: container,
......@@ -203,18 +233,28 @@
}
},
submitHandler: function (form) {
// do other things for a valid form
//form.submit();
var body = $("html, body");
body.stop().animate({
scrollTop: 0
}, 200)
alertarSuccess('¡Votaste con éxito!');
$("#voterow :input").attr("disabled", true);
sendVotacion();
/*$("#voterow :input").attr("disabled", true);
$("#voterow .btn").hide();
$("form").hide();
$(".resultados").show();
$(".votar legend").text('Tu voto');
var result = sendVotacion();
console.log(result);
if (result === true){
alertarSuccess('¡Votaste con éxito!');
$("form").hide();
$(".resultados").show();
$(".votar legend").text('Tu voto');
}else{
alertar('Ocurrió un error');
$("#voterow :input").attr("disabled", false);
$("#voterow .btn").show();
}*/
},
messages: {
votacion: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment