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/
.idea

View File

@ -12,7 +12,9 @@ const RelayFavicon = ({ url }: { url: string }) => {
.replace(/^ws:\/\//, "http://")
.replace(/\/$/, "");
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 {
@ -24,7 +26,7 @@ const RelaysMetadata = ({ relays }: RelaysMetadataProps) => {
<div className="main-content">
{relays?.map(({ url, settings }) => {
return (
<div className="card relay-card">
<div key={url} className="card relay-card">
<RelayFavicon url={url} />
<code className="relay-url f-ellipsis">{url}</code>
<div className="relay-settings">

View File

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

View File

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