update: hopefully......
This commit is contained in:
parent
8a24b30b2a
commit
1e6739b42a
|
|
@ -159,11 +159,4 @@ export const routes = new Elysia()
|
|||
};
|
||||
})
|
||||
|
||||
// Lightweight status poll
|
||||
.get("/checkout/:id/status", async ({ accountId, params, set }) => {
|
||||
const [payment] = await sql`
|
||||
SELECT status, txid FROM payments WHERE id = ${params.id} AND account_id = ${accountId}
|
||||
`;
|
||||
if (!payment) { set.status = 404; return { error: "Payment not found" }; }
|
||||
return { status: payment.status, txid: payment.txid };
|
||||
});
|
||||
;
|
||||
|
|
|
|||
|
|
@ -232,16 +232,25 @@
|
|||
document.getElementById('pay-usd').textContent = data.amount_usd.toFixed(2);
|
||||
document.getElementById('pay-address').textContent = data.address;
|
||||
|
||||
// Show current status immediately
|
||||
if (data.status === 'confirming') {
|
||||
document.getElementById('pay-status').innerHTML = `
|
||||
<span class="w-2 h-2 rounded-full bg-blue-500 animate-pulse"></span>
|
||||
<span class="text-blue-400">Transaction detected, waiting for confirmation...</span>
|
||||
`;
|
||||
if (data.txid) watchedTxids.push(data.txid);
|
||||
}
|
||||
|
||||
// Start countdown
|
||||
const expiresAt = new Date(data.expires_at).getTime();
|
||||
updateCountdown(expiresAt);
|
||||
countdownInterval = setInterval(() => updateCountdown(expiresAt), 1000);
|
||||
|
||||
// Start SSE stream for instant tx detection on the client
|
||||
// Start SSE for instant tx/block detection
|
||||
watchAddress(data.coin, data.address);
|
||||
|
||||
// Poll as fallback (for confirmations and in case SSE drops)
|
||||
pollInterval = setInterval(() => pollStatus(), 10000);
|
||||
// Poll full checkout as fallback
|
||||
pollInterval = setInterval(() => pollPayment(), 10000);
|
||||
}
|
||||
|
||||
let watchedAddress = null;
|
||||
|
|
@ -316,9 +325,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function pollStatus() {
|
||||
async function pollPayment() {
|
||||
try {
|
||||
const res = await fetch(`${PAY_API}/checkout/${paymentId}/status`, { credentials: 'include' });
|
||||
const res = await fetch(`${PAY_API}/checkout/${paymentId}`, { credentials: 'include' });
|
||||
const data = await res.json();
|
||||
|
||||
if (data.status === 'confirming') {
|
||||
|
|
@ -326,6 +335,7 @@
|
|||
<span class="w-2 h-2 rounded-full bg-blue-500 animate-pulse"></span>
|
||||
<span class="text-blue-400">Transaction detected, waiting for confirmation...</span>
|
||||
`;
|
||||
if (data.txid && !watchedTxids.includes(data.txid)) watchedTxids.push(data.txid);
|
||||
} else if (data.status === 'paid') {
|
||||
clearInterval(pollInterval);
|
||||
clearInterval(countdownInterval);
|
||||
|
|
@ -364,7 +374,12 @@
|
|||
document.getElementById('step-pay').classList.remove('hidden');
|
||||
document.getElementById('pay-status-section').classList.add('hidden');
|
||||
document.getElementById('pay-success').classList.remove('hidden');
|
||||
} else if (data.status !== 'expired') {
|
||||
} else if (data.status === 'expired') {
|
||||
document.getElementById('step-select').classList.add('hidden');
|
||||
document.getElementById('step-pay').classList.remove('hidden');
|
||||
document.getElementById('pay-status-section').classList.add('hidden');
|
||||
document.getElementById('pay-expired').classList.remove('hidden');
|
||||
} else {
|
||||
paymentId = data.id;
|
||||
showPayment(data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue