A7: player area - play, wallet, movements (WEB-03, WEB-05, WEB-20..27)

Gioca: the round, the player's funds and their bet; the bet is two steps
(a confirmation screen that sends nothing, then an explicit confirm) with a
fresh idempotency key per screen, and the server re-checks everything.
Portafoglio: spendable apart from in-confirmation, deposit address with a QR
of the player's own address, copy button, simulated test deposits.
Movimenti: the player's own ledger, paged, stacked as cards on a phone.
GET /app/stato/ feeds the page and its polling. Every view takes the user from
the session only. Checked end to end in a real browser (Playwright): status
moves from pending to confirmed without a reload, a double click is one bet.
Mutation checks: cross-account leak, non-idempotent POST and unrestricted
test-deposit amounts are all caught.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 14:41:27 +01:00
1 parent 939c113043
commit 42e5e33371
21 files changed
+1192 -48

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
{# The state of the round, shared by the public home and the play screen. `s` = public_state, `poll_url` = what the page polls. #}
<section id="round-card" class="card round-card" data-state="{{ s.state }}" data-poll-url="{{ poll_url }}"
data-server-now="{{ s.server_now }}" data-closes-at="{{ s.closes_at|default:'' }}" aria-labelledby="round-state">
<p class="state-label" id="round-state" data-field="label" aria-live="polite">{{ s.label }}</p>
<p class="state-message" data-field="message">{{ s.message }}</p>
<p class="countdown"{% if s.seconds_left is None %} hidden{% endif %} data-field="countdown-line">
Chiude fra <strong class="clock" data-field="countdown">{{ s.countdown_text|default:'00:00' }}</strong>
<span class="hint">(ora del server)</span>
</p>
<dl class="stats">
<div><dt>Quota</dt><dd data-field="bet_amount_text">{{ s.bet_amount_text }}</dd></div>
<div><dt>Montepremi confermato</dt><dd data-field="jackpot_text">{{ s.jackpot_text }}</dd></div>
<div><dt>Giocatori</dt><dd><span data-field="confirmed_players">{{ s.confirmed_players }}</span>
<span class="hint" data-field="pending"{% if not s.pending_players %} hidden{% endif %}>+<span data-field="pending_players">{{ s.pending_players }}</span> in conferma</span></dd></div>
</dl>
{% if show_participate %}
<p class="actions"{% if not s.can_participate %} hidden{% endif %} data-field="participate-line">
<a class="button big" href="{% url 'web:app-home' %}" data-field="participate">Partecipa</a>
</p>
{% endif %}
<p class="hint" data-field="connection" role="status" hidden>Connessione persa: i dati potrebbero non essere aggiornati. Riprovo…</p>
<noscript><p class="hint">Senza JavaScript la pagina non si aggiorna da sola: ricaricala per vedere lo stato più recente.</p></noscript>
</section>
+25 -2
View File
@@ -1,6 +1,29 @@
{% extends "web/base.html" %}
{% load static %}
{% block title %}Gioca · PLM Lottery{% endblock %}
{% block head %}<script src="{% static 'web/home.js' %}" defer></script>{% endblock %}
{% block content %}
<h1>Area giocatore</h1>
<p>Ciao {{ user.get_username }}. La schermata di gioco è in costruzione.</p>
<h1>Gioca</h1>
{% include "web/_round_card.html" with poll_url=poll_url show_participate=False %}
<section class="card" aria-labelledby="your-bet">
<h2 id="your-bet">La tua puntata</h2>
<dl class="stats">
<div><dt>Saldo spendibile</dt><dd data-me="spendable_text">{{ me.spendable_text }}</dd></div>
<div data-me="incoming-line"{% if not me.incoming_sats %} hidden{% endif %}><dt>In conferma</dt><dd data-me="incoming_text">{{ me.incoming_text }}</dd></div>
</dl>
<div data-me="participation-box" class="status-box"{% if not me.participation %} hidden{% endif %}>
<p class="badge" data-me="participation_label" data-status="{{ me.participation.status }}">{{ me.participation.label }}</p>
<p data-me="participation_message">{{ me.participation.message }}</p>
</div>
<p class="actions" data-me="bet-form"{% if not me.can_bet %} hidden{% endif %}>
<a class="button big" href="{% url 'web:bet' %}">Punta {{ s.bet_amount_text }}</a>
</p>
<p class="hint" data-me="bet_blocker"{% if not me.bet_blocker %} hidden{% endif %}>{{ me.bet_blocker }}</p>
{% if not me.can_bet and not me.participation and not me.bet_blocker %}<p class="hint" data-me="idle"></p>{% endif %}
<p class="result" data-me="last_result"{% if not me.last_result %} hidden{% endif %}>{{ me.last_result }}</p>
</section>
{% endblock %}
+6 -2
View File
@@ -16,8 +16,12 @@
<nav class="nav" aria-label="Principale">
<a href="{% url 'web:home' %}">Home</a>
{% if user.is_authenticated %}
<a href="{% url 'web:app-home' %}">Gioca</a>
<a href="{% url 'accounts:profile' %}">Profilo</a>
{% with current=request.resolver_match.view_name %}
<a href="{% url 'web:app-home' %}"{% if current == 'web:app-home' or current == 'web:bet' %} aria-current="page"{% endif %}>Gioca</a>
<a href="{% url 'web:wallet' %}"{% if current == 'web:wallet' %} aria-current="page"{% endif %}>Portafoglio</a>
<a href="{% url 'web:movements' %}"{% if current == 'web:movements' %} aria-current="page"{% endif %}>Movimenti</a>
<a href="{% url 'accounts:profile' %}"{% if current == 'accounts:profile' %} aria-current="page"{% endif %}>Profilo</a>
{% endwith %}
<form class="inline" method="post" action="{% url 'accounts:logout' %}">
{% csrf_token %}
<button class="link-button" type="submit">Esci ({{ user.get_username }})</button>
+21
View File
@@ -0,0 +1,21 @@
{% extends "web/base.html" %}
{% block title %}Conferma la puntata · PLM Lottery{% endblock %}
{% block content %}
<h1>Conferma la puntata</h1>
<section class="card narrow">
<dl class="facts">
<dt>Round</dt><dd>{{ s.round_id }}</dd>
<dt>Importo</dt><dd><strong>{{ s.bet_amount_text }}</strong></dd>
<dt>Il round chiude alle</dt><dd>{{ s.closes_at_text }}</dd>
<dt>Saldo spendibile</dt><dd>{{ me.spendable_text }}</dd>
</dl>
<p class="hint">La puntata verrà addebitata subito e partecipa all'estrazione appena confermata. Il montepremi si divide 70% al vincitore e 30% alla piattaforma.</p>
<form method="post" action="{% url 'web:bet' %}">
{% csrf_token %}
<input type="hidden" name="round_id" value="{{ s.round_id }}">
<input type="hidden" name="request_id" value="{{ request_id }}">
<button class="button big" type="submit">Conferma e punta {{ s.bet_amount_text }}</button>
<a class="button secondary big" href="{% url 'web:app-home' %}">Annulla</a>
</form>
</section>
{% endblock %}
+2 -23
View File
@@ -5,27 +5,6 @@
<h1>PLM Lottery</h1>
<p class="lead">Una lotteria a round: ogni giocatore punta la stessa quota, si estrae un vincitore, il montepremi si divide 70% a lui e 30% alla piattaforma.</p>
<section id="round-card" class="card round-card" data-state="{{ s.state }}" data-poll-url="{% url 'web:state' %}"
data-server-now="{{ s.server_now }}" data-closes-at="{{ s.closes_at|default:'' }}" aria-labelledby="round-state">
<p class="state-label" id="round-state" data-field="label" aria-live="polite">{{ s.label }}</p>
<p class="state-message" data-field="message">{{ s.message }}</p>
<p class="countdown"{% if s.seconds_left is None %} hidden{% endif %} data-field="countdown-line">
Chiude fra <strong class="clock" data-field="countdown">{{ s.countdown_text|default:'00:00' }}</strong>
<span class="hint">(ora del server)</span>
</p>
<dl class="stats">
<div><dt>Quota</dt><dd data-field="bet_amount_text">{{ s.bet_amount_text }}</dd></div>
<div><dt>Montepremi confermato</dt><dd data-field="jackpot_text">{{ s.jackpot_text }}</dd></div>
<div><dt>Giocatori</dt><dd><span data-field="confirmed_players">{{ s.confirmed_players }}</span>
<span class="hint" data-field="pending"{% if not s.pending_players %} hidden{% endif %}>+<span data-field="pending_players">{{ s.pending_players }}</span> in conferma</span></dd></div>
</dl>
<p class="actions"{% if not s.can_participate %} hidden{% endif %} data-field="participate-line">
<a class="button big" href="{% url 'web:app-home' %}" data-field="participate">Partecipa</a>
</p>
<p class="hint" data-field="connection" role="status" hidden>Connessione persa: i dati potrebbero non essere aggiornati. Riprovo…</p>
<noscript><p class="hint">Senza JavaScript la pagina non si aggiorna da sola: ricaricala per vedere lo stato più recente.</p></noscript>
</section>
{% url 'web:state' as poll_url %}
{% include "web/_round_card.html" with poll_url=poll_url show_participate=True %}
{% endblock %}
+33
View File
@@ -0,0 +1,33 @@
{% extends "web/base.html" %}
{% block title %}Movimenti · PLM Lottery{% endblock %}
{% block content %}
<h1>Movimenti</h1>
{% if rows %}
<div class="table-wrap">
<table class="movements">
<caption class="visually-hidden">I tuoi movimenti, dal più recente</caption>
<thead><tr><th scope="col">Data (UTC)</th><th scope="col">Operazione</th><th scope="col">Stato</th><th scope="col" class="num">Importo</th><th scope="col">Transazione</th></tr></thead>
<tbody>
{% for row in rows %}
<tr>
<td data-label="Data (UTC)"><time datetime="{{ row.when|date:'c' }}">{{ row.when|date:"d/m/Y H:i:s" }}</time></td>
<td data-label="Operazione">{{ row.kind }}{% if row.round_id %} <span class="hint">round {{ row.round_id }}</span>{% endif %}</td>
<td data-label="Stato"><span class="badge" data-status="{{ row.status_code }}">{{ row.status }}</span></td>
<td data-label="Importo" class="num {% if row.credit %}credit{% else %}debit{% endif %}">{{ row.amount_text }}</td>
<td data-label="Transazione">{% if row.txid %}{% if row.txid_url %}<a href="{{ row.txid_url }}" rel="noopener" title="{{ row.txid }}">{{ row.txid_short }}</a>{% else %}<span title="{{ row.txid }}">{{ row.txid_short }}</span>{% endif %}{% if row.simulated %} <span class="hint">(simulata)</span>{% endif %}{% else %}<span class="hint">—</span>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if page.paginator.num_pages > 1 %}
<nav class="pager" aria-label="Pagine dei movimenti">
{% if page.has_previous %}<a class="button secondary small" href="?pagina={{ page.previous_page_number }}">← Più recenti</a>{% endif %}
<span class="hint">Pagina {{ page.number }} di {{ page.paginator.num_pages }}</span>
{% if page.has_next %}<a class="button secondary small" href="?pagina={{ page.next_page_number }}">Meno recenti →</a>{% endif %}
</nav>
{% endif %}
{% else %}
<p class="card">Non ci sono ancora movimenti. Deposita dal <a href="{% url 'web:wallet' %}">portafoglio</a> per iniziare.</p>
{% endif %}
{% endblock %}
+66
View File
@@ -0,0 +1,66 @@
{% extends "web/base.html" %}
{% load static %}
{% block title %}Portafoglio · PLM Lottery{% endblock %}
{% block head %}<script src="{% static 'web/wallet.js' %}" defer></script>{% endblock %}
{% block content %}
<h1>Portafoglio</h1>
<section class="card">
<h2>Il tuo saldo</h2>
<dl class="stats">
<div><dt>Spendibile</dt><dd>{{ spendable_text }}</dd></div>
<div><dt>In conferma</dt><dd>{{ incoming_text }}</dd></div>
</dl>
<p class="hint">Il saldo spendibile è quello che puoi usare subito per puntare. I fondi in conferma si aggiungono quando la rete li conferma.</p>
{% if pending_deposits %}
<h3>Depositi in conferma</h3>
<ul class="plain">
{% for deposit in pending_deposits %}<li>{{ deposit.amount_text }} · ricevuto alle {{ deposit.since|time:"H:i:s" }} UTC</li>{% endfor %}
</ul>
{% endif %}
</section>
<section class="card" aria-labelledby="deposit">
<h2 id="deposit">Deposita</h2>
<dl class="facts">
<dt>Rete</dt><dd>{{ network_label }}</dd>
<dt>Indirizzo</dt>
<dd>
<div class="copy-row">
<input id="deposit-address" class="address" type="text" readonly value="{{ address }}" aria-label="Il tuo indirizzo di deposito">
<button class="button secondary small" type="button" data-copy-target="deposit-address" hidden>Copia</button>
</div>
<p class="hint" data-copy-status role="status" hidden></p>
</dd>
</dl>
<img class="qr" src="{% url 'web:wallet-qr' %}" width="200" height="200" alt="QR code del tuo indirizzo di deposito">
{% if simulated %}
<p class="hint">Questo è un indirizzo simulato: in prova nessuna moneta reale si muove.</p>
{% else %}
<p class="hint">Invia solo PLM a questo indirizzo. Il deposito è spendibile dopo le conferme richieste.</p>
{% endif %}
</section>
{% if simulated %}
<section class="card narrow" aria-labelledby="test-deposit">
<h2 id="test-deposit">Fondi di prova</h2>
<p class="hint">Solo in prova: ricevi un deposito simulato che arriva «in conferma» e diventa spendibile pochi secondi dopo.</p>
<form method="post" action="{% url 'web:simulated-deposit' %}">
{% csrf_token %}
<input type="hidden" name="request_id" value="{{ request_id }}">
<div class="field">
<label for="test-amount">Importo</label>
<select id="test-amount" name="amount">
{% for option in simulated_amounts %}<option value="{{ option.plm }}">{{ option.text }}</option>{% endfor %}
</select>
</div>
<button class="button" type="submit">Ricevi fondi di prova</button>
</form>
</section>
{% endif %}
<section class="card">
<h2>Prelievo</h2>
<p class="hint">Il prelievo verso un indirizzo esterno sarà disponibile con l'integrazione della rete.</p>
</section>
{% endblock %}