Show and accept amounts in PLM in the test/admin UIs

Balance, withdrawal amount and bet_amount_sats are entered/displayed in
PLM in both static pages; conversion to sats happens client-side right
before the API call, since the backend contract stays sats-based.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5 committed 2026-07-21 10:38:26 +02:00
1 parent a6dbe48457
commit ddaca5520e
2 files changed
+17 -11

No files matched your search

+8 -5
View File
@@ -33,8 +33,8 @@
<div id="admin-form" class="hidden"> <div id="admin-form" class="hidden">
<label>Fee address (dove finisce il 30% di ogni round)</label> <label>Fee address (dove finisce il 30% di ogni round)</label>
<input id="admin-fee-address" placeholder="plm1q..."> <input id="admin-fee-address" placeholder="plm1q...">
<label>Bet amount (sats, 1 PLM = 100000000 sats)</label> <label>Bet amount (PLM)</label>
<input id="admin-bet-amount" placeholder="es. 1000000000 per 10 PLM"> <input id="admin-bet-amount" placeholder="es. 10 per 10 PLM">
<button onclick="adminSave()">Salva</button> <button onclick="adminSave()">Salva</button>
<div id="admin-status" style="margin-top:8px;font-size:0.9rem"></div> <div id="admin-status" style="margin-top:8px;font-size:0.9rem"></div>
</div> </div>
@@ -65,11 +65,13 @@ function adminStatus(msg, ok) {
el.style.color = ok ? '#2a7a2a' : '#a02020'; el.style.color = ok ? '#2a7a2a' : '#a02020';
} }
const SATS_PER_PLM = 100000000;
async function adminLoad() { async function adminLoad() {
try { try {
const data = await callAdmin('GET', '/admin/config'); const data = await callAdmin('GET', '/admin/config');
document.getElementById('admin-fee-address').value = data.fee_address; document.getElementById('admin-fee-address').value = data.fee_address;
document.getElementById('admin-bet-amount').value = data.bet_amount_sats; document.getElementById('admin-bet-amount').value = data.bet_amount_sats / SATS_PER_PLM;
document.getElementById('admin-form').classList.remove('hidden'); document.getElementById('admin-form').classList.remove('hidden');
adminStatus('Configurazione caricata.', true); adminStatus('Configurazione caricata.', true);
} catch (e) { } catch (e) {
@@ -79,9 +81,10 @@ async function adminLoad() {
async function adminSave() { async function adminSave() {
const feeAddress = document.getElementById('admin-fee-address').value; const feeAddress = document.getElementById('admin-fee-address').value;
const betAmount = parseInt(document.getElementById('admin-bet-amount').value, 10); const betAmountPlm = parseFloat(document.getElementById('admin-bet-amount').value);
const betAmountSats = Math.round(betAmountPlm * SATS_PER_PLM);
try { try {
await callAdmin('PUT', '/admin/config', { fee_address: feeAddress, bet_amount_sats: betAmount }); await callAdmin('PUT', '/admin/config', { fee_address: feeAddress, bet_amount_sats: betAmountSats });
adminStatus('Salvato.', true); adminStatus('Salvato.', true);
} catch (e) { } catch (e) {
adminStatus('Errore nel salvataggio: ' + e.message, false); adminStatus('Errore nel salvataggio: ' + e.message, false);
+9 -6
View File
@@ -48,7 +48,7 @@
<div>Indirizzo di deposito / vincite:</div> <div>Indirizzo di deposito / vincite:</div>
<div class="addr" id="dash-address"></div> <div class="addr" id="dash-address"></div>
<div style="margin-top:12px">Saldo interno:</div> <div style="margin-top:12px">Saldo interno:</div>
<div class="balance"><span id="dash-balance">-</span> sats <button onclick="refreshMe()">Aggiorna</button></div> <div class="balance"><span id="dash-balance">-</span> PLM <button onclick="refreshMe()">Aggiorna</button></div>
<hr> <hr>
<h3>Bet</h3> <h3>Bet</h3>
@@ -58,8 +58,8 @@
<h3>Withdrawal</h3> <h3>Withdrawal</h3>
<label>Indirizzo esterno</label> <label>Indirizzo esterno</label>
<input id="wd-address" placeholder="plm1q..."> <input id="wd-address" placeholder="plm1q...">
<label>Importo (sats, 1 PLM = 100000000 sats)</label> <label>Importo (PLM)</label>
<input id="wd-amount" placeholder="es. 200000000 per 2 PLM"> <input id="wd-amount" placeholder="es. 2 per 2 PLM">
<button onclick="withdraw()">Preleva</button> <button onclick="withdraw()">Preleva</button>
</section> </section>
@@ -123,10 +123,12 @@ function logout() {
document.getElementById('auth-section').classList.remove('hidden'); document.getElementById('auth-section').classList.remove('hidden');
} }
const SATS_PER_PLM = 100000000;
async function refreshMe() { async function refreshMe() {
try { try {
const data = await call('GET', '/users/me'); const data = await call('GET', '/users/me');
document.getElementById('dash-balance').textContent = data.balance_sats; document.getElementById('dash-balance').textContent = data.balance_sats / SATS_PER_PLM;
} catch (e) {} } catch (e) {}
} }
@@ -137,8 +139,9 @@ async function placeBet() {
async function withdraw() { async function withdraw() {
const ext = document.getElementById('wd-address').value; const ext = document.getElementById('wd-address').value;
const amt = parseInt(document.getElementById('wd-amount').value, 10); const amtPlm = parseFloat(document.getElementById('wd-amount').value);
try { await call('POST', '/withdrawals', { external_address: ext, amount_sats: amt }); } catch (e) {} const amtSats = Math.round(amtPlm * SATS_PER_PLM);
try { await call('POST', '/withdrawals', { external_address: ext, amount_sats: amtSats }); } catch (e) {}
refreshMe(); refreshMe();
} }