"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { useAccount } from "@/contexts/AccountContext"; import { useWallet } from "@/contexts/WalletContext"; type ActivityMetric = { label: string; value: string; raw: number; max: number; description: string }; function buildMetrics( luxCredits: number, usdBalance: number, testimonials: number, forumPosts: number, ): ActivityMetric[] { return [ { label: "LUX Balance", value: luxCredits.toLocaleString() + " LUX", raw: Math.min(luxCredits / 8000, 1) * 100, max: 8000, description: "Earned via purchases. Drives Inner Circle tier.", }, { label: "USD Balance", value: "$" + usdBalance.toFixed(2), raw: Math.min(usdBalance / 500, 1) * 100, max: 500, description: "Bitcoin-funded USD credit on your handle.", }, { label: "Forum Activity", value: forumPosts + " posts", raw: Math.min(forumPosts / 20, 1) * 100, max: 20, description: "Threads and replies posted to the Void Aggregate.", }, { label: "Testimonials", value: testimonials + " submitted", raw: Math.min(testimonials / 5, 1) * 100, max: 5, description: "Testimonials written and stored locally.", }, ]; } function loadForumPostCount(username: string): number { if (typeof window === "undefined") return 0; try { const raw = localStorage.getItem("cyberlux-forum-v3"); if (!raw) return 0; const data = JSON.parse(raw) as { threads?: { authorHandle: string }[] }; return (data.threads ?? []).filter((t) => t.authorHandle === username).length; } catch { return 0; } } function loadTestimonialCount(): number { if (typeof window === "undefined") return 0; try { const raw = localStorage.getItem("cyberlux-testimonials-v1"); if (!raw) return 0; return (JSON.parse(raw) as unknown[]).length; } catch { return 0; } } const WHAT_IS = [ { q: "What does this score reflect?", a: "Your own activity on this device — LUX credits, USD balance, forum posts, and testimonials you've submitted. Scores are computed locally from your localStorage data." }, { q: "Is this a global reputation system?", a: "No. Data never leaves your browser. There is no server-side scoring. This page is a personal activity dashboard dressed in the CyberLux aesthetic." }, { q: "How do I improve my score?", a: "Fund your account via Bitcoin at /account/add-funds, make purchases (earns LUX), post in /forum, and submit testimonials at /testimonials." }, { q: "What happens if I clear my browser data?", a: "All local data is lost. Export your account bundle from /dashboard before clearing site data to preserve your handle and vault." }, ]; export default function TrustPage() { const { user } = useAccount(); const { luxCredits, usdStoreCredit } = useWallet(); const [metrics, setMetrics] = useState([]); const [hydrated, setHydrated] = useState(false); const [openFaq, setOpenFaq] = useState(null); useEffect(() => { const forumPosts = user ? loadForumPostCount(user.username) : 0; const testimonials = loadTestimonialCount(); setMetrics(buildMetrics(luxCredits, usdStoreCredit, testimonials, forumPosts)); setHydrated(true); }, [luxCredits, usdStoreCredit, user]); const overallScore = hydrated ? Math.round(metrics.reduce((s, m) => s + m.raw, 0) / metrics.length) : 0; return (

Activity Dashboard

Your CyberLux score — computed from this device

LOCAL SCORE · YOUR DEVICE ONLY

{user ? ( <> @{user.username} — Trust Score:{" "} {overallScore}/100 ) : ( <> Activity Score: {overallScore}/100 )}

Computed from your actual local data: LUX credits, USD balance, forum posts, and testimonials stored in this browser. Not a global ranking — your data never leaves your device.

{!user && (

Sign in to see per-handle scores.

)}

Your Metrics

{!hydrated ? (
Loading…
) : (
{metrics.map((m) => (

{m.label}

{m.value}

{m.description}

{Math.round(m.raw)}%
))}
)}

Improve Your Score

{[ { label: "Add Bitcoin funds", sub: "Boosts USD balance", href: "/account/add-funds", color: "border-orange-700/40 text-orange-400" }, { label: "Make a purchase", sub: "Earns LUX credits", href: "/market", color: "border-cyan-700/40 text-cyan-400" }, { label: "Post in forum", sub: "Grows forum activity", href: "/forum", color: "border-purple-700/40 text-purple-400" }, { label: "Write a testimonial", sub: "Adds to your score", href: "/testimonials#submit", color: "border-emerald-700/40 text-emerald-400" }, ].map((item) => (
{item.label}

{item.sub}

))}

FAQ

{WHAT_IS.map((item, i) => (
{openFaq === i && (
{item.a}
)}
))}
); }