From 2d020c90101d844d77f66fa61380ee2fc2e08907 Mon Sep 17 00:00:00 2001 From: TheRON Date: Sun, 14 Jun 2026 07:48:17 -0400 Subject: [PATCH] Updated --- hubzilla/addon/g1wallet/Widget/G1wallet.php | 64 ++++++--------------- 1 file changed, 19 insertions(+), 45 deletions(-) diff --git a/hubzilla/addon/g1wallet/Widget/G1wallet.php b/hubzilla/addon/g1wallet/Widget/G1wallet.php index 1c2c809..ea32ce1 100644 --- a/hubzilla/addon/g1wallet/Widget/G1wallet.php +++ b/hubzilla/addon/g1wallet/Widget/G1wallet.php @@ -3,78 +3,52 @@ namespace Zotlabs\Widget; /** - * G1wallet — sidebar wallet status widget. - * Shows locked/unlocked state, first 12 chars of pubkey, and cached balance. - * At skeleton stage: always shows locked (JS session detection not yet wired). - * Once g1wallet.js is implemented, it dispatches 'g1wallet:unlocked' and - * 'g1wallet:locked' events that this widget's JS listener updates the DOM for. + * G1wallet — sidebar widget. + * Shows the participant's registered Ğ1 address (short) and cached balance. + * Links to /g1wallet for registration or update. + * No JS session state — all server-side. */ class G1wallet { public function widget($arr) { $wallet_url = z_root() . '/g1wallet'; - // Retrieve cached pubkey and balance from channel settings if available. - // These are set by g1wallet_handle_pubkey_post() and the balance refresh flow. - $cached_pubkey = ''; + $stored_address = ''; $cached_balance = ''; if (local_channel()) { - $cached_pubkey = get_pconfig(local_channel(), 'g1wallet', 'g1_pubkey') ?: ''; + $stored_address = get_pconfig(local_channel(), 'g1wallet', 'g1_address') ?: ''; $cached_balance = get_pconfig(local_channel(), 'g1wallet', 'g1_balance') ?: ''; } - $uid = 'g1wallet-widget-' . substr(md5(uniqid()), 0, 6); - - $out = '
'; + $out = '
'; $out .= '
'; $out .= 'Ğ1 Wallet'; $out .= '
'; - // Static locked state — shown on page load. - // JS will update this div via 'g1wallet:unlocked' / 'g1wallet:locked' events. - $out .= '
'; - $out .= $this->render_locked_status($wallet_url, $cached_pubkey, $cached_balance); - $out .= '
'; - - // Data attributes for JS to pick up the widget instance. - $out .= ''; - - $out .= '
'; - return $out; - } - - private function render_locked_status($wallet_url, $cached_pubkey, $cached_balance) { - $out = '
'; - $out .= '🔒 '; - $out .= 'Locked'; - - // If we have a cached pubkey from a previous session, show it as context. - if ($cached_pubkey) { - $short = substr($cached_pubkey, 0, 12) . '…'; - $out .= '
'; + if ($stored_address) { + $short = substr($stored_address, 0, 12) . '…'; + $out .= '
'; + $out .= '
'; $out .= $this->h($short); + $out .= '
'; if ($cached_balance) { - $out .= ' · ' . $this->h($cached_balance) . ' Ğ1'; + $out .= '
' . $this->h($cached_balance) . ' Ğ1
'; } + $out .= ''; + $out .= '
'; + } else { + $out .= '
'; + $out .= 'No address registered.'; + $out .= ''; $out .= '
'; } - $out .= '
'; - $out .= 'Unlock'; - $out .= '
'; $out .= '
'; return $out; } private function h($value) { - // HTML-escapes a value for safe output. return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } }