Fix stale relays #337
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
.idea
|
||||||
|
@ -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">
|
||||||
|
@ -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[]);
|
|
||||||
}
|
}
|
||||||
|
@ -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`)
|
||||||
|
Loading…
Reference in New Issue
Block a user