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.
This commit is contained in:
Russell Ballestrini 2025-09-26 13:02:49 -04:00
parent 50b131190e
commit 8f48b08165

View file

@ -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