mirror of
https://github.com/seigler/govobject-proposal
synced 2025-07-27 06:46:10 +00:00
calculate total proposal amount
This commit is contained in:
parent
ab35b556d1
commit
f95f0cc29b
2 changed files with 67 additions and 21 deletions
42
index.html
42
index.html
|
@ -68,6 +68,29 @@
|
||||||
$('#mainnet').change(function() { gov = init('mainnet', mainnetProvider); });
|
$('#mainnet').change(function() { gov = init('mainnet', mainnetProvider); });
|
||||||
$('#testnet').change(function() { gov = init('testnet', testnetProvider); });
|
$('#testnet').change(function() { gov = init('testnet', testnetProvider); });
|
||||||
|
|
||||||
|
$('#start_epoch').change(function() {
|
||||||
|
paymentCycle.selectedStartIndex = $('#start_epoch').find(':selected').data('index');
|
||||||
|
paymentCycle.updateEndEpoch();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#end_epoch').change(function() {
|
||||||
|
paymentCycle.selectedPeriods = $('#end_epoch').find(':selected').data('index');
|
||||||
|
|
||||||
|
var payment_amount = parseInt($('#payment_amount').val());
|
||||||
|
var periods = parseInt(paymentCycle.selectedPeriods+1);
|
||||||
|
|
||||||
|
$('#total_amount').text(payment_amount * periods);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#payment_amount').change(function() {
|
||||||
|
paymentCycle.selectedPeriods = $('#end_epoch').find(':selected').data('index');
|
||||||
|
|
||||||
|
var payment_amount = parseInt($('#payment_amount').val());
|
||||||
|
var periods = parseInt(paymentCycle.selectedPeriods+1);
|
||||||
|
|
||||||
|
$('#total_amount').text(payment_amount * periods);
|
||||||
|
});
|
||||||
|
|
||||||
$("#time").val(Math.floor((new Date).getTime() / 1000));
|
$("#time").val(Math.floor((new Date).getTime() / 1000));
|
||||||
|
|
||||||
$('#prepareProposal').click(function() {
|
$('#prepareProposal').click(function() {
|
||||||
|
@ -242,7 +265,7 @@
|
||||||
<div class="row" id="createProposalHeader">
|
<div class="row" id="createProposalHeader">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<h1 class="removeMargin">Create a Proposal</h1>
|
<h1 class="removeMargin">Create a Proposal</h1>
|
||||||
<h5 class="header_description">Enter details for your proposal and click 'Create Proposal'. This will generate a command you can run in your local wallet to prepare the proposal at a cost of 0.33 Dash</h5>
|
<h5 class="header_description">Enter details for your proposal and click 'Create Proposal'. This will generate a command you can run in your local wallet to prepare the proposal at a cost of 0.33 DASH</h5>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -263,7 +286,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-3">
|
<div class="col-xs-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start_epoch">Start Date:</label>
|
<label for="start_epoch">First Payment:</label>
|
||||||
<select name="start_epoch" class="form-control" id="start_epoch"></select>
|
<select name="start_epoch" class="form-control" id="start_epoch"></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -275,7 +298,7 @@
|
||||||
<!-- -->
|
<!-- -->
|
||||||
<!-- The following form group is a placeholder for proposal end time. Please change to the correct id. -->
|
<!-- The following form group is a placeholder for proposal end time. Please change to the correct id. -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start_epoch">Number of Payments:</label>
|
<label for="start_epoch">Last Payment:</label>
|
||||||
<select name="start_epoch" class="form-control" id="end_epoch"></select>
|
<select name="start_epoch" class="form-control" id="end_epoch"></select>
|
||||||
</div>
|
</div>
|
||||||
<!-- -->
|
<!-- -->
|
||||||
|
@ -293,7 +316,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-7">
|
<div class="col-xs-7">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="payment_amount">Monthly Payment Amount in Dash:</label>
|
<label for="payment_amount">Payment Amount:</label>
|
||||||
<input type="text" class="form-control" id="payment_amount" value="" placeholder="0">
|
<input type="text" class="form-control" id="payment_amount" value="" placeholder="0">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -308,6 +331,15 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="total_amount">Total Amount: </label>
|
||||||
|
<span id="total_amount">0</span> <span>DASH</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group" style="display:none;">
|
<div class="form-group" style="display:none;">
|
||||||
<label for="type">type:</label>
|
<label for="type">type:</label>
|
||||||
<input type="text" class="form-control" id="type" value="1" placeholder="1">
|
<input type="text" class="form-control" id="type" value="1" placeholder="1">
|
||||||
|
@ -358,7 +390,7 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="prepareProposal">Prepare-Proposal Command:</label>
|
<label for="prepareProposal">Prepare-Proposal Command:</label>
|
||||||
<div>Paste this proposal command into your Dash wallet console to spend a Fee transaction of 0.33 DASH.</div>
|
<div>Paste this proposal command into your wallet console to spend a Fee transaction of 0.33 DASH.</div>
|
||||||
<textarea readonly class="form-control" id="prepareProposal" rows="4" placeholder=""></textarea>
|
<textarea readonly class="form-control" id="prepareProposal" rows="4" placeholder=""></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,17 @@ function PaymentCycle(gov, provider) {
|
||||||
this.paymentCycle = 16616; // mainnet
|
this.paymentCycle = 16616; // mainnet
|
||||||
this.budgetCycles = 24;
|
this.budgetCycles = 24;
|
||||||
|
|
||||||
|
this.selectedStartIndex = 0;
|
||||||
|
this.selectedPeriods = 1;
|
||||||
|
|
||||||
if (this.network == 'testnet') this.paymentCycle = 24;
|
if (this.network == 'testnet') this.paymentCycle = 24;
|
||||||
if (this.network == 'testnet') this.budgetCycles = 96;
|
if (this.network == 'testnet') this.budgetCycles = 96;
|
||||||
|
|
||||||
this.blockHeight = null;
|
this.blockHeight = null;
|
||||||
|
|
||||||
|
this.startDate = [];
|
||||||
|
this.endDate = [];
|
||||||
|
|
||||||
this.Messages = {
|
this.Messages = {
|
||||||
paymentCycle: {
|
paymentCycle: {
|
||||||
months: "Months",
|
months: "Months",
|
||||||
|
@ -89,31 +95,28 @@ PaymentCycle.prototype.updateDropdowns = function() {
|
||||||
|
|
||||||
var blockHeight = this.blockHeight;
|
var blockHeight = this.blockHeight;
|
||||||
|
|
||||||
var startDate = [];
|
|
||||||
var endDate = [];
|
|
||||||
|
|
||||||
for (i = 0; i < this.budgetCycles + 1; i++) {
|
for (i = 0; i < this.budgetCycles + 1; i++) {
|
||||||
|
|
||||||
var superblock = this.getNextSuperblock(blockHeight);
|
var superblock = this.getNextSuperblock(blockHeight);
|
||||||
var timestamp = this.getBlockTimestamp(superblock);
|
var timestamp = this.getBlockTimestamp(superblock);
|
||||||
|
|
||||||
var label = new Date(timestamp).toLocaleDateString();
|
var label = new Date(timestamp).toLocaleDateString();
|
||||||
if (this.network == 'testnet') label = new Date(timestamp).toLocaleString();
|
if (this.network == 'testnet') label += " @ " + new Date(timestamp).toLocaleTimeString();
|
||||||
|
|
||||||
var superblockDate = {
|
var superblockDate = {
|
||||||
superblock: superblock,
|
superblock: superblock,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
label: label
|
label: label
|
||||||
};
|
};
|
||||||
startDate.push(superblockDate);
|
this.startDate.push(superblockDate);
|
||||||
endDate.push(superblockDate);
|
this.endDate.push(superblockDate);
|
||||||
|
|
||||||
blockHeight = superblock;
|
blockHeight = superblock;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endDate.shift(); // remove first element of endDate
|
this.endDate.shift(); // remove first element of endDate
|
||||||
startDate.pop(); // remove last element of startDate to keep length even
|
this.startDate.pop(); // remove last element of startDate to keep length even
|
||||||
|
|
||||||
var now = Math.floor(Date.now());
|
var now = Math.floor(Date.now());
|
||||||
|
|
||||||
|
@ -125,7 +128,7 @@ PaymentCycle.prototype.updateDropdowns = function() {
|
||||||
|
|
||||||
var start_epoch = $("#start_epoch");
|
var start_epoch = $("#start_epoch");
|
||||||
start_epoch.find('option').remove();
|
start_epoch.find('option').remove();
|
||||||
$.each(startDate, function(index) {
|
$.each(this.startDate, function(index) {
|
||||||
|
|
||||||
var eta = self.getTimeDifference(opts, now, this.timestamp);
|
var eta = self.getTimeDifference(opts, now, this.timestamp);
|
||||||
var time = this.timestamp - now;
|
var time = this.timestamp - now;
|
||||||
|
@ -134,22 +137,33 @@ PaymentCycle.prototype.updateDropdowns = function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.updateEndEpoch();
|
||||||
|
|
||||||
opts.precision = null; // 0 units of precision for eta formatting
|
};
|
||||||
|
|
||||||
|
PaymentCycle.prototype.updateEndEpoch = function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var opts = {
|
||||||
|
precision: null
|
||||||
|
}; // 0 units of precision for eta formatting
|
||||||
|
|
||||||
var end_epoch = $("#end_epoch");
|
var end_epoch = $("#end_epoch");
|
||||||
end_epoch.find('option').remove();
|
end_epoch.find('option').remove();
|
||||||
$.each(endDate, function(index) {
|
$.each(this.endDate, function(index) {
|
||||||
|
|
||||||
var eta = self.getTimeDifference(opts, startDate[0].timestamp, this.timestamp);
|
if(index >= self.selectedStartIndex) {
|
||||||
var time = this.timestamp - startDate[0].timestamp;
|
|
||||||
|
|
||||||
var option = $("<option />").val((Math.floor(this.timestamp / 1000))).text(eta + " (" + this.label + ")").attr('data-index', index).attr('data-time', time).attr('data-eta', eta).attr('data-block', this.superblock);
|
var eta = self.getTimeDifference(opts, self.startDate[self.selectedStartIndex].timestamp, this.timestamp);
|
||||||
end_epoch.append(option);
|
var time = this.timestamp - self.startDate[self.selectedStartIndex].timestamp;
|
||||||
|
|
||||||
|
var option = $("<option />").val((Math.floor(this.timestamp / 1000))).text(this.label).attr('data-index', index).attr('data-time', time).attr('data-eta', eta).attr('data-block', this.superblock);
|
||||||
|
end_epoch.append(option);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PaymentCycle.prototype.getInfo = function(cb) {
|
PaymentCycle.prototype.getInfo = function(cb) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue