update: ...........
This commit is contained in:
parent
e62b60e0fd
commit
df638c94f1
|
|
@ -121,13 +121,20 @@ async function handleTxEvent(event: any) {
|
|||
console.log(`SSE: tx ${txHash} for payment ${payment.id}: +${txValue} ${payment.coin}`);
|
||||
|
||||
// Insert into payment_txs (ignore duplicate)
|
||||
await sql`
|
||||
const [inserted] = await sql`
|
||||
INSERT INTO payment_txs (payment_id, txid, amount)
|
||||
VALUES (${payment.id}, ${txHash}, ${txValue.toFixed(8)})
|
||||
ON CONFLICT (payment_id, txid) DO NOTHING
|
||||
RETURNING id
|
||||
`;
|
||||
txidToPayment.set(txHash, payment.id);
|
||||
|
||||
// Extend expiry to 24h on first tx detection
|
||||
if (inserted) {
|
||||
const newExpiry = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
await sql`UPDATE payments SET expires_at = ${newExpiry.toISOString()} WHERE id = ${payment.id} AND expires_at < ${newExpiry.toISOString()}`;
|
||||
}
|
||||
|
||||
// Recalculate total received
|
||||
const [{ total }] = await sql`
|
||||
SELECT COALESCE(SUM(amount::numeric), 0) as total FROM payment_txs WHERE payment_id = ${payment.id}
|
||||
|
|
@ -252,16 +259,24 @@ export async function checkPayments() {
|
|||
const threshold = expected * THRESHOLD;
|
||||
|
||||
// Sync txs from address info into payment_txs
|
||||
let newTxDetected = false;
|
||||
if (info.in?.length) {
|
||||
for (const tx of info.in) {
|
||||
if (!tx.txid) continue;
|
||||
await sql`
|
||||
const [ins] = await sql`
|
||||
INSERT INTO payment_txs (payment_id, txid, amount, confirmed)
|
||||
VALUES (${payment.id}, ${tx.txid}, ${String(tx.amount ?? 0)}, ${tx.block != null})
|
||||
ON CONFLICT (payment_id, txid) DO UPDATE SET confirmed = EXCLUDED.confirmed
|
||||
RETURNING id
|
||||
`;
|
||||
if (ins) newTxDetected = true;
|
||||
}
|
||||
}
|
||||
// Extend expiry to 24h on first tx detection
|
||||
if (newTxDetected) {
|
||||
const newExpiry = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
await sql`UPDATE payments SET expires_at = ${newExpiry.toISOString()} WHERE id = ${payment.id} AND expires_at < ${newExpiry.toISOString()}`;
|
||||
}
|
||||
|
||||
if (payment.status === "pending" || payment.status === "underpaid") {
|
||||
if (coin.confirmations === 0 && received >= threshold) {
|
||||
|
|
|
|||
|
|
@ -298,8 +298,14 @@
|
|||
} else if (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>
|
||||
<span class="text-blue-400">Transaction received, waiting for 1 confirmation...</span>
|
||||
`;
|
||||
// Replace QR with loading spinner
|
||||
document.getElementById('pay-qr').replaceWith(Object.assign(document.createElement('div'), {
|
||||
id: 'pay-qr',
|
||||
className: 'w-48 h-48 mx-auto rounded-lg bg-gray-800 flex items-center justify-center',
|
||||
innerHTML: '<svg class="w-10 h-10 text-blue-500 animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/></svg>',
|
||||
}));
|
||||
syncTxids(data);
|
||||
} else if (status === 'paid') {
|
||||
clearInterval(pollInterval);
|
||||
|
|
|
|||
Loading…
Reference in New Issue