mirror of
https://github.com/seigler/govobject-proposal
synced 2025-07-27 06:46:10 +00:00
added error messages
This commit is contained in:
parent
532aecb75d
commit
500d8da400
1 changed files with 208 additions and 177 deletions
385
index.html
385
index.html
|
@ -24,6 +24,7 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$("#progresstxt").text(progresstxt);
|
$("#progresstxt").text(progresstxt);
|
||||||
|
|
||||||
$.getJSON(apiserversocket + "insight-api-dash/status?q=getinfo", function( data ) {
|
$.getJSON(apiserversocket + "insight-api-dash/status?q=getinfo", function( data ) {
|
||||||
var timefield = $("#time");
|
var timefield = $("#time");
|
||||||
timefield.val(Math.floor((new Date).getTime() / 1000));
|
timefield.val(Math.floor((new Date).getTime() / 1000));
|
||||||
|
@ -118,7 +119,17 @@
|
||||||
copyToClipboard($(this).attr('id'));
|
copyToClipboard($(this).attr('id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#feeTxid').focus(function() {
|
||||||
|
if ($(this).hasClass('validationError')) {
|
||||||
|
$(this).val('');
|
||||||
|
}
|
||||||
|
$(this).removeClass('validationError');
|
||||||
|
});
|
||||||
|
|
||||||
$('.createProposal input').focus(function() {
|
$('.createProposal input').focus(function() {
|
||||||
|
if ($(this).hasClass('validationError')) {
|
||||||
|
$(this).val('');
|
||||||
|
}
|
||||||
$(this).removeClass('validationError');
|
$(this).removeClass('validationError');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -153,91 +164,139 @@
|
||||||
console.log('feeTxid seems good: ' + txidfield.val());
|
console.log('feeTxid seems good: ' + txidfield.val());
|
||||||
console.log("wait while we check the api!");
|
console.log("wait while we check the api!");
|
||||||
|
|
||||||
// first check if transactionid is already in api
|
// first check if transactionid is already in api
|
||||||
$.getJSON(apiserversocket + 'insight-api-dash/tx/' + txidfield.val(), function(data) {
|
$.getJSON(apiserversocket + 'insight-api-dash/tx/' + txidfield.val(), function(data) {
|
||||||
txidfield.attr("disabled", true);
|
txidfield.attr("disabled", true);
|
||||||
$('.walletCommands#walletCommandsProgress').removeClass('hidden');
|
$('.walletCommands#walletCommandsProgress').removeClass('hidden');
|
||||||
var txid = data.tx;
|
var txid = data.tx;
|
||||||
var confirmations = data.confirmations;
|
var confirmations = data.confirmations;
|
||||||
var conftxt;
|
var conftxt;
|
||||||
var conftxt2;
|
var conftxt2;
|
||||||
console.log('Transaction has ' + confirmations + ' confirmation(s)');
|
var progbarval;
|
||||||
$( "#progressbar" ).progressbar({
|
console.log('Transaction has ' + confirmations + ' confirmation(s)');
|
||||||
value: 100/6*confirmations
|
progbarval = 100/6*confirmations;
|
||||||
});
|
$("#progressbar").progressbar({value: progbarval})
|
||||||
|
.children('.ui-progressbar-value')
|
||||||
if (confirmations != 'undefined' && $.isNumeric(confirmations)) {
|
.html(progbarval.toPrecision(3) + '%')
|
||||||
var socket = io(apiserversocket);
|
.css("display", "block");
|
||||||
if (confirmations == 0) {
|
if (confirmations != 'undefined' && $.isNumeric(confirmations)) {
|
||||||
// we have to count the blocks and wait for 6 confirmations
|
var socket = io(apiserversocket);
|
||||||
console.log("we have to count the blocks and wait for 6 confirmations");
|
if (confirmations == 0) {
|
||||||
eventToListenTo = 'block';
|
// we have to count the blocks and wait for 6 confirmations
|
||||||
room = 'inv';
|
console.log("we have to count the blocks and wait for 6 confirmations");
|
||||||
socket.on('connect', function() {
|
eventToListenTo = 'block';
|
||||||
// Join the room.
|
room = 'inv';
|
||||||
socket.emit('subscribe', room);
|
socket.on('connect', function() {
|
||||||
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
|
// Join the room.
|
||||||
});
|
socket.emit('subscribe', room);
|
||||||
socket.on(eventToListenTo, function(data) {
|
console.log("listening for '" + eventToListenTo + "' in '" + room + "'");
|
||||||
console.log("New block received: " + data + " time: " + data.time);
|
});
|
||||||
var blockhash = data;
|
socket.on(eventToListenTo, function(data) {
|
||||||
// let's check if transaction is really in this block or not
|
console.log("New block received: " + data + " time: " + data.time);
|
||||||
if (confirmations == 0) {
|
blockhash = data;
|
||||||
$.getJSON(apiserversocket + 'insight-api-dash/txs/?block=' + blockhash, function(data) {
|
// let's check if transaction is really in this block or not
|
||||||
var txs = data.txs;
|
if (confirmations == 0) {
|
||||||
var found;
|
$.getJSON(apiserversocket + 'insight-api-dash/txs/?block=' + blockhash, function(data) {
|
||||||
var numOfTxs = txs.length;
|
var txs = data.txs;
|
||||||
for (var i = 0; i < numOfTxs; i++) {
|
var found;
|
||||||
console.log('txs' + i + ': ' + txs[i].txid);
|
var numOfTxs = txs.length;
|
||||||
if (txs[i].txid == txidfield.val()) {
|
for (var i = 0; i < numOfTxs; i++) {
|
||||||
console.log('found tx!');
|
console.log('txs' + i + ': ' + txs[i].txid);
|
||||||
found = true;
|
if (txs[i].txid == txidfield.val()) {
|
||||||
|
console.log('found tx!');
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (found) {
|
||||||
if (found) {
|
console.log('all good. Count up confirmations.');
|
||||||
console.log('all good. Count up confirmations.');
|
confirmations = confirmations + 1;
|
||||||
confirmations = confirmations + 1;
|
progbarval = 100/6*confirmations;
|
||||||
$( "#progressbar" ).progressbar({
|
$("#progressbar").progressbar({value: progbarval})
|
||||||
value: 100/6*confirmations
|
.children('.ui-progressbar-value')
|
||||||
});
|
.html(progbarval.toPrecision(3) + '%')
|
||||||
if (confirmations == 1) {
|
.css("display", "block");
|
||||||
conftxt = 'confirmation';
|
if (confirmations == 1) {
|
||||||
conftxt2 = 'confirmations';
|
conftxt = 'confirmation';
|
||||||
}
|
conftxt2 = 'confirmations';
|
||||||
else if (confirmations == 5) {
|
}
|
||||||
conftxt = 'confirmations';
|
else if (confirmations == 5) {
|
||||||
conftxt2 = 'confirmation';
|
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 {
|
else {
|
||||||
conftxt = 'confirmations';
|
console.log('txid not in new block');
|
||||||
conftxt2 = 'confirmations';
|
|
||||||
}
|
}
|
||||||
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
}).fail(function(jqXHR) {
|
||||||
console.log('we have ' + confirmations + ' confirmations...');
|
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 {
|
else {
|
||||||
console.log('txid not in new block');
|
conftxt = 'confirmations';
|
||||||
|
conftxt2 = 'confirmations';
|
||||||
}
|
}
|
||||||
}).fail(function(jqXHR) {
|
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
||||||
if (jqXHR.status == 400) {
|
console.log('we have ' + confirmations + ' confirmations...');
|
||||||
// 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 {
|
if (confirmations >= 6) {
|
||||||
console.log('There seems to be a problem with the api connection. Maybe endpoint resyncing?');
|
progbarval = 100;
|
||||||
}
|
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
|
||||||
});
|
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
||||||
}
|
}
|
||||||
else {
|
$("#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
|
// for the time being just count up the confirmations without confirming everytime if the transaction is still inside the previous blocks
|
||||||
confirmations = confirmations + 1;
|
confirmations = confirmations + 1;
|
||||||
$( "#progressbar" ).progressbar({
|
progbarval = 100/6*confirmations;
|
||||||
value: 100/6*confirmations
|
$("#progressbar").progressbar({value: progbarval})
|
||||||
});
|
.children('.ui-progressbar-value')
|
||||||
if (confirmations == 1) {
|
.html(progbarval.toPrecision(3) + '%')
|
||||||
|
.css("display", "block");
|
||||||
|
if (confirmations = 1) {
|
||||||
conftxt = 'confirmation';
|
conftxt = 'confirmation';
|
||||||
conftxt2 = 'confirmations';
|
conftxt2 = 'confirmations';
|
||||||
}
|
}
|
||||||
else if (confirmations == 5) {
|
else if (confirmations = 5) {
|
||||||
conftxt = 'confirmations';
|
conftxt = 'confirmations';
|
||||||
conftxt2 = 'confirmation';
|
conftxt2 = 'confirmation';
|
||||||
}
|
}
|
||||||
|
@ -247,106 +306,73 @@
|
||||||
}
|
}
|
||||||
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
$("#progresstxt").text("Your transaction has " + confirmations + " " + conftxt + ". Waiting for " + (6 - confirmations) + " more " + conftxt2 + "...");
|
||||||
console.log('we have ' + confirmations + ' confirmations...');
|
console.log('we have ' + confirmations + ' confirmations...');
|
||||||
}
|
if (confirmations >= 6) {
|
||||||
|
progbarval = 100;
|
||||||
if (confirmations >= 6) {
|
$("#progressbar").progressbar({value: progbarval})
|
||||||
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
|
.children('.ui-progressbar-value')
|
||||||
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
.html(progbarval + '%')
|
||||||
}
|
.css("display", "block");
|
||||||
});
|
$('.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 = 1) {
|
}
|
||||||
conftxt = 'confirmation';
|
else {
|
||||||
conftxt2 = 'confirmations';
|
// already reached 6 or more confirmations, so we can proceed
|
||||||
}
|
progbarval = 100;
|
||||||
else if (confirmations = 5) {
|
$("#progressbar").progressbar({value: progbarval})
|
||||||
conftxt = 'confirmations';
|
.children('.ui-progressbar-value')
|
||||||
conftxt2 = 'confirmation';
|
.html(progbarval + '%')
|
||||||
}
|
.css("display", "block");
|
||||||
else {
|
$("#progresstxt").text("Your transaction has " + confirmations + " confirmations. You can now submit the proposal.");
|
||||||
conftxt = 'confirmations';
|
console.log("already reached 6 or more confirmations, so we can proceed");
|
||||||
conftxt2 = 'confirmations';
|
$('.walletCommands#walletCommandsSubmit').removeClass('hidden');
|
||||||
}
|
}
|
||||||
$("#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 {
|
else {
|
||||||
// already reached 6 or more confirmations, so we can proceed
|
console.log('Something went terribly wrong. Faulty api data?');
|
||||||
$( "#progressbar" ).progressbar({
|
txidfield.attr("disabled", false);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
}
|
}).fail(function(jqXHR) {
|
||||||
else {
|
if (jqXHR.status == 400) {
|
||||||
console.log('Something went terribly wrong. Faulty api data?');
|
// there seems to be a problem with your feeTxid because txid is not found in api
|
||||||
txidfield.attr("disabled", false);
|
console.log('problem with feeTxid! Ask for new input!');
|
||||||
}
|
alert("Check again and please enter your correct TxID!");
|
||||||
}).fail(function(jqXHR) {
|
txidfield.attr("disabled", false);
|
||||||
if (jqXHR.status == 400) {
|
} else {
|
||||||
// there seems to be a problem with your feeTxid because txid is not found in api
|
txidfield.attr("disabled", false);
|
||||||
console.log('problem with feeTxid! Ask for new input!');
|
console.log('There seems to be a problem with the api connection');
|
||||||
alert("Check again and please enter your correct TxID!");
|
}
|
||||||
txidfield.attr("disabled", false);
|
});
|
||||||
} else {
|
}
|
||||||
txidfield.attr("disabled", false);
|
else {
|
||||||
console.log('There seems to be a problem with the api connection');
|
$('#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 {
|
||||||
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 {
|
$('#btnNew').click(function() {
|
||||||
$('textarea#submitProposal').val('');
|
proposal.resetProposal();
|
||||||
$('.walletCommands#walletCommandsSubmit').addClass('hidden');
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#btnEdit').click(function() {
|
|
||||||
|
|
||||||
proposal.createProposal();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#btnNew').click(function() {
|
|
||||||
proposal.resetProposal();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
var ProposalGenerator = function(gov) {
|
var ProposalGenerator = function(gov) {
|
||||||
this._mode = 'proposal';
|
this._mode = 'proposal';
|
||||||
|
@ -379,6 +405,25 @@
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|
||||||
switch(e.message) {
|
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':
|
case 'Invalid Timespan':
|
||||||
console.log("Error: invalid timespan");
|
console.log("Error: invalid timespan");
|
||||||
$('#start_epoch, #end_epoch').addClass('validationError');
|
$('#start_epoch, #end_epoch').addClass('validationError');
|
||||||
|
@ -397,21 +442,7 @@
|
||||||
case 'Invalid Address':
|
case 'Invalid Address':
|
||||||
console.log("Error: invalid address");
|
console.log("Error: invalid address");
|
||||||
$('#payment_address').addClass('validationError');
|
$('#payment_address').addClass('validationError');
|
||||||
break;
|
$('#payment_address').val("Invalid Dash Address. Please just copy & paste from wallet.");
|
||||||
|
|
||||||
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');
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -530,7 +561,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue