replaced end date dropdown with a time span in month dropdown

This commit is contained in:
Cofresi 2016-11-03 22:19:58 -04:00
parent 16313c9b2a
commit 718bc0ac3a

View file

@ -16,6 +16,7 @@
var Bitcore = require('bitcore-lib-dash'); var Bitcore = require('bitcore-lib-dash');
//number of days to have as buffer for proposal start date before jumping to next month //number of days to have as buffer for proposal start date before jumping to next month
var bufferdays = 3; var bufferdays = 3;
var blockheight;
eventToListenTo = 'block'; eventToListenTo = 'block';
room = 'inv'; room = 'inv';
@ -39,21 +40,13 @@
$.getJSON( "http://195.141.143.55:3001/insight-api-dash/status?q=getinfo", function( data ) { $.getJSON( "http://195.141.143.55:3001/insight-api-dash/status?q=getinfo", function( data ) {
var blockheight = data.info.blocks; blockheight = data.info.blocks;
console.log('network: ' + gov.network); console.log('network: ' + gov.network);
var budgetPaymentCycleBlocks; var budgetPaymentCycleBlocks = getBudgetPaymentCycleBlocks();
// Amount of blocks in a months period of time (using 2.6 minutes per) = (60*24*30)/2.6
if (gov.network == 'livenet') {
budgetPaymentCycleBlocks = 16616;
}
else {
//for testing purposes
budgetPaymentCycleBlocks = 50; //ten times per day
}
var nextsuperblock = Math.round(blockheight/budgetPaymentCycleBlocks) * budgetPaymentCycleBlocks; var nextsuperblock = Math.round(blockheight/budgetPaymentCycleBlocks) * budgetPaymentCycleBlocks;
var selectblock = nextsuperblock; var selectblock = nextsuperblock;
console.log('budgetPaymentCycleBlocks: ' + budgetPaymentCycleBlocks);
console.log('blockheight: ' + blockheight); console.log('blockheight: ' + blockheight);
console.log('next superblock ' + nextsuperblock); console.log('next superblock ' + nextsuperblock);
@ -87,7 +80,7 @@
else { else {
timeleft = daysleft + ' day' timeleft = daysleft + ' day'
} }
optionsStart.push("<option value='" + d + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>"); optionsStart.push("<option value='" + nextsuperblock + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>");
} }
else { else {
if (i == 1) { if (i == 1) {
@ -96,23 +89,30 @@
else { else {
timeleft = i + ' months'; timeleft = i + ' months';
} }
optionsStart.push("<option value='" + d + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>"); optionsStart.push("<option value='" + nextsuperblock + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>");
optionsEnd.push("<option value='" + d + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>");
if (i == numOfSuperBlockDates - 1) { if (i == numOfSuperBlockDates - 1) {
timeleft = numOfSuperBlockDates + ' month'; timeleft = numOfSuperBlockDates + ' month';
nextsuperblock += budgetPaymentCycleBlocks; nextsuperblock += budgetPaymentCycleBlocks;
optionsEnd.push("<option value='" + d + "'>block " + nextsuperblock + " in " + timeleft + " (" + d + ")</option>");
} }
} }
nextsuperblock += budgetPaymentCycleBlocks; nextsuperblock += budgetPaymentCycleBlocks;
} }
start_epoch.append(optionsStart.join("")); start_epoch.append(optionsStart.join(""));
end_epoch.append(optionsEnd.join(""));
//console.log('blocks left to next superblock: ' + (selectblock - blockheight)); //populate budget cycle dropdown
//console.log('selectblock: ' + selectblock); for (i = 1; i < 100; i ++)
//console.log('budgetPaymentCycleBlocks: ' + budgetPaymentCycleBlocks); {
if (i == 1) {
optionsEnd.push("<option value='" + i + "'>one-time payment</option>");
}
else {
optionsEnd.push("<option value='" + i + "'>payment once a month for " + i + " months</option>");
}
}
end_epoch.append(optionsEnd.join(""));
//if next superblock is less than 3 days (60*24*3/2.6) away, select next month's superblock by default so proposal has more time to be voted upon //if next superblock is less than 3 days (60*24*3/2.6) away, select next month's superblock by default so proposal has more time to be voted upon
if (selectblock - blockheight < (60*24*bufferdays/2.6)) { if (selectblock - blockheight < (60*24*bufferdays/2.6)) {
@ -123,19 +123,9 @@
start_epoch.val(selectstartdate); start_epoch.val(selectstartdate);
nextsuperblocktimestamp = nextsuperblocktimestamp + budgetPaymentCycleBlocks * (2.6 * 60 * 1000); nextsuperblocktimestamp = nextsuperblocktimestamp + budgetPaymentCycleBlocks * (2.6 * 60 * 1000);
var selectenddate = $.datepicker.formatDate('yy-mm-dd', new Date(nextsuperblocktimestamp)); var selectenddate = $.datepicker.formatDate('yy-mm-dd', new Date(nextsuperblocktimestamp));
end_epoch.val(selectenddate);
} }
}); });
//change end date to one month after start date by default
$('#start_epoch').change(function() {
var start_time = $('#start_epoch').val();
var startindex = $('#start_epoch').find(":selected").index();
var endindex = startindex + 1;
$('#end_epoch :nth-child(' + endindex + ')').prop('selected', true);
});
$('#prepareProposal').click(function() { $('#prepareProposal').click(function() {
copyToClipboard($(this).attr('id')); copyToClipboard($(this).attr('id'));
}); });
@ -195,8 +185,12 @@
this.gov.payment_amount = parseFloat($('#payment_amount').val()); this.gov.payment_amount = parseFloat($('#payment_amount').val());
// format dates for gobject serialization // format dates for gobject serialization
this.gov.start_epoch = (new Date($('#start_epoch').val()) / 1000) || null; var startdate = formattedDateForSuperblockHeight($('#start_epoch').val());
this.gov.end_epoch = (new Date($('#end_epoch').val()) / 1000) || null; console.log('startdate: ' + startdate);
this.gov.start_epoch = (new Date(startdate)) || null;
var enddate = formattedDateForSuperblockHeight($('#start_epoch').val(),$('#end_epoch').val());
console.log('enddate: ' + enddate);
this.gov.end_epoch = (new Date(enddate)) || null;
// hidden elements // hidden elements
this.gov.type = parseInt($('#type').val()); this.gov.type = parseInt($('#type').val());
@ -320,6 +314,32 @@
document.execCommand('copy'); document.execCommand('copy');
}; };
getBudgetPaymentCycleBlocks = function() {
// Amount of blocks in a months period of time (using 2.6 minutes per) = (60*24*30)/2.6
if (gov.network == 'livenet') {
return 16616;
}
else {
//for testing purposes
return 50; //ten times per day
}
};
formattedDateForSuperblockHeight = function(startheight, months) {
months = months || 0;
var endheight;
var blockdiff;
if (months !== 0) {
endheight = (parseInt(startheight) + (getBudgetPaymentCycleBlocks()*months));
blockdiff = endheight - blockheight;
}
else {
blockdiff = startheight - blockheight;
}
var superblocktimestamp = $.now() + blockdiff * (2.6 * 60 * 1000);
var formattedDate = $.datepicker.formatDate('yy-mm-dd', new Date(superblocktimestamp));
return formattedDate;
};
</script> </script>
@ -417,7 +437,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="end_epoch">Proposal End Date:</label> <label for="end_epoch">Choose payment cycle:</label>
<select name="end_epoch" class="form-control" id="end_epoch"></select> <select name="end_epoch" class="form-control" id="end_epoch"></select>
</div> </div>