diff --git a/index.html b/index.html index 0f9c9e7..63cd85b 100644 --- a/index.html +++ b/index.html @@ -716,7 +716,70 @@ function startDepositWatch(chain, id) { pollDeposit(); } -document.getElementById('check').addEventListener('click', () => document.getElementById('submit').click()); +// "Check server" is read-only: it looks the URL up in the list (GET /datalist) and +// shows the server's expiry and balance from /weinfodata. It never POSTs to /data, +// so checking a URL that is not listed creates nothing. +function normalizeUrl(u) { + u = u.trim(); + if (!u) return ''; + if (!u.startsWith('http://') && !u.startsWith('https://')) u = 'https://' + u; + return u.replace(/\/+$/, ''); +} +function hidePaymentRows() { + document.getElementById('iv-min').parentElement.style.display = 'none'; + document.getElementById('iv-addr').parentElement.style.display = 'none'; + document.getElementById('qrcode').style.display = 'none'; + document.getElementById('share-btn').style.display = 'none'; +} +document.getElementById('check').addEventListener('click', async () => { + stopDepositWatch(); + const urlInput = document.getElementById('url'); + const url = normalizeUrl(urlInput.value); + if (!url) return; + urlInput.value = url; + const chain = getChain(); + const status = document.getElementById('iv-status'); + const inv = document.getElementById('invoice'); + inv.classList.remove('show'); + document.getElementById('terms-box').classList.remove('show'); + status.className = ''; + status.textContent = 'Checking…'; + try { + const listResp = await fetch(`/datalist/${chain}?page=0&limit=100`); + if (!listResp.ok) throw new Error(`HTTP ${listResp.status}`); + const list = await listResp.json(); + const idx = list.findIndex(d => normalizeUrl(d.url || '').toLowerCase() === url.toLowerCase()); + if (idx < 0) { + status.className = 'err-line'; + status.textContent = `Not in the ${chain} list: no server with this exact URL. To list it, press "Add server".`; + return; + } + const d = list[idx]; + const infoResp = await fetch(`/weinfodata/${chain}/${d.id}`); + const info = infoResp.ok ? await infoResp.json() : {}; + const expiry = (info.expiry_date || '').slice(0, 10) || '—'; // '2027-07-16 00:00:00' -> the date + const bal = info.balance != null ? fmt(info.balance) : null; + const unc = info.unconfirmed_balance != null ? fmt(info.unconfirmed_balance) : null; + document.getElementById('iv-chain').textContent = info.chain || chain; + document.getElementById('iv-balance').textContent = bal ? (unc ? bal + ' (' + unc + ')' : bal) : '—'; + document.getElementById('iv-donations').textContent = info.donation != null ? fmt(info.donation) : '—'; + document.getElementById('iv-contact').textContent = '—'; + document.getElementById('iv-url').textContent = d.url; + const weinfoEl = document.getElementById('iv-weinfo'); + weinfoEl.href = `/weinfo/${chain}/${d.id}`; + weinfoEl.textContent = 'View page'; + document.getElementById('iv-nextdep').textContent = expiry; + document.getElementById('iv-nextdep-row').style.display = 'flex'; + hidePaymentRows(); + status.className = 'ok-line'; + status.textContent = `Server is listed (#${idx + 1} of ${list.length}). Expiry: ${expiry}. Renewal opens 6 months before.`; + inv.classList.add('show'); + inv.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } catch (err) { + status.className = 'err-line'; + status.textContent = 'Could not check the list right now. Please try again in a moment.'; + } +}); document.getElementById('submit').addEventListener('click', async () => { stopDepositWatch(); const urlInput = document.getElementById('url');