55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Zotlabs\Widget;
|
|
|
|
/**
|
|
* 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';
|
|
|
|
$stored_address = '';
|
|
$cached_balance = '';
|
|
|
|
if (local_channel()) {
|
|
$stored_address = get_pconfig(local_channel(), 'g1wallet', 'g1_address') ?: '';
|
|
$cached_balance = get_pconfig(local_channel(), 'g1wallet', 'g1_balance') ?: '';
|
|
}
|
|
|
|
$out = '<div class="g1wallet-widget">';
|
|
$out .= '<div class="g1wallet-widget-header">';
|
|
$out .= '<a href="' . $this->h($wallet_url) . '" class="g1wallet-widget-title">Ğ1 Wallet</a>';
|
|
$out .= '</div>';
|
|
|
|
if ($stored_address) {
|
|
$short = substr($stored_address, 0, 12) . '…';
|
|
$out .= '<div class="g1wallet-status mt-1">';
|
|
$out .= '<div class="g1wallet-cached-key text-muted small font-monospace">';
|
|
$out .= $this->h($short);
|
|
$out .= '</div>';
|
|
if ($cached_balance) {
|
|
$out .= '<div class="small mt-1">' . $this->h($cached_balance) . ' Ğ1</div>';
|
|
}
|
|
$out .= '<div class="mt-1"><a href="' . $this->h($wallet_url) . '" class="btn btn-xs btn-outline-secondary btn-sm">View</a></div>';
|
|
$out .= '</div>';
|
|
} else {
|
|
$out .= '<div class="g1wallet-status mt-1">';
|
|
$out .= '<span class="text-muted small">No address registered.</span>';
|
|
$out .= '<div class="mt-1"><a href="' . $this->h($wallet_url) . '" class="btn btn-xs btn-outline-secondary btn-sm">Register</a></div>';
|
|
$out .= '</div>';
|
|
}
|
|
|
|
$out .= '</div>';
|
|
return $out;
|
|
}
|
|
|
|
private function h($value) {
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
}
|