mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Recoding timer removing dependecy on browser's setInterval
Ref: https://github.com/btcpayserver/btcpayserver/issues/130
This commit is contained in:
@@ -104,12 +104,9 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var display = $(".timer-row__time-left"); // Timer container
|
|
||||||
|
|
||||||
// check if the Document expired
|
// check if the Document expired
|
||||||
if (srvModel.expirationSeconds > 0) {
|
if (srvModel.expirationSeconds > 0) {
|
||||||
progressStart(srvModel.maxTimeSeconds); // Progress bar
|
progressStart(srvModel.maxTimeSeconds); // Progress bar
|
||||||
startTimer(srvModel.expirationSeconds, display); // Timer
|
|
||||||
|
|
||||||
if (!validateEmail(srvModel.customerEmail))
|
if (!validateEmail(srvModel.customerEmail))
|
||||||
emailForm(); // Email form Display
|
emailForm(); // Email form Display
|
||||||
@@ -246,42 +243,21 @@ $(document).ready(function () {
|
|||||||
$(".single-item-order__right__btc-price__chevron").toggleClass("expanded");
|
$(".single-item-order__right__btc-price__chevron").toggleClass("expanded");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Timer Countdown
|
// Timer Countdown && Progress bar
|
||||||
function startTimer(duration, display) {
|
|
||||||
var timer = duration, minutes, seconds;
|
|
||||||
var timeout = setInterval(function () {
|
|
||||||
minutes = parseInt(timer / 60, 10);
|
|
||||||
seconds = parseInt(timer % 60, 10);
|
|
||||||
|
|
||||||
minutes = minutes < 10 ? "0" + minutes : minutes;
|
|
||||||
seconds = seconds < 10 ? "0" + seconds : seconds;
|
|
||||||
|
|
||||||
display.text(minutes + ":" + seconds);
|
|
||||||
|
|
||||||
if (--timer < 0) {
|
|
||||||
clearInterval(timeout);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progress bar
|
|
||||||
function progressStart(timerMax) {
|
function progressStart(timerMax) {
|
||||||
var end = new Date(); // Setup Time Variable, should come from server
|
var end = new Date(); // Setup Time Variable, should come from server
|
||||||
end.setSeconds(end.getSeconds() + srvModel.expirationSeconds);
|
end.setSeconds(end.getSeconds() + srvModel.expirationSeconds);
|
||||||
timerMax *= 1000; // Usually 15 minutes = 9000 second= 900000 ms
|
timerMax *= 1000; // Usually 15 minutes = 9000 second= 900000 ms
|
||||||
var timeoutVal = Math.floor(timerMax / 100); // Timeout calc
|
|
||||||
animateUpdate(); //Launch it
|
animateUpdate(); //Launch it
|
||||||
|
|
||||||
function updateProgress(percentage) {
|
|
||||||
$('.timer-row__progress-bar').css("width", percentage + "%");
|
|
||||||
}
|
|
||||||
|
|
||||||
function animateUpdate() {
|
function animateUpdate() {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var timeDiff = end.getTime() - now.getTime();
|
var timeDiff = end.getTime() - now.getTime();
|
||||||
var perc = 100 - Math.round(timeDiff / timerMax * 100);
|
var perc = 100 - Math.round(timeDiff / timerMax * 100);
|
||||||
var status = checkoutCtrl.srvModel.status;
|
var status = checkoutCtrl.srvModel.status;
|
||||||
|
|
||||||
|
updateTimer(timeDiff / 1000);
|
||||||
|
|
||||||
if (perc === 75 && (status === "paidPartial" || status === "new")) {
|
if (perc === 75 && (status === "paidPartial" || status === "new")) {
|
||||||
$(".timer-row").addClass("expiring-soon");
|
$(".timer-row").addClass("expiring-soon");
|
||||||
checkoutCtrl.expiringSoon = true;
|
checkoutCtrl.expiringSoon = true;
|
||||||
@@ -289,12 +265,34 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
if (perc <= 100) {
|
if (perc <= 100) {
|
||||||
updateProgress(perc);
|
updateProgress(perc);
|
||||||
|
|
||||||
|
var timeoutVal = 300; // Timeout calc
|
||||||
setTimeout(animateUpdate, timeoutVal);
|
setTimeout(animateUpdate, timeoutVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (perc >= 100 && status === "expired") {
|
//if (perc >= 100 && status === "expired") {
|
||||||
// onDataCallback(status);
|
// onDataCallback(status);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateProgress(percentage) {
|
||||||
|
$('.timer-row__progress-bar').css("width", percentage + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTimer(timer) {
|
||||||
|
var display = $(".timer-row__time-left");
|
||||||
|
if (timer >= 0) {
|
||||||
|
var minutes = parseInt(timer / 60, 10);
|
||||||
|
minutes = minutes < 10 ? "0" + minutes : minutes;
|
||||||
|
|
||||||
|
var seconds = parseInt(timer % 60, 10);
|
||||||
|
seconds = seconds < 10 ? "0" + seconds : seconds;
|
||||||
|
|
||||||
|
display.text(minutes + ":" + seconds);
|
||||||
|
} else {
|
||||||
|
display.text("00:00");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clipboard Copy
|
// Clipboard Copy
|
||||||
|
|||||||
Reference in New Issue
Block a user