2026-01-27 16:21:58 +00:00
|
|
|
---
|
|
|
|
|
import Layout from '../layouts/Layout.astro';
|
2026-01-28 23:47:14 +00:00
|
|
|
import { API_BASE as apiBase } from '../lib/api';
|
|
|
|
|
import DelegationGraph from '../components/voting/DelegationGraph.astro';
|
2026-01-27 16:21:58 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<Layout title="Delegations - Likwid">
|
2026-01-29 12:50:25 +00:00
|
|
|
<section class="ui-page">
|
|
|
|
|
<div class="ui-container">
|
|
|
|
|
<div class="hero ui-card ui-card-glass">
|
|
|
|
|
<div class="hero-top">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 class="hero-title">Vote Delegations</h1>
|
|
|
|
|
<p class="hero-subtitle">Delegate your voting power to trusted members</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="hero-actions">
|
|
|
|
|
<a href="/communities" class="ui-btn ui-btn-secondary">Browse</a>
|
|
|
|
|
<button class="ui-btn ui-btn-primary" id="new-delegation-btn" type="button" style="display:none;">New Delegation</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-28 23:47:14 +00:00
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="hero-kpis">
|
|
|
|
|
<div class="hero-kpis-label">At a glance</div>
|
|
|
|
|
<div class="ui-kpis">
|
|
|
|
|
<div class="ui-kpi">
|
|
|
|
|
<div class="ui-kpi-value" id="kpi-outgoing">—</div>
|
|
|
|
|
<div class="ui-kpi-label">My delegations</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="ui-kpi">
|
|
|
|
|
<div class="ui-kpi-value" id="kpi-incoming">—</div>
|
|
|
|
|
<div class="ui-kpi-label">Delegated to me</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="ui-kpi">
|
|
|
|
|
<div class="ui-kpi-value" id="kpi-delegates">—</div>
|
|
|
|
|
<div class="ui-kpi-label">Available delegates</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="ui-card auth-required" id="auth-check">
|
|
|
|
|
<p>Please <a href="/login">log in</a> to manage delegations.</p>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="delegations-content" id="delegations-content" style="display: none;">
|
|
|
|
|
<details class="panel ui-card" open>
|
|
|
|
|
<summary class="panel-summary">
|
|
|
|
|
<span class="panel-title">Delegation network</span>
|
|
|
|
|
<span class="panel-meta">Explorable view</span>
|
|
|
|
|
</summary>
|
|
|
|
|
<div class="panel-body">
|
|
|
|
|
<DelegationGraph />
|
|
|
|
|
</div>
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
<div class="tabs ui-card">
|
|
|
|
|
<button class="tab active" data-tab="outgoing" type="button">My Delegations</button>
|
|
|
|
|
<button class="tab" data-tab="incoming" type="button">Delegated to Me</button>
|
|
|
|
|
<button class="tab" data-tab="delegates" type="button">Find Delegates</button>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="tab-content active" id="tab-outgoing">
|
|
|
|
|
<div class="section-header ui-card">
|
|
|
|
|
<div>
|
|
|
|
|
<h2>Active Delegations</h2>
|
|
|
|
|
<p class="help-text">Your current outgoing delegations (what you delegate to others).</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button class="ui-btn ui-btn-primary" id="new-delegation-btn-secondary" type="button">New Delegation</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="delegations-list" id="my-delegations">
|
|
|
|
|
<p class="loading">Loading delegations...</p>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="tab-content" id="tab-incoming">
|
|
|
|
|
<div class="section-header ui-card">
|
|
|
|
|
<div>
|
|
|
|
|
<h2>Votes Delegated to Me</h2>
|
|
|
|
|
<p class="help-text">Incoming delegations (people who trust you to vote on their behalf).</p>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="delegations-list" id="incoming-delegations">
|
|
|
|
|
<p class="loading">Loading...</p>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-content" id="tab-delegates">
|
|
|
|
|
<div class="section-header ui-card">
|
|
|
|
|
<div>
|
|
|
|
|
<h2>Available Delegates</h2>
|
|
|
|
|
<p class="help-text">Find trusted community members to delegate your votes to.</p>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
<div class="delegates-list" id="delegates-list">
|
|
|
|
|
<p class="loading">Loading delegates...</p>
|
2026-01-28 23:47:14 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="modal" id="delegation-modal">
|
|
|
|
|
<div class="modal-content ui-card">
|
|
|
|
|
<div class="modal-header">
|
|
|
|
|
<h2>Create Delegation</h2>
|
|
|
|
|
<button type="button" class="ui-btn ui-btn-secondary" id="cancel-delegation">Close</button>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
<form id="delegation-form">
|
|
|
|
|
<div class="form-grid">
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="delegate-select">Delegate to</label>
|
|
|
|
|
<select id="delegate-select" required class="ui-select">
|
|
|
|
|
<option value="">Select a delegate...</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="scope-select">Scope</label>
|
|
|
|
|
<select id="scope-select" required class="ui-select">
|
|
|
|
|
<option value="global">Global (all votes)</option>
|
|
|
|
|
<option value="community">Specific Community</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group" id="community-select-group" style="display: none;">
|
|
|
|
|
<label for="community-select">Community</label>
|
|
|
|
|
<select id="community-select" class="ui-select">
|
|
|
|
|
<option value="">Select community...</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="weight-input">Delegation weight</label>
|
|
|
|
|
<input id="weight-input" type="range" min="0.1" max="1" step="0.1" value="1" />
|
|
|
|
|
<div class="help-text" id="weight-label">100% of your voting power</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-actions">
|
|
|
|
|
<button type="submit" class="ui-btn ui-btn-primary">Create Delegation</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
</section>
|
2026-01-27 16:21:58 +00:00
|
|
|
</Layout>
|
|
|
|
|
|
|
|
|
|
<style>
|
2026-01-29 12:50:25 +00:00
|
|
|
.hero {
|
|
|
|
|
padding: 1.25rem;
|
|
|
|
|
margin-bottom: 1rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
.hero-top {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
flex-wrap: wrap;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
.hero-title {
|
2026-01-27 16:21:58 +00:00
|
|
|
margin: 0;
|
2026-01-29 12:50:25 +00:00
|
|
|
font-size: 2.125rem;
|
|
|
|
|
letter-spacing: -0.02em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.hero-subtitle {
|
|
|
|
|
margin: 0.25rem 0 0;
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.hero-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.hero-kpis {
|
|
|
|
|
margin-top: 1rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
.hero-kpis-label {
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
font-size: 0.8125rem;
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
letter-spacing: 0.02em;
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-required {
|
|
|
|
|
padding: 1rem 1.1rem;
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-required a {
|
|
|
|
|
color: var(--color-primary);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tabs {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 0.5rem;
|
2026-01-29 12:50:25 +00:00
|
|
|
margin: 1rem 0;
|
|
|
|
|
padding: 0.5rem;
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: 14px;
|
|
|
|
|
background: rgba(255, 255, 255, 0.03);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab {
|
2026-01-29 12:50:25 +00:00
|
|
|
flex: 1;
|
|
|
|
|
padding: 0.65rem 0.9rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
background: transparent;
|
2026-01-29 12:50:25 +00:00
|
|
|
border: 1px solid transparent;
|
|
|
|
|
color: var(--color-text-muted);
|
2026-01-27 16:21:58 +00:00
|
|
|
cursor: pointer;
|
2026-01-29 12:50:25 +00:00
|
|
|
border-radius: 12px;
|
|
|
|
|
transition: transform 140ms ease, background 140ms ease, color 140ms ease, border-color 140ms ease;
|
|
|
|
|
font-weight: 700;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab:hover {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text);
|
|
|
|
|
background: rgba(255, 255, 255, 0.05);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab.active {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text);
|
|
|
|
|
background: rgba(255, 255, 255, 0.07);
|
|
|
|
|
border-color: var(--color-border);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab-content {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tab-content.active {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-header {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
2026-01-29 12:50:25 +00:00
|
|
|
align-items: flex-start;
|
|
|
|
|
gap: 1rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
margin-bottom: 1rem;
|
2026-01-29 12:50:25 +00:00
|
|
|
padding: 1rem 1.1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-header h2 {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 1rem;
|
|
|
|
|
letter-spacing: -0.01em;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegations-list, .delegates-list {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card, .delegate-card {
|
2026-01-29 12:50:25 +00:00
|
|
|
background: rgba(255, 255, 255, 0.03);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: 14px;
|
|
|
|
|
padding: 1.1rem;
|
|
|
|
|
transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card:hover, .delegate-card:hover {
|
|
|
|
|
transform: translateY(-2px);
|
|
|
|
|
border-color: var(--color-border-hover);
|
|
|
|
|
background: rgba(255, 255, 255, 0.05);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card header {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 0.75rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card .delegate-name {
|
|
|
|
|
font-weight: 600;
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card .scope-badge {
|
|
|
|
|
padding: 0.25rem 0.75rem;
|
|
|
|
|
border-radius: 1rem;
|
|
|
|
|
font-size: 0.85rem;
|
2026-01-29 12:50:25 +00:00
|
|
|
background: rgba(255, 255, 255, 0.08);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
color: var(--color-text);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card .meta {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
2026-01-27 16:21:58 +00:00
|
|
|
font-size: 0.9rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegation-card .actions {
|
|
|
|
|
margin-top: 1rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegate-card {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegate-info h3 {
|
|
|
|
|
margin: 0 0 0.25rem 0;
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text);
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegate-info .bio {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
2026-01-27 16:21:58 +00:00
|
|
|
font-size: 0.9rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegate-stats {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 1.5rem;
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
2026-01-27 16:21:58 +00:00
|
|
|
font-size: 0.9rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal {
|
|
|
|
|
display: none;
|
|
|
|
|
position: fixed;
|
|
|
|
|
inset: 0;
|
|
|
|
|
background: rgba(0,0,0,0.5);
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
2026-01-29 12:50:25 +00:00
|
|
|
padding: 1rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal.active {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal-content {
|
2026-01-29 12:50:25 +00:00
|
|
|
padding: 1.25rem;
|
|
|
|
|
border-radius: 16px;
|
2026-01-27 16:21:58 +00:00
|
|
|
width: 100%;
|
|
|
|
|
max-width: 500px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
.modal-header {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.modal-header h2 {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 1.125rem;
|
|
|
|
|
letter-spacing: -0.01em;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 16:21:58 +00:00
|
|
|
.form-group {
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-group label {
|
|
|
|
|
display: block;
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
.form-grid {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
gap: 0.75rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.form-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-end;
|
2026-01-29 12:50:25 +00:00
|
|
|
margin-top: 1rem;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.help-text {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
margin: 0.35rem 0 0;
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.loading {
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
2026-01-27 16:21:58 +00:00
|
|
|
text-align: center;
|
|
|
|
|
padding: 2rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.empty-state {
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding: 3rem;
|
2026-01-29 12:50:25 +00:00
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media (max-width: 640px) {
|
|
|
|
|
.delegate-card {
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delegate-stats {
|
|
|
|
|
width: 100%;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
}
|
2026-01-27 16:21:58 +00:00
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2026-01-28 23:47:14 +00:00
|
|
|
<script define:vars={{ apiBase }}>
|
|
|
|
|
const API_URL = apiBase;
|
2026-01-27 16:21:58 +00:00
|
|
|
let token = localStorage.getItem('token');
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
function escapeHtml(value) {
|
|
|
|
|
return String(value || '').replace(/[&<>"']/g, function(ch) {
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case '&': return '&';
|
|
|
|
|
case '<': return '<';
|
|
|
|
|
case '>': return '>';
|
|
|
|
|
case '"': return '"';
|
|
|
|
|
case "'": return ''';
|
|
|
|
|
default: return ch;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeScope(scope) {
|
|
|
|
|
const s = String(scope || '').toLowerCase();
|
|
|
|
|
if (s === 'global' || s === 'community' || s === 'topic' || s === 'proposal') return s;
|
|
|
|
|
return 'global';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getScopeLabel(scope) {
|
|
|
|
|
const s = normalizeScope(scope);
|
|
|
|
|
const labels = {
|
|
|
|
|
global: '🌐 Global',
|
|
|
|
|
community: '🏘️ Community',
|
|
|
|
|
topic: '📁 Topic',
|
|
|
|
|
proposal: '📄 Proposal'
|
|
|
|
|
};
|
|
|
|
|
return labels[s] || s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setText(id, value) {
|
|
|
|
|
const el = document.getElementById(id);
|
|
|
|
|
if (el) el.textContent = String(value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 16:21:58 +00:00
|
|
|
async function init() {
|
|
|
|
|
if (!token) {
|
|
|
|
|
document.getElementById('auth-check').style.display = 'block';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById('auth-check').style.display = 'none';
|
|
|
|
|
document.getElementById('delegations-content').style.display = 'block';
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
document.getElementById('new-delegation-btn')?.setAttribute('style', 'display:inline-flex;');
|
|
|
|
|
|
2026-01-27 16:21:58 +00:00
|
|
|
await Promise.all([
|
|
|
|
|
loadMyDelegations(),
|
|
|
|
|
loadIncomingDelegations(),
|
|
|
|
|
loadDelegates()
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
setupTabs();
|
|
|
|
|
setupModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setupTabs() {
|
|
|
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
|
|
|
tab.addEventListener('click', () => {
|
|
|
|
|
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
|
|
|
|
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
|
|
|
|
tab.classList.add('active');
|
|
|
|
|
document.getElementById(`tab-${tab.dataset.tab}`).classList.add('active');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setupModal() {
|
|
|
|
|
const modal = document.getElementById('delegation-modal');
|
|
|
|
|
const newBtn = document.getElementById('new-delegation-btn');
|
2026-01-29 12:50:25 +00:00
|
|
|
const newBtnSecondary = document.getElementById('new-delegation-btn-secondary');
|
2026-01-27 16:21:58 +00:00
|
|
|
const cancelBtn = document.getElementById('cancel-delegation');
|
|
|
|
|
const form = document.getElementById('delegation-form');
|
|
|
|
|
const scopeSelect = document.getElementById('scope-select');
|
|
|
|
|
const communityGroup = document.getElementById('community-select-group');
|
2026-01-28 23:47:14 +00:00
|
|
|
const weightInput = document.getElementById('weight-input');
|
|
|
|
|
const weightLabel = document.getElementById('weight-label');
|
2026-01-27 16:21:58 +00:00
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
const openModal = async () => {
|
2026-01-27 16:21:58 +00:00
|
|
|
await loadDelegatesForSelect();
|
|
|
|
|
await loadCommunitiesForSelect();
|
|
|
|
|
modal.classList.add('active');
|
2026-01-29 12:50:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
newBtn?.addEventListener('click', openModal);
|
|
|
|
|
newBtnSecondary?.addEventListener('click', openModal);
|
2026-01-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
cancelBtn?.addEventListener('click', () => {
|
|
|
|
|
modal.classList.remove('active');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
scopeSelect?.addEventListener('change', () => {
|
|
|
|
|
communityGroup.style.display = scopeSelect.value === 'community' ? 'block' : 'none';
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 23:47:14 +00:00
|
|
|
weightInput?.addEventListener('input', () => {
|
|
|
|
|
const v = parseFloat(weightInput.value || '1');
|
|
|
|
|
if (weightLabel) weightLabel.textContent = `${Math.round(v * 100)}% of your voting power`;
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-27 16:21:58 +00:00
|
|
|
form?.addEventListener('submit', async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
await createDelegation();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadMyDelegations() {
|
|
|
|
|
const container = document.getElementById('my-delegations');
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegations`, {
|
|
|
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
|
|
|
});
|
|
|
|
|
const delegations = await res.json();
|
2026-01-29 12:50:25 +00:00
|
|
|
|
|
|
|
|
setText('kpi-outgoing', delegations.length);
|
2026-01-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
if (delegations.length === 0) {
|
|
|
|
|
container.innerHTML = '<div class="empty-state">No active delegations. Create one to delegate your voting power.</div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
container.innerHTML = delegations.map(d => {
|
|
|
|
|
const safeName = escapeHtml(d.delegate_username || 'Unknown');
|
|
|
|
|
const scopeLabel = escapeHtml(getScopeLabel(d.scope));
|
|
|
|
|
const weightPct = Math.round((Number(d.weight) || 1) * 100);
|
|
|
|
|
const createdAt = d.created_at ? new Date(d.created_at).toLocaleDateString() : '';
|
|
|
|
|
const safeId = escapeHtml(d.id);
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
|
<div class="delegation-card">
|
|
|
|
|
<header>
|
|
|
|
|
<span class="delegate-name">→ ${safeName}</span>
|
|
|
|
|
<span class="scope-badge">${scopeLabel}</span>
|
|
|
|
|
</header>
|
|
|
|
|
<div class="meta">
|
|
|
|
|
Weight: ${weightPct}%<br/>
|
|
|
|
|
${createdAt ? `Created: ${escapeHtml(createdAt)}` : ''}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="actions">
|
|
|
|
|
<button class="ui-btn ui-btn-danger" type="button" data-revoke-id="${safeId}">Revoke</button>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
`;
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
container.querySelectorAll('[data-revoke-id]').forEach((btn) => {
|
|
|
|
|
btn.addEventListener('click', async () => {
|
|
|
|
|
const id = btn.getAttribute('data-revoke-id') || '';
|
|
|
|
|
await window.revokeDelegation(id);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-27 16:21:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
container.innerHTML = '<div class="error">Failed to load delegations</div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadIncomingDelegations() {
|
|
|
|
|
const container = document.getElementById('incoming-delegations');
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegations/to-me`, {
|
|
|
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
|
|
|
});
|
|
|
|
|
const delegations = await res.json();
|
2026-01-29 12:50:25 +00:00
|
|
|
|
|
|
|
|
setText('kpi-incoming', delegations.length);
|
2026-01-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
if (delegations.length === 0) {
|
|
|
|
|
container.innerHTML = '<div class="empty-state">No one has delegated votes to you yet.</div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
container.innerHTML = delegations.map(d => {
|
|
|
|
|
const safeName = escapeHtml(d.delegator_username || d.delegate_username || 'Unknown');
|
|
|
|
|
const scopeLabel = escapeHtml(getScopeLabel(d.scope));
|
|
|
|
|
const weightPct = Math.round((Number(d.weight) || 1) * 100);
|
|
|
|
|
const createdAt = d.created_at ? new Date(d.created_at).toLocaleDateString() : '';
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
|
<div class="delegation-card">
|
|
|
|
|
<header>
|
|
|
|
|
<span class="delegate-name">← ${safeName}</span>
|
|
|
|
|
<span class="scope-badge">${scopeLabel}</span>
|
|
|
|
|
</header>
|
|
|
|
|
<div class="meta">
|
|
|
|
|
Weight: ${weightPct}%<br/>
|
|
|
|
|
${createdAt ? `Since: ${escapeHtml(createdAt)}` : ''}
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
`;
|
|
|
|
|
}).join('');
|
2026-01-27 16:21:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
container.innerHTML = '<div class="error">Failed to load incoming delegations</div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadDelegates() {
|
|
|
|
|
const container = document.getElementById('delegates-list');
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegates`);
|
|
|
|
|
const delegates = await res.json();
|
2026-01-29 12:50:25 +00:00
|
|
|
|
|
|
|
|
setText('kpi-delegates', delegates.length);
|
2026-01-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
if (delegates.length === 0) {
|
|
|
|
|
container.innerHTML = '<div class="empty-state">No delegates available yet.</div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 12:50:25 +00:00
|
|
|
container.innerHTML = delegates.map(d => {
|
|
|
|
|
const safeName = escapeHtml(d.display_name || d.username || 'Unknown');
|
|
|
|
|
const safeBio = escapeHtml(d.bio || 'No bio provided');
|
|
|
|
|
const delegators = Number(d.total_delegators) || 0;
|
|
|
|
|
const votes = Number(d.total_votes_cast) || 0;
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
|
<div class="delegate-card">
|
|
|
|
|
<div class="delegate-info">
|
|
|
|
|
<h3>${safeName}</h3>
|
|
|
|
|
<p class="bio">${safeBio}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="delegate-stats">
|
|
|
|
|
<span>${delegators} delegators</span>
|
|
|
|
|
<span>${votes} votes cast</span>
|
|
|
|
|
</div>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
2026-01-29 12:50:25 +00:00
|
|
|
`;
|
|
|
|
|
}).join('');
|
2026-01-27 16:21:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
container.innerHTML = '<div class="error">Failed to load delegates</div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadDelegatesForSelect() {
|
|
|
|
|
const select = document.getElementById('delegate-select');
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegates`);
|
|
|
|
|
const delegates = await res.json();
|
|
|
|
|
select.innerHTML = '<option value="">Select a delegate...</option>' +
|
2026-01-29 12:50:25 +00:00
|
|
|
delegates.map(d => {
|
|
|
|
|
const value = escapeHtml(d.user_id);
|
|
|
|
|
const label = escapeHtml(d.display_name || d.username || 'Unknown');
|
|
|
|
|
return `<option value="${value}">${label}</option>`;
|
|
|
|
|
}).join('');
|
2026-01-27 16:21:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to load delegates for select');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadCommunitiesForSelect() {
|
|
|
|
|
const select = document.getElementById('community-select');
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/communities`);
|
|
|
|
|
const communities = await res.json();
|
|
|
|
|
select.innerHTML = '<option value="">Select community...</option>' +
|
2026-01-29 12:50:25 +00:00
|
|
|
communities.map(c => {
|
|
|
|
|
const value = escapeHtml(c.id);
|
|
|
|
|
const label = escapeHtml(c.name);
|
|
|
|
|
return `<option value="${value}">${label}</option>`;
|
|
|
|
|
}).join('');
|
2026-01-27 16:21:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Failed to load communities');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createDelegation() {
|
|
|
|
|
const delegateId = document.getElementById('delegate-select').value;
|
|
|
|
|
const scope = document.getElementById('scope-select').value;
|
|
|
|
|
const communityId = document.getElementById('community-select').value;
|
2026-01-28 23:47:14 +00:00
|
|
|
const weight = parseFloat(document.getElementById('weight-input').value || '1');
|
2026-01-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
delegate_id: delegateId,
|
|
|
|
|
scope: scope,
|
2026-01-28 23:47:14 +00:00
|
|
|
weight: weight,
|
2026-01-27 16:21:58 +00:00
|
|
|
};
|
|
|
|
|
if (scope === 'community' && communityId) {
|
|
|
|
|
body.community_id = communityId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegations`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
document.getElementById('delegation-modal').classList.remove('active');
|
|
|
|
|
await loadMyDelegations();
|
2026-01-28 23:47:14 +00:00
|
|
|
window.dispatchEvent(new Event('delegations:changed'));
|
2026-01-27 16:21:58 +00:00
|
|
|
} else {
|
|
|
|
|
const err = await res.text();
|
|
|
|
|
alert('Failed to create delegation: ' + err);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
alert('Failed to create delegation');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.revokeDelegation = async function(id) {
|
|
|
|
|
if (!confirm('Are you sure you want to revoke this delegation?')) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API_URL}/api/delegations/${id}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
await loadMyDelegations();
|
2026-01-28 23:47:14 +00:00
|
|
|
window.dispatchEvent(new Event('delegations:changed'));
|
2026-01-27 16:21:58 +00:00
|
|
|
} else {
|
|
|
|
|
alert('Failed to revoke delegation');
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
alert('Failed to revoke delegation');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
</script>
|