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