Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/app/analytics/AnalyticsPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { useLiveIntents } from "@/hooks/useLiveIntents";
import {
computeAnalytics,
getStatusDistributionEntries,
computeShareSeries,
computeConcentration,
computeTopMovers,
SLA_THRESHOLDS,
type ShareDimension,
type ShareSeriesPoint,
type TopMover,
type ConcentrationResult,
type AnalyticsResult,
type KpiCard,
type KpiDeltaState,
Expand All @@ -20,6 +27,7 @@ import { downloadBlob, svgToPng } from "@/lib/export/svgToPng";
import { downloadCsv } from "@/lib/csv";
import { secureLogger } from "@/lib/secureLogging";
import { useTranslation } from "@/lib/i18n/I18nProvider";
import { Tooltip } from "@/components/Tooltip";

// ─── Inline format helper ─────────────────────────────────────────────────────

Expand Down Expand Up @@ -1149,6 +1157,72 @@ export default function AnalyticsPageClient() {
</div>
</div>

{/* ── Issue #468: Market-share trends ────────────────────────────── */}
<div className="mt-8 card p-5">
<div className="mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<div>
<div className="eyebrow">Market share trends</div>
<h2 className="mt-2 text-lg font-semibold text-vx-text">Share over time</h2>
</div>
<div className="flex items-center gap-2 flex-wrap">
{/* Dimension selector */}
{(["srcChain", "dstToken", "solver"] as ShareDimension[]).map((dim) => (
<button
key={dim}
type="button"
onClick={() => setDimension(dim)}
className={`px-3 py-1 rounded-lg text-xs font-semibold transition-colors ${
dimension === dim
? "bg-vx-sage-bg text-vx-sage border border-vx-sage/30"
: "bg-vx-surface/50 text-vx-muted border border-vx-border hover:text-vx-text"
}`}
aria-pressed={dimension === dim}
>
{dim === "srcChain" ? "Source Chain" : dim === "dstToken" ? "Dest Token" : "Solver"}
</button>
))}
{/* Normalise toggle */}
<button
type="button"
onClick={() => setNormalized((v) => !v)}
className={`px-3 py-1 rounded-lg text-xs font-semibold border transition-colors ${
normalized
? "bg-vx-sage-bg text-vx-sage border border-vx-sage/30"
: "bg-vx-surface/50 text-vx-muted border border-vx-border hover:text-vx-text"
}`}
aria-pressed={normalized}
>
100% normalised
</button>
</div>
</div>
<StackedAreaChart
seriesData={shareSeries.series}
entities={shareSeries.entities}
colors={shareSeries.colors}
normalized={normalized}
/>
</div>

{/* ── Issue #468: Top movers + Concentration ──────────────────────── */}
<div className="mt-8 grid gap-6 lg:grid-cols-2">
<div className="card p-5">
<div className="eyebrow">Top movers (7d vs previous 7d)</div>
<h2 className="mt-2 text-lg font-semibold text-vx-text">Largest share shifts</h2>
<div className="mt-4">
<TopMoversPanel movers={topMovers} />
</div>
</div>

<div className="card p-5">
<div className="eyebrow">Solver concentration</div>
<h2 className="mt-2 text-lg font-semibold text-vx-text">HHI & top-1/top-3 share</h2>
<div className="mt-4">
<ConcentrationIndicator result={concentration} />
</div>
</div>
</div>

{/* Fill-time / SLA panel (issue #465) */}
<div className="mt-8 card p-5">
<div className="eyebrow">Fill-time &amp; SLA</div>
Expand All @@ -1162,6 +1236,8 @@ export default function AnalyticsPageClient() {
<SlaPanel data={analytics.slaPanel} />
</div>
</div>
</div>
</div>
</main>
<Footer />
</div>
Expand Down
151 changes: 151 additions & 0 deletions src/app/governance/GovernancePageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"use client";

/**
* Governance proposals list page — issue #469.
* Migrated from direct governanceStore imports to SWR-backed hooks.
*/

import { useState } from "react";
import Link from "next/link";
import { Nav } from "@/components/Nav";
import { useProposals } from "@/hooks/useGovernance";
import type { ProposalFilters } from "@/lib/governanceApi";
import { timeRemaining } from "@/lib/time";
import { getMessage } from "@/i18n/messages";

export default function GovernancePageClient() {
const [filter, setFilter] = useState<ProposalFilters["status"]>("all");

const { proposals, isLoading, error } = useProposals(
filter === "all" ? undefined : { status: filter }
);

return (
<div className="min-h-screen">
<Nav variant="breadcrumb" label="Governance" />

<main id="main-content" className="max-w-5xl mx-auto px-3 sm:px-5 py-8 sm:py-12">
<div className="mb-8 sm:mb-10">
<div className="eyebrow mb-2 sm:mb-3 text-xs">Community Protocol</div>
<h1 className="text-2xl sm:text-3xl font-bold text-vx-text mb-2 sm:mb-3">
{getMessage("solve.governance.title")}
</h1>
<p className="text-vx-muted text-xs sm:text-sm max-w-lg leading-relaxed">
{getMessage("solve.governance.description")}
</p>
</div>

{/* Filter buttons */}
<div className="flex gap-2 mb-6 overflow-x-auto pb-1">
{(["all", "active", "passed", "rejected"] as const).map((f) => (
<button
key={f}
type="button"
onClick={() => setFilter(f)}
className={`px-3 py-1.5 rounded-lg text-xs font-semibold capitalize transition-colors ${
filter === f
? "bg-vx-sage-bg text-vx-sage border border-vx-sage/30"
: "bg-vx-surface/50 text-vx-muted hover:text-vx-text border border-vx-border"
}`}
>
{f}
</button>
))}
</div>

{/* Loading skeleton */}
{isLoading && proposals.length === 0 && (
<div className="space-y-4" aria-busy="true" aria-label="Loading proposals…">
{[1, 2, 3].map((i) => (
<div key={i} className="card p-5 sm:p-6 space-y-3 animate-pulse">
<div className="h-4 w-48 rounded bg-vx-surface/60" />
<div className="h-5 w-3/4 rounded bg-vx-surface/50" />
<div className="h-4 w-full rounded bg-vx-surface/40" />
</div>
))}
</div>
)}

{/* Error state */}
{error && !isLoading && (
<div role="alert" className="card p-6 text-sm text-vx-muted">
Unable to load proposals: {error.message}
</div>
)}

{/* Empty state */}
{!isLoading && !error && proposals.length === 0 && (
<div className="card p-6 text-sm text-vx-muted text-center">
No proposals match the selected filter.
</div>
)}

{/* Proposal list */}
{proposals.length > 0 && (
<div className="space-y-4">
{proposals.map((proposal) => (
<div
key={proposal.id}
className="card p-5 sm:p-6 hover:border-vx-sage/40 transition-colors"
>
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-3">
<div className="flex items-center gap-2">
<span className="font-mono text-xs text-vx-sage font-bold">{proposal.id}</span>
<span className="text-xs px-2 py-0.5 rounded-full bg-vx-surface text-vx-muted border border-vx-border">
{proposal.category}
</span>
</div>
<span
className={`text-xs px-2.5 py-0.5 rounded-full font-medium w-fit ${
proposal.status === "active"
? "bg-vx-sage-bg text-vx-sage border border-vx-sage/30"
: proposal.status === "passed"
? "bg-blue-500/10 text-blue-400 border border-blue-500/30"
: "bg-red-500/10 text-red-400 border border-red-500/30"
}`}
>
{proposal.status}
</span>
</div>

<h2 className="text-base sm:text-lg font-bold text-vx-text mb-2">
<Link
href={`/governance/${proposal.id}`}
className="hover:text-vx-sage transition-colors"
>
{proposal.title}
</Link>
</h2>

<p className="text-xs sm:text-sm text-vx-muted mb-4 line-clamp-2 leading-relaxed">
{proposal.description}
</p>

<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 pt-3 border-t border-vx-line text-xs text-vx-muted">
<div className="flex gap-4">
<span>
For: <strong className="text-vx-text">{proposal.votesFor.toLocaleString()}</strong>
</span>
<span>
Against: <strong className="text-vx-text">{proposal.votesAgainst.toLocaleString()}</strong>
</span>
</div>

<div className="flex items-center gap-4">
<span>Deadline: {timeRemaining(proposal.deadline)}</span>
<Link
href={`/governance/${proposal.id}`}
className="text-vx-sage hover:underline font-semibold"
>
View Proposal & Discussion →
</Link>
</div>
</div>
</div>
))}
</div>
)}
</main>
</div>
);
}
Loading
Loading