This commit is contained in:
2026-06-08 02:48:24 -04:00
parent 95dfc02e82
commit bf3e72f3ce
4 changed files with 66 additions and 46 deletions

View File

@@ -51,17 +51,18 @@ function cry01_render_landing($association_slug, $access) {
// ---------------------------------------------------------------------------
function cry01_render_balance_display() {
// Renders the operator Ğ1 balance from cache. Shows staleness if cache is old.
$cache = cry01_read_cache();
$balance = $cache['operator_balance'] ?? null;
$pubkey = $cache['operator_g1_pubkey'] ?? '';
// Renders the Ğ1 balance from cache. The cached key belongs to whoever last refreshed.
// Shows staleness if cache is old.
$cache = cry01_read_cache();
$balance = $cache['balance'] ?? null;
$pubkey = $cache['g1_pubkey'] ?? '';
$refreshed = $cache['refreshed_at'] ?? null;
$out = '<div class="cry01-balance-display mb-4">';
$out .= '<h5 class="cry01-section-label">Operator Ğ1 Balance</h5>';
$out .= '<h5 class="cry01-section-label">Ğ1 Balance</h5>';
if ($balance === null) {
$out .= '<p class="text-muted fst-italic">Balance not yet loaded. Operator: use Manage to refresh.</p>';
$out .= '<p class="text-muted fst-italic">Balance not yet loaded. Unlock your Ğ1 wallet and use Manage to refresh.</p>';
} else {
$out .= '<p class="cry01-balance-amount">' . cry01_h($balance) . '</p>';
if ($pubkey) {
@@ -88,7 +89,6 @@ function cry01_render_signal_board($association_slug, $access) {
}
// TODO: load signals from orchestrator spool for this association.
// Placeholder until orchestrator query is implemented.
$out = '<div class="cry01-signal-board mb-4">';
$out .= '<h5 class="cry01-section-label">Capacity Signals</h5>';
$out .= '<p class="text-muted fst-italic">No signals posted yet.</p>';
@@ -102,6 +102,7 @@ function cry01_render_signal_board($association_slug, $access) {
function cry01_render_signal_form($association_slug, $access) {
// Renders the capacity signal registration form.
// The g1_pubkey field is populated by the g1wallet session event when available.
$config = cry01_load_config();
$categories = $config['signal_categories'] ?? [];
$form_url = z_root() . '/cry01/' . cry01_h($association_slug) . '/signal';
@@ -110,14 +111,18 @@ function cry01_render_signal_form($association_slug, $access) {
$out .= '<h3>Register a Capacity Signal</h3>';
$out .= '<p class="text-muted">Describe what you are offering or seeking, denominated in Ğ1.</p>';
// Wallet session note — replaced by g1wallet integration once built.
$out .= '<div class="alert alert-info small">Your Ğ1 public key will be populated automatically once the Ğ1 Wallet addon is installed. Until then, enter it manually below.</div>';
$out .= '<form method="post" action="' . $form_url . '" class="cry01-form" novalidate>';
$out .= cry01_csrf_token();
// Ğ1 public key
// g1_pubkey — will be read-only and auto-populated by g1wallet session once available.
$out .= '<div class="mb-3">';
$out .= '<label class="form-label" for="g1_pubkey">Your Ğ1 Public Key <span class="text-danger">*</span></label>';
$out .= '<input type="text" class="form-control" id="g1_pubkey" name="g1_pubkey" required
placeholder="G1..." maxlength="64">';
placeholder="G1..." maxlength="64"
data-g1wallet-target="pubkey">';
$out .= '<div class="form-text">Your Ğ1 address. This is your payment address for this signal.</div>';
$out .= '</div>';
@@ -200,11 +205,11 @@ function cry01_render_g1_candidates($association_slug) {
function cry01_render_manage($association_slug) {
// Renders the operator manage page: cache refresh and config status.
// The Ğ1 public key comes from the wallet session — not from config.
$cache = cry01_read_cache();
$refreshed = $cache['refreshed_at'] ?? null;
$config = cry01_load_config();
$has_rpc = !empty($config['g1_rpc_endpoint']);
$has_key = !empty($config['operator_g1_pubkey']);
$manage_url = z_root() . '/cry01/' . cry01_h($association_slug) . '/manage';
@@ -215,29 +220,37 @@ function cry01_render_manage($association_slug) {
$out .= '<div class="mb-3">';
$out .= '<h5>Configuration</h5>';
$out .= '<p>' . ($has_rpc ? '✓' : '✗') . ' Duniter RPC endpoint: ';
$out .= $has_rpc ? '<span class="text-success">configured</span>' : '<span class="text-danger">missing</span>';
$out .= '</p>';
$out .= '<p>' . ($has_key ? '✓' : '✗') . ' Operator Ğ1 public key: ';
$out .= $has_key ? '<span class="text-success">configured</span>' : '<span class="text-danger">missing</span>';
$out .= $has_rpc
? '<span class="text-success">configured</span>'
: '<span class="text-danger">missing</span>';
$out .= '</p>';
$out .= '<p class="text-muted small">Your Ğ1 public key comes from your Ğ1 Wallet session — not from config. ';
$out .= 'Unlock your wallet at <a href="' . z_root() . '/g1wallet">Ğ1 Wallet</a>, then return here to refresh.</p>';
$out .= '</div>';
// Cache status
$out .= '<div class="mb-3">';
$out .= '<h5>Balance Cache</h5>';
if ($refreshed) {
$stale = cry01_cache_is_stale() ? ' (stale)' : ' (current)';
$cached_key = $cache['g1_pubkey'] ?? '';
$stale = cry01_cache_is_stale() ? ' (stale)' : ' (current)';
$out .= '<p>Last refreshed: ' . cry01_h($refreshed) . $stale . '</p>';
if ($cached_key) {
$out .= '<p class="text-muted small">Cached key: ' . cry01_h(substr($cached_key, 0, 16) . '...') . '</p>';
}
} else {
$out .= '<p class="text-muted">Cache has not been populated yet.</p>';
}
$out .= '</div>';
// Refresh form
// Refresh form — g1_pubkey comes from wallet session via hidden field.
// g1wallet.js populates data-g1wallet-target="pubkey" fields on unlock.
$out .= '<form method="post" action="' . $manage_url . '">';
$out .= cry01_csrf_token();
$out .= '<input type="hidden" name="action" value="refresh_cache">';
$out .= '<input type="hidden" name="g1_pubkey" id="manage_g1_pubkey" data-g1wallet-target="pubkey">';
$out .= '<button type="submit" class="btn btn-sm btn-outline-primary">Refresh Balance Cache</button>';
$out .= '<span class="text-muted small ms-2">Requires active Ğ1 Wallet session.</span>';
$out .= '</form>';
$out .= '</div>';