From 8f48b08165a03bebd9da7f80b4ea95f230ef08f0 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Fri, 26 Sep 2025 13:02:49 -0400 Subject: [PATCH] Stop crypto quote page polling for terminal payment statuses The crypto checkout page was polling indefinitely even after reaching terminal states like expired, cancelled, or completed refunds. This wastes resources and can cause unnecessary server load. Changed the polling logic to: - Store the polling interval reference - Check after each poll if a terminal status has been reached - Clear the interval and stop polling for terminal statuses - Also stop polling for 'confirmed' status since the order is complete Terminal statuses that stop polling include: - expired - cancelled - expired-refunded-complete - underpaid-refunded-complete - confirmed-overpaid-refunded - out-of-stock-refunded-complete - no-refund - no-refund-complete - confirmed (order complete) Non-terminal statuses like 'underpaid-refunded' continue polling until they transition to their complete state. --- make_post_sell/templates/crypto_checkout.j2 | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/make_post_sell/templates/crypto_checkout.j2 b/make_post_sell/templates/crypto_checkout.j2 index 2e37e74..f9104fb 100644 --- a/make_post_sell/templates/crypto_checkout.j2 +++ b/make_post_sell/templates/crypto_checkout.j2 @@ -464,8 +464,30 @@ // ignore transient errors } } - poll(); - setInterval(poll, 5000); + + // Store polling interval so we can stop it for terminal statuses + let pollInterval = null; + + // Wrapper function to check if we should stop polling + async function pollWithTerminalCheck() { + await poll(); + + // Stop polling if we've reached a terminal status or confirmed status + const currentStatus = statusEl ? statusEl.textContent.trim() : ''; + if (terminalStatuses.includes(currentStatus) || currentStatus === 'confirmed') { + if (pollInterval) { + clearInterval(pollInterval); + pollInterval = null; + console.log('Stopped polling - terminal/confirmed status reached:', currentStatus); + } + } + } + + // Initial poll + pollWithTerminalCheck(); + + // Set up interval polling + pollInterval = setInterval(pollWithTerminalCheck, 5000); })(); // Cancel quote function