2026-07-21 10:27:05 +02:00
|
|
|
<!doctype html>
|
|
|
|
|
<html lang="it">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
2026-07-21 10:46:55 +02:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
|
<title>PLM Lottery — Test</title>
|
2026-07-21 10:27:05 +02:00
|
|
|
<style>
|
2026-07-21 10:46:55 +02:00
|
|
|
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@500;600&family=Fira+Sans:wght@400;500;600;700&display=swap');
|
|
|
|
|
|
|
|
|
|
:root {
|
|
|
|
|
--color-background: #F8FAFC;
|
|
|
|
|
--color-surface: #FFFFFF;
|
|
|
|
|
--color-foreground: #0F172A;
|
|
|
|
|
--color-muted-foreground: #64748B;
|
|
|
|
|
--color-border: #E2E8F0;
|
|
|
|
|
--color-primary: #F59E0B;
|
|
|
|
|
--color-on-primary: #0F172A;
|
|
|
|
|
--color-accent: #7C3AED;
|
|
|
|
|
--color-destructive: #DC2626;
|
|
|
|
|
--color-destructive-bg: #FEF2F2;
|
|
|
|
|
--color-success: #16A34A;
|
|
|
|
|
--color-success-bg: #F0FDF4;
|
|
|
|
|
--color-ring: #F59E0B;
|
|
|
|
|
--radius: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
* { box-sizing: border-box; }
|
|
|
|
|
|
|
|
|
|
body {
|
|
|
|
|
font-family: 'Fira Sans', system-ui, sans-serif;
|
|
|
|
|
background: var(--color-background);
|
|
|
|
|
color: var(--color-foreground);
|
|
|
|
|
max-width: 480px;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
padding: 32px 20px 80px;
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.mono { font-family: 'Fira Code', monospace; }
|
|
|
|
|
|
|
|
|
|
header { margin-bottom: 24px; }
|
|
|
|
|
header h1 { font-size: 1.375rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
|
|
|
|
|
header p { color: var(--color-muted-foreground); font-size: 0.9rem; margin: 4px 0 0; }
|
|
|
|
|
|
|
|
|
|
.card {
|
|
|
|
|
background: var(--color-surface);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: var(--radius);
|
|
|
|
|
padding: 20px;
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.card h2 { font-size: 1rem; font-weight: 600; margin: 0 0 4px; }
|
|
|
|
|
.card .hint { color: var(--color-muted-foreground); font-size: 0.85rem; margin: 0 0 14px; }
|
|
|
|
|
|
|
|
|
|
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--color-border); }
|
|
|
|
|
.tab {
|
|
|
|
|
flex: 1; text-align: center; padding: 10px 0; font-weight: 600; font-size: 0.9rem;
|
|
|
|
|
color: var(--color-muted-foreground); cursor: pointer; border-bottom: 2px solid transparent;
|
|
|
|
|
margin-bottom: -1px; transition: color 150ms, border-color 150ms;
|
|
|
|
|
}
|
|
|
|
|
.tab.active { color: var(--color-foreground); border-bottom-color: var(--color-primary); }
|
|
|
|
|
.tab-panel { display: none; }
|
|
|
|
|
.tab-panel.active { display: block; }
|
|
|
|
|
|
|
|
|
|
label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--color-muted-foreground); margin-top: 12px; margin-bottom: 6px; }
|
|
|
|
|
label:first-child { margin-top: 0; }
|
|
|
|
|
|
|
|
|
|
input {
|
|
|
|
|
width: 100%; padding: 10px 12px; font-size: 0.95rem; font-family: inherit;
|
|
|
|
|
border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface);
|
|
|
|
|
color: var(--color-foreground); transition: border-color 150ms, box-shadow 150ms;
|
|
|
|
|
}
|
|
|
|
|
input:focus {
|
|
|
|
|
outline: none; border-color: var(--color-ring);
|
|
|
|
|
box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-ring) 25%, transparent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
button {
|
|
|
|
|
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
|
|
|
|
min-height: 44px; padding: 0 18px; margin-top: 16px; width: 100%;
|
|
|
|
|
font-family: inherit; font-size: 0.95rem; font-weight: 600;
|
|
|
|
|
background: var(--color-primary); color: var(--color-on-primary);
|
|
|
|
|
border: none; border-radius: 8px; cursor: pointer;
|
|
|
|
|
transition: filter 150ms, transform 150ms;
|
|
|
|
|
}
|
|
|
|
|
button:hover { filter: brightness(0.94); }
|
|
|
|
|
button:active { transform: scale(0.98); }
|
|
|
|
|
button:disabled { opacity: 0.6; cursor: default; }
|
|
|
|
|
button:focus-visible { outline: 2px solid var(--color-ring); outline-offset: 2px; }
|
|
|
|
|
|
|
|
|
|
button.secondary {
|
|
|
|
|
width: auto; margin-top: 0; padding: 0 12px; min-height: 36px;
|
|
|
|
|
background: var(--color-background); color: var(--color-foreground);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
button.link {
|
|
|
|
|
width: auto; margin-top: 0; padding: 0; min-height: auto;
|
|
|
|
|
background: none; color: var(--color-muted-foreground); font-weight: 500;
|
|
|
|
|
font-size: 0.85rem; text-decoration: underline;
|
|
|
|
|
}
|
|
|
|
|
button.link:hover { filter: none; color: var(--color-foreground); }
|
|
|
|
|
|
|
|
|
|
.account-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
|
|
|
|
|
.account-bar .name { font-weight: 600; }
|
|
|
|
|
|
|
|
|
|
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
|
|
|
|
|
|
|
|
.address-box {
|
|
|
|
|
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
|
|
|
background: var(--color-background); border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: 8px; padding: 10px 12px; font-size: 0.85rem; word-break: break-all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.balance-value { font-size: 2rem; font-weight: 700; }
|
|
|
|
|
.balance-unit { color: var(--color-muted-foreground); font-size: 1rem; font-weight: 500; }
|
|
|
|
|
|
|
|
|
|
.icon { width: 16px; height: 16px; flex-shrink: 0; }
|
|
|
|
|
|
2026-07-21 10:52:06 +02:00
|
|
|
nav.menu { display: flex; gap: 4px; margin-bottom: 16px; }
|
|
|
|
|
nav.menu button.nav-item {
|
|
|
|
|
flex: 1; width: auto; margin-top: 0; min-height: 56px; padding: 8px 4px;
|
|
|
|
|
flex-direction: column; gap: 4px; font-size: 0.8rem; font-weight: 600;
|
|
|
|
|
background: var(--color-surface); color: var(--color-muted-foreground);
|
|
|
|
|
border: 1px solid var(--color-border); border-radius: 10px;
|
|
|
|
|
}
|
|
|
|
|
nav.menu button.nav-item .icon { width: 20px; height: 20px; }
|
|
|
|
|
nav.menu button.nav-item.active {
|
|
|
|
|
background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary);
|
|
|
|
|
}
|
|
|
|
|
nav.menu button.nav-item:hover { filter: none; border-color: var(--color-ring); }
|
|
|
|
|
nav.menu button.nav-item.active:hover { filter: brightness(0.94); }
|
|
|
|
|
|
|
|
|
|
.dash-panel { display: none; }
|
|
|
|
|
.dash-panel.active { display: block; }
|
|
|
|
|
|
|
|
|
|
.qr-box { display: flex; justify-content: center; padding: 16px; background: #fff; border: 1px solid var(--color-border); border-radius: 10px; margin-top: 14px; }
|
|
|
|
|
.qr-box img { width: 200px; height: 200px; image-rendering: pixelated; }
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
.hidden { display: none !important; }
|
|
|
|
|
|
2026-07-21 16:03:42 +02:00
|
|
|
.draw-state { display: none; text-align: center; padding: 8px 0 4px; }
|
|
|
|
|
.draw-state.active { display: block; }
|
|
|
|
|
.draw-spinner {
|
|
|
|
|
width: 40px; height: 40px; margin: 0 auto 10px;
|
|
|
|
|
border: 3px solid var(--color-border); border-top-color: var(--color-primary);
|
|
|
|
|
border-radius: 50%; animation: spin 900ms linear infinite;
|
|
|
|
|
}
|
|
|
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
|
|
|
.draw-state .draw-label { font-weight: 600; font-size: 0.95rem; }
|
|
|
|
|
.draw-result { font-size: 1.05rem; font-weight: 700; padding: 6px 0; }
|
|
|
|
|
.draw-result.win { color: var(--color-success); }
|
|
|
|
|
.draw-result.lose { color: var(--color-muted-foreground); }
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
#toast-container {
|
|
|
|
|
position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
|
|
|
|
|
display: flex; flex-direction: column; gap: 8px; z-index: 100; width: calc(100% - 40px); max-width: 440px;
|
|
|
|
|
}
|
|
|
|
|
.toast {
|
|
|
|
|
display: flex; align-items: flex-start; gap: 8px;
|
|
|
|
|
padding: 12px 14px; border-radius: 8px; font-size: 0.85rem; font-weight: 500;
|
|
|
|
|
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
|
|
|
|
|
animation: toast-in 200ms ease-out;
|
|
|
|
|
}
|
|
|
|
|
.toast.success { background: var(--color-success-bg); color: var(--color-success); }
|
|
|
|
|
.toast.error { background: var(--color-destructive-bg); color: var(--color-destructive); }
|
|
|
|
|
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
|
|
|
|
|
|
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
|
|
|
* { animation: none !important; transition: none !important; }
|
|
|
|
|
}
|
2026-07-21 10:27:05 +02:00
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
<header>
|
|
|
|
|
<h1>PLM Lottery</h1>
|
|
|
|
|
<p>Dashboard di test — mainnet reale</p>
|
|
|
|
|
</header>
|
2026-07-21 10:27:05 +02:00
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
<section id="auth-section" class="card">
|
|
|
|
|
<div class="tabs">
|
|
|
|
|
<div class="tab active" id="tab-login" onclick="switchTab('login')">Login</div>
|
|
|
|
|
<div class="tab" id="tab-register" onclick="switchTab('register')">Registrati</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-panel active" id="panel-login">
|
|
|
|
|
<label for="login-username">Username</label>
|
|
|
|
|
<input id="login-username" autocomplete="username">
|
|
|
|
|
<label for="login-password">Password</label>
|
|
|
|
|
<input id="login-password" type="password" autocomplete="current-password">
|
|
|
|
|
<button onclick="login()" id="login-btn">Accedi</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-panel" id="panel-register">
|
|
|
|
|
<label for="reg-username">Username</label>
|
|
|
|
|
<input id="reg-username" autocomplete="username">
|
|
|
|
|
<label for="reg-password">Password</label>
|
|
|
|
|
<input id="reg-password" type="password" autocomplete="new-password">
|
2026-07-21 14:22:03 +02:00
|
|
|
<label for="reg-password-confirm">Conferma password</label>
|
|
|
|
|
<input id="reg-password-confirm" type="password" autocomplete="new-password">
|
2026-07-21 10:46:55 +02:00
|
|
|
<button onclick="register()" id="register-btn">Crea account</button>
|
2026-07-21 10:27:05 +02:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section id="dashboard-section" class="hidden">
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
<div class="card">
|
|
|
|
|
<div class="account-bar">
|
|
|
|
|
<span class="name" id="dash-username"></span>
|
|
|
|
|
<button class="link" onclick="logout()">Esci</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-21 10:57:39 +02:00
|
|
|
<div class="card">
|
2026-07-21 16:03:42 +02:00
|
|
|
<div class="row-between" id="round-normal-row">
|
2026-07-21 10:57:39 +02:00
|
|
|
<h2 id="round-title">Round —</h2>
|
|
|
|
|
<span class="mono" id="round-timer" style="font-size:1.1rem;font-weight:700">--:--</span>
|
|
|
|
|
</div>
|
2026-07-21 16:03:42 +02:00
|
|
|
<div class="row-between" style="margin-top:10px" id="round-stats-row">
|
2026-07-21 10:57:39 +02:00
|
|
|
<div>
|
|
|
|
|
<div class="hint" style="margin-bottom:2px">Giocatori</div>
|
|
|
|
|
<span class="mono" id="round-players">—</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="text-align:right">
|
|
|
|
|
<div class="hint" style="margin-bottom:2px">Jackpot</div>
|
|
|
|
|
<span class="mono" id="round-jackpot">—</span> <span class="balance-unit">PLM</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-07-21 16:03:42 +02:00
|
|
|
|
|
|
|
|
<div class="draw-state" id="draw-state">
|
|
|
|
|
<div class="draw-spinner"></div>
|
|
|
|
|
<div class="draw-label">Estrazione del vincitore in corso…</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="hidden" id="draw-result"></div>
|
2026-07-21 10:57:39 +02:00
|
|
|
</div>
|
|
|
|
|
|
2026-07-21 10:52:06 +02:00
|
|
|
<nav class="menu" aria-label="Sezioni">
|
|
|
|
|
<button class="nav-item active" id="nav-deposit" onclick="switchPanel('deposit')">
|
|
|
|
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="14" rx="2"/><path d="M16 21V5a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v16"/></svg>
|
|
|
|
|
Deposito
|
|
|
|
|
</button>
|
|
|
|
|
<button class="nav-item" id="nav-bet" onclick="switchPanel('bet')">
|
|
|
|
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="6" width="20" height="12" rx="2"/><path d="M6 12h.01M12 12h.01M18 12h.01"/></svg>
|
|
|
|
|
Bet
|
|
|
|
|
</button>
|
|
|
|
|
<button class="nav-item" id="nav-withdraw" onclick="switchPanel('withdraw')">
|
|
|
|
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
|
|
|
|
|
Prelievo
|
|
|
|
|
</button>
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
<div class="dash-panel active" id="panel-deposit">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<h2>Saldo interno</h2>
|
|
|
|
|
<p class="hint">Aggiornato dopo 1 conferma sulla rete</p>
|
|
|
|
|
<div class="row-between">
|
|
|
|
|
<div><span class="balance-value mono" id="dash-balance">—</span> <span class="balance-unit">PLM</span></div>
|
|
|
|
|
<button class="secondary" onclick="refreshMe()" id="refresh-btn" aria-label="Aggiorna saldo">
|
|
|
|
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6"/></svg>
|
|
|
|
|
Aggiorna
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card">
|
|
|
|
|
<h2>Indirizzo di deposito</h2>
|
|
|
|
|
<p class="hint">È anche l'indirizzo su cui ricevi eventuali vincite</p>
|
|
|
|
|
<div class="address-box">
|
|
|
|
|
<span class="mono" id="dash-address"></span>
|
|
|
|
|
<button class="secondary" onclick="copyAddress()" aria-label="Copia indirizzo">
|
|
|
|
|
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="qr-box">
|
|
|
|
|
<img id="dash-qr" alt="QR code dell'indirizzo di deposito">
|
|
|
|
|
</div>
|
2026-07-21 10:46:55 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-21 10:52:06 +02:00
|
|
|
<div class="dash-panel" id="panel-bet">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<h2>Bet</h2>
|
|
|
|
|
<p class="hint">Ingresso fisso al round corrente</p>
|
|
|
|
|
<button onclick="placeBet()" id="bet-btn">Piazza bet (10 PLM)</button>
|
2026-07-21 10:46:55 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-21 10:52:06 +02:00
|
|
|
<div class="dash-panel" id="panel-withdraw">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<h2>Withdrawal</h2>
|
|
|
|
|
<p class="hint">Invia fondi a un indirizzo PLM esterno</p>
|
|
|
|
|
<label for="wd-address">Indirizzo esterno</label>
|
|
|
|
|
<input id="wd-address" class="mono" placeholder="plm1q...">
|
|
|
|
|
<label for="wd-amount">Importo (PLM)</label>
|
|
|
|
|
<input id="wd-amount" inputmode="decimal" placeholder="es. 2">
|
|
|
|
|
<button onclick="withdraw()" id="withdraw-btn">Preleva</button>
|
|
|
|
|
</div>
|
2026-07-21 10:46:55 +02:00
|
|
|
</div>
|
2026-07-21 10:27:05 +02:00
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
<div id="toast-container" aria-live="polite"></div>
|
2026-07-21 10:27:05 +02:00
|
|
|
|
|
|
|
|
<script>
|
2026-07-21 10:46:55 +02:00
|
|
|
const SATS_PER_PLM = 100000000;
|
|
|
|
|
|
2026-07-21 10:27:05 +02:00
|
|
|
let token = localStorage.getItem('plm_token');
|
|
|
|
|
let username = localStorage.getItem('plm_username');
|
|
|
|
|
let address = localStorage.getItem('plm_address');
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
function toast(message, type) {
|
|
|
|
|
const container = document.getElementById('toast-container');
|
|
|
|
|
const el = document.createElement('div');
|
|
|
|
|
el.className = 'toast ' + type;
|
|
|
|
|
el.textContent = message;
|
|
|
|
|
container.appendChild(el);
|
|
|
|
|
setTimeout(() => el.remove(), 4000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function withLoading(button, label, fn) {
|
|
|
|
|
const original = button.textContent;
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
button.textContent = label;
|
|
|
|
|
try {
|
|
|
|
|
await fn();
|
|
|
|
|
} finally {
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
button.textContent = original;
|
|
|
|
|
}
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function call(method, path, body) {
|
|
|
|
|
const headers = { 'Content-Type': 'application/json' };
|
|
|
|
|
if (token) headers['Authorization'] = 'Bearer ' + token;
|
|
|
|
|
const res = await fetch(path, { method, headers, body: body ? JSON.stringify(body) : undefined });
|
|
|
|
|
const data = await res.json().catch(() => ({}));
|
|
|
|
|
if (!res.ok) throw new Error(data.detail || res.statusText);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
function switchTab(name) {
|
|
|
|
|
document.getElementById('tab-login').classList.toggle('active', name === 'login');
|
|
|
|
|
document.getElementById('tab-register').classList.toggle('active', name === 'register');
|
|
|
|
|
document.getElementById('panel-login').classList.toggle('active', name === 'login');
|
|
|
|
|
document.getElementById('panel-register').classList.toggle('active', name === 'register');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:52:06 +02:00
|
|
|
function switchPanel(name) {
|
|
|
|
|
for (const key of ['deposit', 'bet', 'withdraw']) {
|
|
|
|
|
document.getElementById('nav-' + key).classList.toggle('active', key === name);
|
|
|
|
|
document.getElementById('panel-' + key).classList.toggle('active', key === name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:57:39 +02:00
|
|
|
let roundCloseAt = null;
|
|
|
|
|
let roundTimerInterval = null;
|
2026-07-21 16:03:42 +02:00
|
|
|
let roundPollTimeout = null;
|
2026-07-21 10:57:39 +02:00
|
|
|
|
|
|
|
|
const ROUND_STATUS_LABELS = {
|
|
|
|
|
open: 'aperto',
|
|
|
|
|
closing: 'in chiusura',
|
|
|
|
|
drawing: 'estrazione in corso',
|
|
|
|
|
paying_out: 'pagamento in corso',
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-21 16:03:42 +02:00
|
|
|
const DRAWING_STATUSES = ['closing', 'drawing', 'paying_out'];
|
|
|
|
|
|
|
|
|
|
// Per round_id: when we first saw it enter a drawing status (client clock), and
|
|
|
|
|
// whether the win/lose result has already been shown for it. Local-only state,
|
|
|
|
|
// not persisted — a page reload just re-derives it from the next poll.
|
|
|
|
|
const drawStartedAt = {};
|
|
|
|
|
const revealedRounds = new Set();
|
|
|
|
|
let activeResultRoundId = null; // round_id whose win/lose result is on screen, if any
|
|
|
|
|
|
2026-07-21 10:57:39 +02:00
|
|
|
function updateRoundTimer() {
|
|
|
|
|
const el = document.getElementById('round-timer');
|
|
|
|
|
if (!roundCloseAt) { el.textContent = '--:--'; return; }
|
|
|
|
|
const totalSec = Math.max(0, Math.floor((roundCloseAt - new Date()) / 1000));
|
|
|
|
|
const mm = String(Math.floor(totalSec / 60)).padStart(2, '0');
|
|
|
|
|
const ss = String(totalSec % 60).padStart(2, '0');
|
|
|
|
|
el.textContent = mm + ':' + ss;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 16:03:42 +02:00
|
|
|
function showDrawingState() {
|
|
|
|
|
document.getElementById('round-normal-row').classList.add('hidden');
|
|
|
|
|
document.getElementById('round-stats-row').classList.add('hidden');
|
|
|
|
|
document.getElementById('draw-state').classList.add('active');
|
|
|
|
|
document.getElementById('draw-result').classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showResultState(html, cls) {
|
|
|
|
|
document.getElementById('round-normal-row').classList.add('hidden');
|
|
|
|
|
document.getElementById('round-stats-row').classList.add('hidden');
|
|
|
|
|
document.getElementById('draw-state').classList.remove('active');
|
|
|
|
|
const el = document.getElementById('draw-result');
|
|
|
|
|
el.className = 'draw-result ' + cls;
|
|
|
|
|
el.innerHTML = html;
|
|
|
|
|
el.classList.remove('hidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showNormalState() {
|
|
|
|
|
document.getElementById('round-normal-row').classList.remove('hidden');
|
|
|
|
|
document.getElementById('round-stats-row').classList.remove('hidden');
|
|
|
|
|
document.getElementById('draw-state').classList.remove('active');
|
|
|
|
|
document.getElementById('draw-result').classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:57:39 +02:00
|
|
|
async function refreshRound() {
|
|
|
|
|
try {
|
|
|
|
|
const data = await call('GET', '/rounds/current');
|
|
|
|
|
document.getElementById('round-title').textContent = data.round_id
|
|
|
|
|
? 'Round #' + data.round_id + ' — ' + (ROUND_STATUS_LABELS[data.status] || data.status)
|
|
|
|
|
: 'Nessun round attivo';
|
|
|
|
|
document.getElementById('round-players').textContent = data.participant_count;
|
|
|
|
|
document.getElementById('round-jackpot').textContent = data.jackpot_sats / SATS_PER_PLM;
|
|
|
|
|
roundCloseAt = data.closes_at ? new Date(data.closes_at) : null;
|
|
|
|
|
updateRoundTimer();
|
2026-07-21 16:03:42 +02:00
|
|
|
|
|
|
|
|
const isDrawing = data.round_id && DRAWING_STATUSES.includes(data.status);
|
|
|
|
|
|
|
|
|
|
if (isDrawing) {
|
|
|
|
|
if (!(data.round_id in drawStartedAt)) drawStartedAt[data.round_id] = Date.now();
|
|
|
|
|
const elapsedMs = Date.now() - drawStartedAt[data.round_id];
|
|
|
|
|
const minMs = data.draw_animation_seconds * 1000;
|
|
|
|
|
|
|
|
|
|
if (data.winner_user_id != null && elapsedMs >= minMs && !revealedRounds.has(data.round_id)) {
|
|
|
|
|
revealedRounds.add(data.round_id);
|
|
|
|
|
activeResultRoundId = data.round_id;
|
|
|
|
|
if (myUserId != null && data.winner_user_id === myUserId) {
|
|
|
|
|
const won = (data.winner_amount_sats / SATS_PER_PLM);
|
|
|
|
|
showResultState('🎉 Hai vinto! +' + won + ' PLM', 'win');
|
|
|
|
|
toast('Hai vinto il round #' + data.round_id + '! +' + won + ' PLM', 'success');
|
|
|
|
|
} else {
|
|
|
|
|
showResultState('Non hai vinto questa volta.', 'lose');
|
|
|
|
|
}
|
|
|
|
|
} else if (!revealedRounds.has(data.round_id)) {
|
|
|
|
|
showDrawingState();
|
|
|
|
|
}
|
|
|
|
|
} else if (data.round_id && data.round_id !== activeResultRoundId) {
|
|
|
|
|
// a genuinely new round is open — clear any previous result and go back to normal
|
|
|
|
|
activeResultRoundId = null;
|
|
|
|
|
showNormalState();
|
|
|
|
|
} else if (!data.round_id && activeResultRoundId == null) {
|
|
|
|
|
// nothing has ever been revealed and there's no active round — plain empty state
|
|
|
|
|
showNormalState();
|
|
|
|
|
}
|
|
|
|
|
// else: no active round right now, but we just revealed a result for the last
|
|
|
|
|
// one — keep it on screen through the cooldown gap instead of flashing back to
|
|
|
|
|
// "Nessun round attivo".
|
|
|
|
|
|
|
|
|
|
scheduleNextRoundPoll(isDrawing);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
scheduleNextRoundPoll(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scheduleNextRoundPoll(fast) {
|
|
|
|
|
clearTimeout(roundPollTimeout);
|
|
|
|
|
roundPollTimeout = setTimeout(refreshRound, fast ? 3000 : 15000);
|
2026-07-21 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:27:05 +02:00
|
|
|
function showDashboard() {
|
|
|
|
|
document.getElementById('auth-section').classList.add('hidden');
|
|
|
|
|
document.getElementById('dashboard-section').classList.remove('hidden');
|
|
|
|
|
document.getElementById('dash-username').textContent = username;
|
|
|
|
|
document.getElementById('dash-address').textContent = address;
|
2026-07-21 10:52:06 +02:00
|
|
|
document.getElementById('dash-qr').src = '/qr/' + encodeURIComponent(address);
|
2026-07-21 10:27:05 +02:00
|
|
|
refreshMe();
|
2026-07-21 10:57:39 +02:00
|
|
|
refreshRound();
|
|
|
|
|
clearInterval(roundTimerInterval);
|
|
|
|
|
roundTimerInterval = setInterval(updateRoundTimer, 1000);
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
function persistSession(data, u) {
|
2026-07-21 10:27:05 +02:00
|
|
|
token = data.access_token; username = u; address = data.address;
|
|
|
|
|
localStorage.setItem('plm_token', token);
|
|
|
|
|
localStorage.setItem('plm_username', username);
|
|
|
|
|
localStorage.setItem('plm_address', address);
|
2026-07-21 10:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function register() {
|
|
|
|
|
const btn = document.getElementById('register-btn');
|
|
|
|
|
const u = document.getElementById('reg-username').value;
|
|
|
|
|
const p = document.getElementById('reg-password').value;
|
2026-07-21 14:22:03 +02:00
|
|
|
const pConfirm = document.getElementById('reg-password-confirm').value;
|
|
|
|
|
if (p !== pConfirm) {
|
|
|
|
|
toast('Le password non coincidono.', 'error');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-21 10:46:55 +02:00
|
|
|
await withLoading(btn, 'Creazione…', async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await call('POST', '/auth/register', { username: u, password: p });
|
|
|
|
|
persistSession(data, u);
|
|
|
|
|
toast('Account creato.', 'success');
|
|
|
|
|
showDashboard();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast(e.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function login() {
|
2026-07-21 10:46:55 +02:00
|
|
|
const btn = document.getElementById('login-btn');
|
2026-07-21 10:27:05 +02:00
|
|
|
const u = document.getElementById('login-username').value;
|
|
|
|
|
const p = document.getElementById('login-password').value;
|
2026-07-21 10:46:55 +02:00
|
|
|
await withLoading(btn, 'Accesso…', async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await call('POST', '/auth/login', { username: u, password: p });
|
|
|
|
|
persistSession(data, u);
|
|
|
|
|
toast('Accesso riuscito.', 'success');
|
|
|
|
|
showDashboard();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast(e.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function logout() {
|
|
|
|
|
localStorage.clear();
|
|
|
|
|
token = username = address = null;
|
2026-07-21 16:03:42 +02:00
|
|
|
myUserId = null;
|
|
|
|
|
activeResultRoundId = null;
|
|
|
|
|
revealedRounds.clear();
|
|
|
|
|
for (const key of Object.keys(drawStartedAt)) delete drawStartedAt[key];
|
2026-07-21 10:57:39 +02:00
|
|
|
clearInterval(roundTimerInterval);
|
2026-07-21 16:03:42 +02:00
|
|
|
clearTimeout(roundPollTimeout);
|
2026-07-21 10:27:05 +02:00
|
|
|
document.getElementById('dashboard-section').classList.add('hidden');
|
|
|
|
|
document.getElementById('auth-section').classList.remove('hidden');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-21 10:46:55 +02:00
|
|
|
async function copyAddress() {
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(address);
|
|
|
|
|
toast('Indirizzo copiato.', 'success');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast('Impossibile copiare automaticamente.', 'error');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-21 10:38:26 +02:00
|
|
|
|
2026-07-21 16:03:42 +02:00
|
|
|
let myUserId = null;
|
|
|
|
|
|
2026-07-21 10:27:05 +02:00
|
|
|
async function refreshMe() {
|
2026-07-21 10:46:55 +02:00
|
|
|
const btn = document.getElementById('refresh-btn');
|
|
|
|
|
await withLoading(btn, '…', async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await call('GET', '/users/me');
|
2026-07-21 16:03:42 +02:00
|
|
|
myUserId = data.id;
|
2026-07-21 10:46:55 +02:00
|
|
|
document.getElementById('dash-balance').textContent = data.balance_sats / SATS_PER_PLM;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast(e.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function placeBet() {
|
2026-07-21 10:46:55 +02:00
|
|
|
const btn = document.getElementById('bet-btn');
|
|
|
|
|
await withLoading(btn, 'Invio bet…', async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await call('POST', '/bets', {});
|
|
|
|
|
toast('Bet piazzata sul round #' + data.round_id + '.', 'success');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast(e.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-21 10:27:05 +02:00
|
|
|
refreshMe();
|
2026-07-21 10:57:39 +02:00
|
|
|
refreshRound();
|
2026-07-21 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function withdraw() {
|
2026-07-21 10:46:55 +02:00
|
|
|
const btn = document.getElementById('withdraw-btn');
|
2026-07-21 10:27:05 +02:00
|
|
|
const ext = document.getElementById('wd-address').value;
|
2026-07-21 10:38:26 +02:00
|
|
|
const amtPlm = parseFloat(document.getElementById('wd-amount').value);
|
|
|
|
|
const amtSats = Math.round(amtPlm * SATS_PER_PLM);
|
2026-07-21 10:46:55 +02:00
|
|
|
await withLoading(btn, 'Invio…', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await call('POST', '/withdrawals', { external_address: ext, amount_sats: amtSats });
|
|
|
|
|
toast('Withdrawal inviato.', 'success');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast(e.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-07-21 10:27:05 +02:00
|
|
|
refreshMe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token) showDashboard();
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|