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');
});
@ -153,91 +164,139 @@
console.log('feeTxid seems good: ' + txidfield.val());
console.log("wait while we check the api!");
// first check if transactionid is already in api
$.getJSON(apiserversocket + 'insight-api-dash/tx/' + txidfield.val(), function(data) {
txidfield.attr("disabled", true);
$('.walletCommands#walletCommandsProgress').removeClass('hidden');
var txid = data.tx;
var confirmations = data.confirmations;
var conftxt;
var conftxt2;
console.log('Transaction has ' + confirmations + ' confirmation(s)');
$( "#progressbar" ).progressbar({
value: 100/6*confirmations
});
if (confirmations != 'undefined' && $.isNumeric(confirmations)) {
var socket = io(apiserversocket);
if (confirmations == 0) {
// we have to count the blocks and wait for 6 confirmations
console.log("we have to count the blocks and wait for 6 confirmations");
eventToListenTo = 'block';
room = 'inv';
socket.on('connect', function() {
// Join the room.
socket.emit('subscribe', room);
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
});
socket.on(eventToListenTo, function(data) {
console.log("New block received: " + data + " time: " + data.time);
var 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) {
var txs = data.txs;
var found;
var numOfTxs = txs.length;
for (var i = 0; i < numOfTxs; i++) {
console.log('txs' + i + ': ' + txs[i].txid);
if (txs[i].txid == txidfield.val()) {
console.log('found tx!');
found = true;
// first check if transactionid is already in api
$.getJSON(apiserversocket + 'insight-api-dash/tx/' + txidfield.val(), function(data) {
txidfield.attr("disabled", true);
$('.walletCommands#walletCommandsProgress').removeClass('hidden');
var txid = data.tx;
var confirmations = data.confirmations;
var conftxt;
var conftxt2;
var progbarval;
console.log('Transaction has ' + confirmations + ' confirmation(s)');
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) {
// we have to count the blocks and wait for 6 confirmations
console.log("we have to count the blocks and wait for 6 confirmations");
eventToListenTo = 'block';
room = 'inv';
socket.on('connect', function() {
// Join the room.
socket.emit('subscribe', room);
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
});
socket.on(eventToListenTo, function(data) {
console.log("New block received: " + data + " time: " + data.time);
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) {
var txs = data.txs;
var found;
var numOfTxs = txs.length;
for (var i = 0; i < numOfTxs; i++) {
console.log('txs' + i + ': ' + txs[i].txid);
if (txs[i].txid == txidfield.val()) {
console.log('found tx!');
found = true;
}
}
}
if (found) {
console.log('all good. Count up confirmations.');
confirmations = confirmations + 1;
$( "#progressbar" ).progressbar({
value: 100/6*confirmations
});
if (confirmations == 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
}
else if (confirmations == 5) {
conftxt = 'confirmations';
conftxt2 = 'confirmation';
if (found) {
console.log('all good. Count up confirmations.');
confirmations = confirmations + 1;
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';
}
else if (confirmations == 5) {
conftxt = 'confirmations';
conftxt2 = 'confirmation';
}
else {
conftxt = 'confirmations';
conftxt2 = 'confirmations';
}
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
console.log('we have ' + confirmations + ' confirmations...');
}
else {
conftxt = 'confirmations';
conftxt2 = 'confirmations';
console.log('txid not in new block');
}
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
console.log('we have ' + confirmations + ' confirmations...');
}).fail(function(jqXHR) {
if (jqXHR.status == 400) {
// there seems to be a problem with your feeTxid because txid is not found in api
console.log('block hash not found in api!');
} else {
console.log('There seems to be a problem with the api connection. Maybe endpoint resyncing?');
}
});
}
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;
progbarval = 100/6*confirmations;
if (confirmations == 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
}
else if (confirmations == 5) {
conftxt = 'confirmations';
conftxt2 = 'confirmation';
}
else {
console.log('txid not in new block');
conftxt = 'confirmations';
conftxt2 = 'confirmations';
}
}).fail(function(jqXHR) {
if (jqXHR.status == 400) {
// there seems to be a problem with your feeTxid because txid is not found in api
console.log('block hash not found in api!');
} else {
console.log('There seems to be a problem with the api connection. Maybe endpoint resyncing?');
}
});
}
else {
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
console.log('we have ' + confirmations + ' confirmations...');
}
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) {
// we have to count the blocks and wait for outstanding confirmations
console.log("we have to count the blocks and wait for outstanding confirmations");
eventToListenTo = 'block';
room = 'inv';
socket.on('connect', function() {
// Join the room.
socket.emit('subscribe', room);
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
});
socket.on(eventToListenTo, function(data) {
console.log("New block received: " + data + " time: " + data.time);
// 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
});
if (confirmations == 1) {
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';
}
else if (confirmations == 5) {
else if (confirmations = 5) {
conftxt = 'confirmations';
conftxt2 = 'confirmation';
}
@ -247,106 +306,73 @@
}
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
console.log('we have ' + confirmations + ' confirmations...');
}
if (confirmations >= 6) {
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
}
});
}
else if (confirmations > 0 && confirmations <= 5) {
// we have to count the blocks and wait for outstanding confirmations
console.log("we have to count the blocks and wait for outstanding confirmations");
eventToListenTo = 'block';
room = 'inv';
socket.on('connect', function() {
// Join the room.
socket.emit('subscribe', room);
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
});
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
if (confirmations >= 6) {
progbarval = 100;
$("#progressbar").progressbar({value: progbarval})
.children('.ui-progressbar-value')
.html(progbarval + '%')
.css("display", "block");
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
}
});
if (confirmations = 1) {
conftxt = 'confirmation';
conftxt2 = 'confirmations';
}
else if (confirmations = 5) {
conftxt = 'confirmations';
conftxt2 = 'confirmation';
}
else {
conftxt = 'confirmations';
conftxt2 = 'confirmations';
}
$("#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
});
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
}
});
}
else {
// already reached 6 or more confirmations, so we can proceed
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');
}
}
else {
// already reached 6 or more confirmations, so we can proceed
$( "#progressbar" ).progressbar({
value: 100
});
$("#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');
console.log('Something went terribly wrong. Faulty api data?');
txidfield.attr("disabled", false);
}
}
else {
console.log('Something went terribly wrong. Faulty api data?');
txidfield.attr("disabled", false);
}
}).fail(function(jqXHR) {
if (jqXHR.status == 400) {
// there seems to be a problem with your feeTxid because txid is not found in api
console.log('problem with feeTxid! Ask for new input!');
alert("Check again and please enter your correct TxID!");
txidfield.attr("disabled", false);
} else {
txidfield.attr("disabled", false);
console.log('There seems to be a problem with the api connection');
}
});
}).fail(function(jqXHR) {
if (jqXHR.status == 400) {
// there seems to be a problem with your feeTxid because txid is not found in api
console.log('problem with feeTxid! Ask for new input!');
alert("Check again and please enter your correct TxID!");
txidfield.attr("disabled", false);
} else {
txidfield.attr("disabled", false);
console.log('There seems to be a problem with the api connection');
}
});
}
else {
$('#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 {
alert("there is something wrong with your transaction ID. It must be alphanumeric!")
$('#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();
});
} else {
$('textarea#submitProposal').val('');
$('.walletCommands#walletCommandsSubmit').addClass('hidden');
}
});
$('#btnEdit').click(function() {
proposal.createProposal();
});
$('#btnNew').click(function() {
proposal.resetProposal();
});
}
$('#btnNew').click(function() {
proposal.resetProposal();
});
}
});
});
});
var ProposalGenerator = function(gov) {
this._mode = 'proposal';
@ -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>