import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { BenchmarkTable } from "@/components/BenchmarkTable"; import { mirrors } from "@/config/mirrors"; import { benchmarkAllMirrors } from "@/utils/benchmark"; import { BenchmarkResult } from "@/types/benchmark"; import { toast } from "sonner"; import { Activity, Zap } from "lucide-react"; const Index = () => { const [did, setDid] = useState(""); const [loading, setLoading] = useState(false); const [results, setResults] = useState([]); const resolveHandle = async (handle: string): Promise => { try { const response = await fetch( `https://quickdid.smokesignal.tools/xrpc/com.atproto.identity.resolveHandle?handle=${ encodeURIComponent(handle) }`, ); const data = await response.json(); if (data.error) { toast.error( `Unable to resolve handle: ${data.message || "Invalid handle"}`, ); return null; } return data.did; } catch (error) { toast.error("Failed to resolve handle"); console.error(error); return null; } }; const handleBenchmark = async () => { if (!did.trim()) { toast.error("Please enter a DID or handle"); return; } setLoading(true); setResults([]); try { let resolvedDid = did.trim(); // If input doesn't start with "did:plc", treat it as a handle if (!resolvedDid.startsWith("did:plc")) { const resolved = await resolveHandle(resolvedDid); if (!resolved) { setLoading(false); return; } resolvedDid = resolved; toast.success(`Resolved to ${resolvedDid}`); } const benchmarkResults = await benchmarkAllMirrors(mirrors, resolvedDid); setResults(benchmarkResults); const successCount = benchmarkResults.filter((r) => r.status === "success" ).length; toast.success( `Benchmark complete! ${successCount}/${benchmarkResults.length} mirrors responded`, ); } catch (error) { toast.error("Failed to run benchmark"); console.error(error); } finally { setLoading(false); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !loading) { handleBenchmark(); } }; return (
{/* Header */}

PLC Mirror Benchmark

Test and compare response times across different PLC.directory mirrors

{/* Input Section */}
setDid(e.target.value)} onKeyPress={handleKeyPress} className="flex-1 font-mono" disabled={loading} />
Testing {mirrors.length} mirrors with 5 attempts each
{/* Results Section */} {(results.length > 0 || loading) && (

Results

{loading ? (

Benchmarking mirrors...

) : }
)} {/* Info Section */} {results.length === 0 && !loading && (

How to use:

  1. Enter an ATProto DID or handle (e.g., did:plc:z72i7hdynmk6r22z27h6tvur or handle.bsky.social)
  2. Click "Run Benchmark" or press Enter
  3. View response times and status for each mirror

Mirrors can be configured in{" "} src/config/mirrors.ts

)}
); }; export default Index;