diff --git a/the-matrix/js/payment.js b/the-matrix/js/payment.js index 7492bd3..d1dfe19 100644 --- a/the-matrix/js/payment.js +++ b/the-matrix/js/payment.js @@ -163,7 +163,9 @@ function startPolling() { async function poll() { if (!currentJobId) return; try { - const res = await fetch(`${API_BASE}/jobs/${currentJobId}`); + const token = await getOrRefreshToken('/api'); + const pollHeaders = token ? { 'X-Nostr-Token': token } : {}; + const res = await fetch(`${API_BASE}/jobs/${currentJobId}`, { headers: pollHeaders }); const data = await res.json(); const { state, workInvoice, result, reason } = data; diff --git a/the-matrix/js/ui.js b/the-matrix/js/ui.js index dc5c700..4795eed 100644 --- a/the-matrix/js/ui.js +++ b/the-matrix/js/ui.js @@ -117,9 +117,18 @@ async function _fetchEstimate(text) { } } +// Fast trivial heuristic — same pattern as edge-worker.js _isGreeting(). +// Prevents /api/estimate network calls for greeting messages on every keypress. +const _TRIVIAL_RE = /^(hi|hey|hello|howdy|greetings|yo|sup|hiya|what'?s up)[!?.,]?\s*$/i; + function _scheduleCostPreview(text) { clearTimeout(_estimateTimer); if (!text || text.length < 4) { _hideCostPreview(); return; } + // Skip estimate entirely for trivially local messages — zero network calls + if (_TRIVIAL_RE.test(text.trim())) { + _showCostPreview('answered locally ⚡ 0 sats', '#44dd88'); + return; + } _estimateTimer = setTimeout(() => _fetchEstimate(text), 300); }