added error messages

This commit is contained in:
Cofresi 2016-11-23 20:37:35 -04:00
parent 532aecb75d
commit 500d8da400

View file

@ -24,6 +24,7 @@
$(document).ready(function() {
$("#progresstxt").text(progresstxt);
$.getJSON(apiserversocket + "insight-api-dash/status?q=getinfo", function( data ) {
var timefield = $("#time");
timefield.val(Math.floor((new Date).getTime() / 1000));
@ -118,7 +119,17 @@
copyToClipboard($(this).attr('id'));
});
$('#feeTxid').focus(function() {
if ($(this).hasClass('validationError')) {
$(this).val('');
}
$(this).removeClass('validationError');
});
$('.createProposal input').focus(function() {
if ($(this).hasClass('validationError')) {
$(this).val('');
}
$(this).removeClass('validationError');
});
@ -161,11 +172,13 @@
var confirmations = data.confirmations;
var conftxt;
var conftxt2;
var progbarval;
console.log('Transaction has ' + confirmations + ' confirmation(s)');
$( "#progressbar" ).progressbar({
value: 100/6*confirmations
});
progbarval = 100/6*confirmations;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval.toPrecision(3) + '%')
.css("display", "block");
if (confirmations != 'undefined' && $.isNumeric(confirmations)) {
var socket = io(apiserversocket);
if (confirmations == 0) {
@ -180,7 +193,7 @@
});
socket.on(eventToListenTo, function(data) {
console.log("New block received: " + data + " time: " + data.time);
var blockhash = data;
blockhash = data;
// let's check if transaction is really in this block or not
if (confirmations == 0) {
$.getJSON(apiserversocket + 'insight-api-dash/txs/?block=' + blockhash, function(data) {
@ -197,9 +210,11 @@
if (found) {
console.log('all good. Count up confirmations.');
confirmations = confirmations + 1;
$( "#progressbar" ).progressbar({
value: 100/6*confirmations
});
progbarval = 100/6*confirmations;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval.toPrecision(3) + '%')
.css("display", "block");
if (confirmations == 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
@ -230,9 +245,7 @@
else {
// for the time being just count up the confirmations without confirming everytime if the transaction is still inside the previous blocks
confirmations = confirmations + 1;
$( "#progressbar" ).progressbar({
value: 100/6*confirmations
});
progbarval = 100/6*confirmations;
if (confirmations == 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
@ -250,9 +263,14 @@
}
if (confirmations >= 6) {
progbarval = 100;
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
}
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval.toPrecision(3) + '%')
.css("display", "block");
});
}
else if (confirmations > 0 && confirmations <= 5) {
@ -267,12 +285,13 @@
});
socket.on(eventToListenTo, function(data) {
console.log("New block received: " + data + " time: " + data.time);
var blockhash = data;
// for the time being just count up the confirmations without confirming everytime if the transaction is still inside the previous blocks
confirmations = confirmations + 1;
$("#progressbar").progressbar({
value: 100/6*confirmations
});
progbarval = 100/6*confirmations;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval.toPrecision(3) + '%')
.css("display", "block");
if (confirmations = 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
@ -288,18 +307,22 @@
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
console.log('we have ' + confirmations + ' confirmations...');
if (confirmations >= 6) {
$("#progressbar").progressbar({
value: 100
});
progbarval = 100;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval + '%')
.css("display", "block");
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
}
});
}
else {
// already reached 6 or more confirmations, so we can proceed
$( "#progressbar" ).progressbar({
value: 100
});
progbarval = 100;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval + '%')
.css("display", "block");
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
console.log("already reached 6 or more confirmations, so we can proceed");
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
@ -322,23 +345,26 @@
});
}
else {
alert("there is something wrong with your transaction ID. It must be alphanumeric!")
$('#feeTxid').addClass('validationError');
$('#feeTxid').val('Your transacton ID is invalid. It must be alphanumeric. Please just copy & paste from console.');
console.log("there is something wrong with your transaction ID. It must be alphanumeric!")
}
}
} else {
else {
$('#feeTxid').addClass('validationError');
$('#feeTxid').val('Your transacton ID is invalid. Please just copy & paste from console.');
console.log("there is something wrong with your transaction ID. It must be exactly 64 characters!")
}
}
else {
$('textarea#submitProposal').val('');
$('.walletCommands#walletCommandsSubmit').addClass('hidden');
}
});
$('#btnEdit').click(function() {
proposal.createProposal();
});
$('#btnNew').click(function() {
@ -379,6 +405,25 @@
catch (e) {
switch(e.message) {
case 'Invalid Name':
console.log("error: invalid name");
$('#name').addClass('validationError');
$('#name').val("Invalid name. Please enter a name without spaces and weird characters. E.g. can use a '-' or '_' instead of a space.");
break;
case 'Invalid URL':
console.log("Error: invalid url");
$('#url').addClass('validationError');
$('#url').val("There is a formatting error in your URL. Did you forget the leading 'http://'?");
break;
case 'Invalid Payment Amount':
console.log("Error: invalid payment amount");
$('#payment_amount').addClass('validationError');
$('#payment_amount').val("Invalid payment amount. Please enter a number from 1 - 7500");
break;
case 'Invalid Timespan':
console.log("Error: invalid timespan");
$('#start_epoch, #end_epoch').addClass('validationError');
@ -397,21 +442,7 @@
case 'Invalid Address':
console.log("Error: invalid address");
$('#payment_address').addClass('validationError');
break;
case 'Invalid Payment Amount':
console.log("Error: invalid payment amount");
$('#payment_amount').addClass('validationError');
break;
case 'Invalid URL':
console.log("Error: invalid url");
$('#url').addClass('validationError');
break;
case 'Invalid Name':
console.log("error: invalid name");
$('#name').addClass('validationError');
$('#payment_address').val("Invalid Dash Address. Please just copy & paste from wallet.");
break;
default:
@ -530,7 +561,7 @@
}
}
return true;
};
}
</script>