forked from fractalide/fractalide-website-styx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: No calculation/validation on ICO Details page (issue fractal…
…ide#188). Solution: Add calculation for ADA price and validation for terms & conditions and user answer.
- Loading branch information
1 parent
936cbdb
commit e2c0165
Showing
5 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$(document).ready(function(){ | ||
|
||
generateRandomEpoch(); | ||
|
||
$('#myModal').on('show.bs.modal', function (e) { | ||
if(!isValidAnswer()) { | ||
e.preventDefault(); | ||
generateRandomEpoch(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
function generateRandomEpoch(){ | ||
var e = Math.floor(Math.random() * 42); | ||
$('#epoch').html(e); | ||
} | ||
|
||
function calculateP(e) { | ||
var x = 0.01; | ||
var d = 75; | ||
var n = 41; | ||
var p = x * 0.01 * (100 - d + e / (n - 1) * d); | ||
return p.toFixed(4); | ||
} | ||
|
||
function isValidAnswer() { | ||
var valid = true; | ||
|
||
$('.checklist input[type=checkbox]').each(function(i) { | ||
valid &= $(this).is(':checked'); | ||
$(this).toggleClass('error', $(this).is(':not(:checked)')); | ||
}); | ||
|
||
var p = calculateP(parseInt($('#epoch').html())); | ||
var answer = (parseFloat($('#answer').val()) || 0).toFixed(4); | ||
valid &= answer === p | ||
$('#answer').parents('div.form-group').toggleClass('has-error', answer !== p); | ||
|
||
$('#warning_message').toggleClass('text-danger', !valid); | ||
|
||
return valid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters