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:
1 parent
939c113043
commit
42e5e33371
21 files changed
+1192
-48
No files matched your search
@@ -0,0 +1,176 @@
|
||||
"""The player area (WEB-20 .. WEB-27, roadmap A7). Every view needs a session and reads or changes only the
|
||||
signed-in player's own data (WEB-03): no view takes a user id from the request."""
|
||||
|
||||
import io
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import qrcode
|
||||
import qrcode.image.svg
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.http import Http404, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from apps.lottery.addresses import participant_address
|
||||
from apps.lottery.balances import balance_of
|
||||
from apps.lottery.errors import LedgerError
|
||||
from apps.lottery.format import plm_text
|
||||
from apps.lottery.ledger import get_ledger
|
||||
from apps.lottery.messages import ledger_error_text
|
||||
from apps.lottery.models import SATS_PER_PLM, Movement
|
||||
from apps.lottery.player import full_state, player_state
|
||||
from apps.lottery.status import public_state
|
||||
|
||||
# The test deposits a player can ask for on the simulated ledger (WEB-26): fixed, so a tampered form gets nothing else.
|
||||
SIMULATED_DEPOSITS_PLM = (10, 50, 100)
|
||||
|
||||
KIND_LABELS = {"deposit": "Deposito", "bet": "Puntata", "win": "Vincita", "refund": "Rimborso", "withdrawal": "Prelievo"}
|
||||
STATUS_LABELS = {"pending": "In conferma", "confirmed": "Confermato", "failed": "Non riuscito"}
|
||||
MOVEMENTS_PER_PAGE = 25
|
||||
|
||||
|
||||
def _uuid(value: str | None) -> UUID | None:
|
||||
try:
|
||||
return UUID(value or "")
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
# --- play --------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def play(request):
|
||||
"""«Gioca»: the round, the player's funds and their bet in it (WEB-20)."""
|
||||
state = full_state(request.user)
|
||||
return render(request, "web/app_home.html", {"s": state, "me": state["me"], "poll_url": "/app/stato/"})
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def player_state_json(request):
|
||||
"""The same, as JSON, for the page to poll (WEB-05, WEB-27): the player's own data only."""
|
||||
return JsonResponse(full_state(request.user))
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def bet(request):
|
||||
"""The bet in two steps (WEB-22): GET shows round and amount and asks for an explicit confirmation; POST sends
|
||||
it. The server decides — round, deadline, quota, limits and funds are all checked again in the ledger — and
|
||||
the request carries its own idempotency key, so a double send is one bet (WEB-23)."""
|
||||
public = public_state()
|
||||
if request.method == "POST":
|
||||
round_id = request.POST.get("round_id", "")
|
||||
request_id = _uuid(request.POST.get("request_id"))
|
||||
if not round_id.isdigit() or request_id is None:
|
||||
messages.error(request, ledger_error_text("missing_request_id", {}))
|
||||
return redirect("web:app-home")
|
||||
try:
|
||||
result = get_ledger().place_bet(request.user, int(round_id), request_id=request_id)
|
||||
except LedgerError as error:
|
||||
messages.error(request, ledger_error_text(error.code, error.params))
|
||||
return redirect("web:app-home")
|
||||
if result.replayed:
|
||||
messages.info(request, "Questa puntata era già stata registrata: non è stata addebitata due volte.")
|
||||
else:
|
||||
messages.success(request, "Puntata inviata: è in attesa di conferma.")
|
||||
return redirect("web:app-home")
|
||||
|
||||
me = player_state(request.user, public=public)
|
||||
if not me["can_bet"]:
|
||||
if me["participation"] is not None:
|
||||
text = ledger_error_text("already_betting", {})
|
||||
else:
|
||||
text = me["bet_blocker"] or ledger_error_text("round_closing", {})
|
||||
messages.error(request, text)
|
||||
return redirect("web:app-home")
|
||||
return render(request, "web/bet_confirm.html", {"s": public, "me": me, "request_id": uuid4()})
|
||||
|
||||
|
||||
# --- wallet ------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _network_label() -> str:
|
||||
return {"regtest": "PLM regtest (rete di prova)", "mainnet": "PLM mainnet"}[settings.PLM_NETWORK]
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def wallet(request):
|
||||
"""«Portafoglio»: spendable funds apart from funds in confirmation, and where to deposit (WEB-21)."""
|
||||
balance = balance_of(request.user)
|
||||
pending = Movement.objects.filter(user=request.user, kind="deposit", status="pending").order_by("-created_at")
|
||||
context = {
|
||||
"spendable_text": plm_text(balance.spendable_sats), "incoming_text": plm_text(balance.incoming_sats),
|
||||
"pending_deposits": [{"amount_text": plm_text(m.amount_sats), "since": m.created_at} for m in pending],
|
||||
"address": participant_address(request.user), "network_label": _network_label(),
|
||||
"simulated": settings.LEDGER_BACKEND == "simulated",
|
||||
"simulated_amounts": [{"plm": n, "text": plm_text(n * SATS_PER_PLM)} for n in SIMULATED_DEPOSITS_PLM],
|
||||
"request_id": uuid4(),
|
||||
}
|
||||
return render(request, "web/wallet.html", context)
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def wallet_qr(request):
|
||||
"""The QR of the player's own deposit address — never an address taken from the request (WEB-03, WEB-21)."""
|
||||
image = qrcode.make(participant_address(request.user), image_factory=qrcode.image.svg.SvgPathImage, box_size=10)
|
||||
buffer = io.BytesIO()
|
||||
image.save(buffer)
|
||||
return HttpResponse(buffer.getvalue(), content_type="image/svg+xml")
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
@require_POST
|
||||
def simulated_deposit(request):
|
||||
"""Test funds for the simulated ledger (WEB-26): they arrive «in conferma» and the worker confirms them a few
|
||||
seconds later, so the whole path can be seen. Not available when the ledger is real."""
|
||||
if settings.LEDGER_BACKEND != "simulated":
|
||||
raise Http404
|
||||
request_id = _uuid(request.POST.get("request_id"))
|
||||
amount = request.POST.get("amount", "")
|
||||
if request_id is None or not amount.isdigit() or int(amount) not in SIMULATED_DEPOSITS_PLM:
|
||||
messages.error(request, "La richiesta di deposito non è valida.")
|
||||
return redirect("web:wallet")
|
||||
try:
|
||||
result = get_ledger().deposit(request.user, int(amount) * SATS_PER_PLM, request_id=request_id, confirmed=False)
|
||||
except LedgerError as error:
|
||||
messages.error(request, ledger_error_text(error.code, error.params))
|
||||
return redirect("web:wallet")
|
||||
if result.replayed:
|
||||
messages.info(request, "Questo deposito era già stato registrato.")
|
||||
else:
|
||||
messages.success(request, f"Deposito di prova di {plm_text(int(amount) * SATS_PER_PLM)} in conferma.")
|
||||
return redirect("web:wallet")
|
||||
|
||||
|
||||
# --- history -----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def movements(request):
|
||||
"""«Movimenti»: deposits, bets, wins and withdrawals of this player, newest first (WEB-25)."""
|
||||
queryset = (Movement.objects.filter(user=request.user).select_related("chain_transaction")
|
||||
.order_by("-created_at", "-id"))
|
||||
page = Paginator(queryset, MOVEMENTS_PER_PAGE).get_page(request.GET.get("pagina"))
|
||||
rows = []
|
||||
for movement in page:
|
||||
txid = movement.chain_transaction.current_txid if movement.chain_transaction_id else None
|
||||
rows.append({
|
||||
"when": movement.created_at, "kind": KIND_LABELS[movement.kind], "status": STATUS_LABELS[movement.status],
|
||||
"status_code": movement.status, "amount_text": ("+" if movement.amount_sats > 0 else "") + plm_text(movement.amount_sats),
|
||||
"credit": movement.amount_sats > 0, "round_id": movement.round_id,
|
||||
"txid": txid, "txid_short": f"{txid[:10]}…{txid[-6:]}" if txid else "",
|
||||
"txid_url": settings.EXPLORER_TX_URL.replace("{txid}", txid) if txid and settings.EXPLORER_TX_URL else "",
|
||||
"simulated": bool(txid) and settings.LEDGER_BACKEND == "simulated",
|
||||
})
|
||||
return render(request, "web/movements.html", {"rows": rows, "page": page})
|
||||
@@ -36,7 +36,30 @@ if (typeof document !== "undefined") {
|
||||
const setText = (name, value) => { const el = field(name); if (el && el.textContent !== String(value)) el.textContent = value; };
|
||||
const setHidden = (name, hidden) => { const el = field(name); if (el) el.hidden = hidden; };
|
||||
|
||||
const me = (name) => document.querySelector(`[data-me="${name}"]`);
|
||||
const setMe = (name, value) => { const el = me(name); if (el && el.textContent !== String(value)) el.textContent = value; };
|
||||
const hideMe = (name, hidden) => { const el = me(name); if (el) el.hidden = hidden; };
|
||||
|
||||
/* The player's own block (play screen only): funds, the bet's status, whether a bet can be placed. */
|
||||
function renderMe(m) {
|
||||
setMe("spendable_text", m.spendable_text);
|
||||
setMe("incoming_text", m.incoming_text);
|
||||
hideMe("incoming-line", !m.incoming_sats);
|
||||
const p = m.participation;
|
||||
hideMe("participation-box", !p);
|
||||
setMe("participation_label", p ? p.label : "");
|
||||
const badge = me("participation_label");
|
||||
if (badge) badge.dataset.status = p ? p.status : "";
|
||||
setMe("participation_message", p ? p.message : "");
|
||||
hideMe("bet-form", !m.can_bet);
|
||||
setMe("bet_blocker", m.bet_blocker);
|
||||
hideMe("bet_blocker", !m.bet_blocker);
|
||||
setMe("last_result", m.last_result);
|
||||
hideMe("last_result", !m.last_result);
|
||||
}
|
||||
|
||||
function render(s) {
|
||||
if (s.me) renderMe(s.me);
|
||||
card.dataset.state = s.state;
|
||||
offsetMs = serverOffsetMs(s.server_now, Date.now());
|
||||
closesAt = s.closes_at || "";
|
||||
|
||||
@@ -87,3 +87,38 @@ input[type=text], input[type=password] { width: 100%; min-height: 2.75rem; paddi
|
||||
.stats dd .hint { font-size: .85rem; font-weight: 400; }
|
||||
.actions { margin: 0; }
|
||||
.button.big { min-height: 3.25rem; padding-inline: 2.2rem; font-size: 1.15rem; }
|
||||
|
||||
/* Player area (WEB-20 .. WEB-27) */
|
||||
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
||||
.nav a[aria-current="page"] { font-weight: 700; border-bottom: 2px solid var(--accent); }
|
||||
.message.info { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
|
||||
.status-box { margin: 0 0 1rem; }
|
||||
.badge { display: inline-block; margin: 0 0 .4rem; padding: .15rem .7rem; border-radius: 999px; font-size: .9rem; font-weight: 600;
|
||||
background: var(--bg); border: 1px solid var(--line); color: var(--text); }
|
||||
.badge[data-status="confirmed"] { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
|
||||
.badge[data-status="pending"] { border-color: var(--accent); color: var(--accent); }
|
||||
.badge[data-status="rejected"], .badge[data-status="excluded"], .badge[data-status="failed"] { background: var(--error-bg); color: var(--error); border-color: var(--error); }
|
||||
.result { font-weight: 600; margin: 1rem 0 0; }
|
||||
select { min-height: 2.75rem; padding: .5rem .75rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
|
||||
.copy-row { display: flex; gap: .5rem; align-items: stretch; flex-wrap: wrap; }
|
||||
.address { flex: 1 1 14rem; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }
|
||||
input[type=text].address { width: auto; }
|
||||
.qr { display: block; margin: 1rem 0; background: #fff; padding: .5rem; border-radius: 8px; max-width: 100%; height: auto; }
|
||||
.plain { list-style: none; padding: 0; margin: 0; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.movements { width: 100%; border-collapse: collapse; background: var(--surface); }
|
||||
.movements th, .movements td { padding: .6rem .7rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
|
||||
.movements .num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.credit { color: var(--ok); } .debit { color: var(--text); }
|
||||
.pager { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; margin-block: 1rem; }
|
||||
.button.secondary.big { margin-left: .5rem; }
|
||||
|
||||
/* On a phone the movements are stacked cards, so the amount is never scrolled out of sight. */
|
||||
@media (max-width: 40rem) {
|
||||
.movements, .movements tbody, .movements tr, .movements td { display: block; width: 100%; }
|
||||
.movements thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
|
||||
.movements tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .8rem; padding: .3rem .8rem; }
|
||||
.movements td { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border: 0; white-space: normal; text-align: right; }
|
||||
.movements td::before { content: attr(data-label); color: var(--muted); font-size: .9rem; text-align: left; }
|
||||
.movements td.num { text-align: right; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* The wallet's «Copia» button (WEB-21). Without JavaScript the address is a read-only field the visitor can select
|
||||
and copy; with it, a button appears that copies it and says so. No dependencies, no inline code. */
|
||||
|
||||
function copyText(text, clipboard) {
|
||||
if (clipboard && typeof clipboard.writeText === "function") return clipboard.writeText(text);
|
||||
return Promise.reject(new Error("clipboard unavailable"));
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined") module.exports = { copyText };
|
||||
|
||||
if (typeof document !== "undefined") {
|
||||
document.querySelectorAll("[data-copy-target]").forEach((button) => {
|
||||
const input = document.getElementById(button.dataset.copyTarget);
|
||||
const status = document.querySelector("[data-copy-status]");
|
||||
if (!input) return;
|
||||
button.hidden = false;
|
||||
button.addEventListener("click", async () => {
|
||||
let message = "Indirizzo copiato.";
|
||||
try {
|
||||
await copyText(input.value, navigator.clipboard);
|
||||
} catch (error) {
|
||||
input.select(); // the clipboard is not available here: leave the address selected for the visitor to copy
|
||||
message = "Non riesco a copiare da solo: l'indirizzo è selezionato, copialo a mano.";
|
||||
}
|
||||
if (status) { status.textContent = message; status.hidden = false; }
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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 %}
|
||||
@@ -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>
|
||||
|
||||
@@ -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 %}
|
||||
@@ -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 %}
|
||||
@@ -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 %}
|
||||
@@ -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 %}
|
||||
+8
-2
@@ -1,11 +1,17 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
from . import player_views, views
|
||||
|
||||
app_name = "web"
|
||||
urlpatterns = [
|
||||
path("", views.home, name="home"),
|
||||
path("stato/", views.state, name="state"),
|
||||
path("app/", views.app_home, name="app-home"),
|
||||
path("app/", player_views.play, name="app-home"),
|
||||
path("app/stato/", player_views.player_state_json, name="player-state"),
|
||||
path("app/punta/", player_views.bet, name="bet"),
|
||||
path("app/portafoglio/", player_views.wallet, name="wallet"),
|
||||
path("app/portafoglio/qr.svg", player_views.wallet_qr, name="wallet-qr"),
|
||||
path("app/portafoglio/deposito-prova/", player_views.simulated_deposit, name="simulated-deposit"),
|
||||
path("app/movimenti/", player_views.movements, name="movements"),
|
||||
path("health/live", views.health_live, name="health-live"),
|
||||
]
|
||||
@@ -1,4 +1,3 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import connection
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
@@ -20,13 +19,6 @@ def state(request):
|
||||
return JsonResponse(public_state())
|
||||
|
||||
|
||||
@never_cache
|
||||
@login_required
|
||||
def app_home(request):
|
||||
"""Placeholder of the player area (WEB-20): the play screen arrives with A7."""
|
||||
return render(request, "web/app_home.html")
|
||||
|
||||
|
||||
def health_live(request):
|
||||
"""Liveness for the container healthcheck: the process answers and the database opens (ARC-73)."""
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user