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:
2026-07-21 10:38:26 +02:00
co-authored by Claude Sonnet 5
parent a6dbe48457
commit ddaca5520e
2 changed files with 17 additions and 11 deletions
+8 -5
View File
@@ -33,8 +33,8 @@
<div id="admin-form" class="hidden">
<label>Fee address (dove finisce il 30% di ogni round)</label>
<input id="admin-fee-address" placeholder="plm1q...">
<label>Bet amount (sats, 1 PLM = 100000000 sats)</label>
<input id="admin-bet-amount" placeholder="es. 1000000000 per 10 PLM">
<label>Bet amount (PLM)</label>
<input id="admin-bet-amount" placeholder="es. 10 per 10 PLM">
<button onclick="adminSave()">Salva</button>
<div id="admin-status" style="margin-top:8px;font-size:0.9rem"></div>
</div>
@@ -65,11 +65,13 @@ function adminStatus(msg, ok) {
el.style.color = ok ? '#2a7a2a' : '#a02020';
}
const SATS_PER_PLM = 100000000;
async function adminLoad() {
try {
const data = await callAdmin('GET', '/admin/config');
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');
adminStatus('Configurazione caricata.', true);
} catch (e) {
@@ -79,9 +81,10 @@ async function adminLoad() {
async function adminSave() {
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 {
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);
} catch (e) {
adminStatus('Errore nel salvataggio: ' + e.message, false);
+9 -6
View File
@@ -48,7 +48,7 @@
<div>Indirizzo di deposito / vincite:</div>
<div class="addr" id="dash-address"></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>
<h3>Bet</h3>
@@ -58,8 +58,8 @@
<h3>Withdrawal</h3>
<label>Indirizzo esterno</label>
<input id="wd-address" placeholder="plm1q...">
<label>Importo (sats, 1 PLM = 100000000 sats)</label>
<input id="wd-amount" placeholder="es. 200000000 per 2 PLM">
<label>Importo (PLM)</label>
<input id="wd-amount" placeholder="es. 2 per 2 PLM">
<button onclick="withdraw()">Preleva</button>
</section>
@@ -123,10 +123,12 @@ function logout() {
document.getElementById('auth-section').classList.remove('hidden');
}
const SATS_PER_PLM = 100000000;
async function refreshMe() {
try {
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) {}
}
@@ -137,8 +139,9 @@ async function placeBet() {
async function withdraw() {
const ext = document.getElementById('wd-address').value;
const amt = parseInt(document.getElementById('wd-amount').value, 10);
try { await call('POST', '/withdrawals', { external_address: ext, amount_sats: amt }); } catch (e) {}
const amtPlm = parseFloat(document.getElementById('wd-amount').value);
const amtSats = Math.round(amtPlm * SATS_PER_PLM);
try { await call('POST', '/withdrawals', { external_address: ext, amount_sats: amtSats }); } catch (e) {}
refreshMe();
}