mirror of
https://github.com/hoornet/vega.git
synced 2026-05-07 12:49:13 -07:00
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:
44
src/hooks/useReputation.ts
Normal file
44
src/hooks/useReputation.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user