Add Web of Trust reputation on profiles via Vertex DVM

Query Vertex Verify Reputation API (kind 5312) for each profile and
display "Followed by people you trust" with clickable top-follower
avatars. Includes in-memory cache, request dedup, and graceful
fallback when logged out or API unreachable.
This commit is contained in:
Jure
2026-03-29 10:42:19 +02:00
parent 8bc38c11e6
commit 2c17361e50
6 changed files with 178 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
import { useEffect, useState } from "react";
import { verifyReputation } from "../lib/nostr";
import type { ReputationResult } from "../lib/nostr";
import { useUserStore } from "../stores/user";
const cache = new Map<string, ReputationResult | null>();
const pending = new Map<string, Promise<ReputationResult | null>>();
export function useReputation(pubkey: string): { data: ReputationResult | null; loading: boolean } {
const [data, setData] = useState<ReputationResult | null>(() => cache.get(pubkey) ?? null);
const [loading, setLoading] = useState(!cache.has(pubkey));
const loggedIn = useUserStore((s) => s.loggedIn);
useEffect(() => {
if (!loggedIn) {
setLoading(false);
return;
}
if (cache.has(pubkey)) {
setData(cache.get(pubkey)!);
setLoading(false);
return;
}
// Deduplicate concurrent requests
if (!pending.has(pubkey)) {
const request = verifyReputation(pubkey).then((result) => {
cache.set(pubkey, result);
pending.delete(pubkey);
return result;
});
pending.set(pubkey, request);
}
setLoading(true);
pending.get(pubkey)!.then((result) => {
setData(result);
setLoading(false);
});
}, [pubkey, loggedIn]);
return { data, loading };
}