Merge pull request #337 from v0l/fix-stale-relays

Fix stale relays
This commit is contained in:
Kieran 2023-02-21 10:14:01 +00:00 committed by GitHub
commit 389f73725f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 22 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules/ node_modules/
.idea

View File

@ -12,7 +12,9 @@ const RelayFavicon = ({ url }: { url: string }) => {
.replace(/^ws:\/\//, "http://") .replace(/^ws:\/\//, "http://")
.replace(/\/$/, ""); .replace(/\/$/, "");
const [faviconUrl, setFaviconUrl] = useState(`${cleanUrl}/favicon.ico`); const [faviconUrl, setFaviconUrl] = useState(`${cleanUrl}/favicon.ico`);
return <img className="favicon" src={faviconUrl} onError={() => setFaviconUrl(Nostrich)} />; return (
<img className="favicon" src={faviconUrl} onError={() => setFaviconUrl(Nostrich)} alt={`favicon for ${url}`} />
);
}; };
interface RelaysMetadataProps { interface RelaysMetadataProps {
@ -24,7 +26,7 @@ const RelaysMetadata = ({ relays }: RelaysMetadataProps) => {
<div className="main-content"> <div className="main-content">
{relays?.map(({ url, settings }) => { {relays?.map(({ url, settings }) => {
return ( return (
<div className="card relay-card"> <div key={url} className="card relay-card">
<RelayFavicon url={url} /> <RelayFavicon url={url} />
<code className="relay-url f-ellipsis">{url}</code> <code className="relay-url f-ellipsis">{url}</code>
<div className="relay-settings"> <div className="relay-settings">

View File

@ -7,29 +7,26 @@ export default function useRelaysFeed(pubkey: HexKey) {
const sub = useMemo(() => { const sub = useMemo(() => {
const x = new Subscriptions(); const x = new Subscriptions();
x.Id = `relays:${pubkey.slice(0, 12)}`; x.Id = `relays:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.Relays]); x.Kinds = new Set([EventKind.ContactList]);
x.Authors = new Set([pubkey]); x.Authors = new Set([pubkey]);
x.Limit = 1; x.Limit = 1;
return x; return x;
}, [pubkey]); }, [pubkey]);
const relays = useSubscription(sub, { leaveOpen: false, cache: true }); const relays = useSubscription(sub, { leaveOpen: false, cache: false });
const notes = relays.store.notes; const eventContent = relays.store.notes[0]?.content;
const tags = notes.slice(-1)[0]?.tags || [];
return tags.reduce((rs, tag) => { if (!eventContent) {
const [t, url, ...settings] = tag; return [] as FullRelaySettings[];
if (t === "r") { }
return [
...rs, try {
{ return Object.entries(JSON.parse(eventContent)).map(([url, settings]) => ({
url, url,
settings: { settings,
read: settings.length === 0 || settings.includes("read"), })) as FullRelaySettings[];
write: settings.length === 0 || settings.includes("write"), } catch (error) {
}, console.error(error);
}, return [] as FullRelaySettings[];
]; }
}
return rs;
}, [] as FullRelaySettings[]);
} }

View File

@ -76,6 +76,7 @@ const RelayInfo = () => {
<div className="f-grow"> <div className="f-grow">
{stats.info.supported_nips.map(a => ( {stats.info.supported_nips.map(a => (
<span <span
key={a}
className="pill" className="pill"
onClick={() => onClick={() =>
navigate(`https://github.com/nostr-protocol/nips/blob/master/${a.toString().padStart(2, "0")}.md`) navigate(`https://github.com/nostr-protocol/nips/blob/master/${a.toString().padStart(2, "0")}.md`)