Skip to content

Commit

Permalink
row bg + few small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Dec 21, 2024
1 parent 1f8781a commit 092390d
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 44 deletions.
2 changes: 2 additions & 0 deletions apps/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.6.4",
"publint": "^0.2.0",
"rollup-plugin-polyfill-node": "^0.13.0",
"sass-embedded": "^1.82.0",
"serve": "^14.2.4",
"svelte": "^5.2.7",
Expand Down Expand Up @@ -101,6 +102,7 @@
"@nostrwatch/nocap": "workspace:^",
"@nostrwatch/nocap-websocket-adapter-default": "workspace:^",
"@nostrwatch/utils": "workspace:^",
"@nostrwatch/worker-relay": "^1.3.0",
"@unovis/svelte": "^1.4.5",
"@unovis/ts": "^1.4.5",
"brotli": "^1.3.3",
Expand Down
9 changes: 8 additions & 1 deletion apps/gui/src/lib/components/lists/table/DataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@
</Table.Header>
<Table.Body>
{#each tableInstance?.rows as row (row.id)}
<Table.Row class="{$rowStyles.get(row.pubkey)}" style="{row.banner? `background-image: ${row.banner}; background-repeat: no-repeat; background-size: cover; background-blend-mode: lighten;`: ''}">
<Table.Row
class="{$rowStyles.get(row.pubkey)}"
style="{row.banner?
`background: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.8)), url('${row.banner}');
background-repeat: no-repeat;
background-size: cover; `
: ''}"
>
{#if actionsComponent}
<svelte:component this={actionsComponent} data={row} />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import Badge from "../../ui/badge/badge.svelte";
import type { Nip11 } from "@nostrwatch/nip66/models";
import * as Alert from "$lib/components/ui/alert/index.js";
// Props passed to the component
export let relayUrl: string;
export let nip11: Writable<Nip11 | undefined>;
Expand Down Expand Up @@ -218,11 +221,15 @@
</script>

<div class="p-6 min-h-screen text-white">

<Alert.Root class="mb-2">
<Alert.Title>Notice</Alert.Title>
<Alert.Description>
The relay audit feature is alpha and very experimental. Presently, `AUTH` relays will return false negatives. Only a few NIPs presently have testing suites.
</Alert.Description>
</Alert.Root>

<div class="mb-8">
<h2 class="text-3xl font-bold">
Running NIP Audit
<a href="{relayUrl}" target="_blank" class="text-blue-400 hover:underline">{relayUrl}</a>
</h2>
{#if $auditResults.length === 0}
<p class="text-gray-400 mt-2">No audit results yet.</p>
{/if}
Expand Down
6 changes: 5 additions & 1 deletion apps/gui/src/lib/services/Nip11Service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { nip11 } from 'nostr-tools';
import { nip11sLocal } from '$lib/stores/nip11s.js';
import { Nip11, type RelayInformation } from '@nostrwatch/nip66/models';
import { getRelayErrorSubject, setRelayError, type RelayErrorMessages } from '$lib/stores/relay-errors.js';
import { relaysErrors } from '$lib/stores/relay-errors';

export type Nip11ServiceMessage = {
relay: string,
Expand Down Expand Up @@ -31,16 +32,19 @@ export class Nip11Service {
while(!result && !error){
result = (get(nip11sLocal) as Map<string, Nip11>)?.get(relay)
error = getRelayErrorSubject(relay, 'nip11')
console.log('n11s relays errors (from store in whjile loop)', get(relaysErrors), getRelayErrorSubject(relay, 'nip11'))
await new Promise( resolve => setTimeout( resolve, 200 ))
}
console.log('n11s done?!?!?')
return result;
}

private onmessage(message: MessageEvent<Nip11ServiceMessage>){
console.log('N11S recieved nip11 service message', message)
const { relay, nip11:_nip11, error } = message.data;
if(!_nip11) return;
const nip11 = new Nip11(_nip11 as RelayInformation)
if(error) {
console.log('N11S setting error in store', error.message)
setRelayError(relay, 'nip11', error.message)
return
}
Expand Down
7 changes: 5 additions & 2 deletions apps/gui/src/lib/services/Nip11Service/nip11.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const check = async (relay: string): Promise<nip11.RelayInformation> => {

const timeoutMessage = (relay: string) => {
const error = `Request for NIP-11 from ${relay} timed out.`
console.error(error)
console.error('TIMEOUT ERROR', error)
self.postMessage({ relay, error } as Nip11ServiceMessage)
}

Expand All @@ -24,15 +24,18 @@ self.onmessage = ({ data }) => {
.then((nip11: nip11.RelayInformation) => {
if(timedOut) return;
clearTimeout(timeout)
console.error('CHECK CATCH RESOLVE', error)
self.postMessage({ relay, nip11 } as Nip11ServiceMessage)
})
.catch((error: any) => {
if(timedOut) return;
clearTimeout(timeout)
console.error('CHECK CATCH ERROR', error)
self.postMessage({ relay, error } as Nip11ServiceMessage)
})
}

self.onerror = () => {
self.onerror = (err: any) => {
console.log('WORKER ERROR', err)
self.postMessage({ error: 'timed out.' } as Nip11ServiceMessage)
}
4 changes: 4 additions & 0 deletions apps/gui/src/lib/stores/relay-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type RelayErrorMessage = string
export type RelayErrorMessages = RelayErrorMessage[]
export type RelayErrors = Map<RelayErrorSubject, RelayErrorMessages>
export type RelaysErrors = Map<string, RelayErrors>

export const relaysErrors: Writable<RelaysErrors> = writable(new Map())

export const getRelayErrors = (relay: string): RelayErrors | undefined => {
Expand All @@ -24,6 +25,9 @@ export const setRelayError = (relay: string, subject: RelayErrorSubject, message
if(typeof messages === 'undefined') messages = [];
(messages as RelayErrorMessages).push(message)
relayErrors.set(subject, messages)
console.log('n11s relayErrors', relay, relayErrors)
$relaysErrors.set(relay, relayErrors)
console.log('n11s relays errors', $relaysErrors)
relaysErrors.set($relaysErrors);
console.log('n11s relays errors (from store)', get(relaysErrors))
}
53 changes: 35 additions & 18 deletions apps/gui/src/routes/relays/[protocol]/[...relay]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import { onDestroy, onMount } from 'svelte';
import { doBootstrap } from '$lib/stores/routines.js';
import { derived, writable, type Readable, type Writable } from 'svelte/store';
import { Nip66Event, PubkeyProfile, PubkeyRelays, type Monitor, type INip11 } from '@nostrwatch/nip66/models';
import { Nip66Event, PubkeyProfile, PubkeyRelays, type Monitor, type INip11, type IEvent } from '@nostrwatch/nip66/models';
import { relayAggregates, relayCheckAggregator } from '$lib/stores/checks.js';
import { nip11s, nip11Service, nip11sLocal } from '$lib/stores/nip11s.js';
import { isSeeded } from '$lib/stores/app.js';
import { eventsArray } from '$lib/stores/events.js';
import { relaysErrors } from '$lib/stores/relay-errors.js';
import { isHex } from '$lib/utils/nostr.js';
import { Nip11 } from '@nostrwatch/nip66/models';
import { isLivesyncing, doAggregateCache, hasBeenBoostrapped } from '$lib/stores/app';
Expand All @@ -17,6 +18,7 @@
import { Skeleton } from "$lib/components/ui/skeleton";
import { nip66Ready } from '$lib/stores/app';
import { nip66 } from '$lib/stores';
import { getRelayErrorSubject } from '$lib/stores/relay-errors';
let ProfileCompact: typeof import('$lib/components/partials/ProfileCompact.svelte').default | null = null;
let RelayChecks: typeof import('$lib/components/partials/relay-single/RelayChecks.svelte').default | null = null;
Expand Down Expand Up @@ -69,8 +71,9 @@
export let params: { protocol: string; relay: string };
let currentRelay: string = '';
let loading: boolean = true;
let nip11Ready: Writable<boolean> = writable(false);
const nip11Ready: Writable<boolean> = writable(false);
const operatorMetaReady: Writable<boolean> = writable(false);
const operatorProfile: Writable<PubkeyProfile | null> = writable(null);
const operatorRelays: Writable<PubkeyRelays | null> = writable(null);
const monitors: Writable<Monitor[]> = writable([]);
Expand Down Expand Up @@ -147,12 +150,12 @@
};
const loadNip11 = async () => {
await $nip11Service.check(relayUrl);
await $nip11Service.check(relayUrl)
nip11Ready.set(true);
};
const loadOperatorMeta = async () => {
if (!operatorPubkey) return;
if (!operatorPubkey) return operatorMetaReady.set(true);
const onevent = (event: IEvent) => {
if (event.kind === 0 && !$operatorProfile) {
operatorProfile.set(new PubkeyProfile(event));
Expand All @@ -162,6 +165,7 @@
}
};
await $nip66?.services?.relay?.fetchOperatorMeta(operatorPubkey, { onevent });
operatorMetaReady.set(true)
};
const mount = async () => {
Expand Down Expand Up @@ -246,6 +250,8 @@
$: showAuditTab = relayUrl && $activeTab === 'audit';
$: errors = $relaysErrors?.get(relayUrl)
let [minColWidth, maxColWidth, gap] = [400, 800, 21];
let width: number, height: number;
</script>
Expand Down Expand Up @@ -290,7 +296,7 @@
<Tabs.Trigger value="overview" class="text-lg flex-grow" on:click={() => activeTab.set('overview')}>Overview</Tabs.Trigger>
<Tabs.Trigger value="checks" class="text-lg flex-grow" on:click={() => activeTab.set('checks')}>Checks</Tabs.Trigger>
<Tabs.Trigger disabled={!$nip11} value="nip11" class="text-lg flex-grow" on:click={() => activeTab.set('nip11')}>NIP-11</Tabs.Trigger>
<Tabs.Trigger disabled={operatorPubkey && $operatorRelays?.relays?.length} value="operator-feed" class="text-lg flex-grow" on:click={() => activeTab.set('operator-feed')}>Operator Feed</Tabs.Trigger>
<Tabs.Trigger disabled={!(operatorPubkey && $operatorRelays?.relays?.length)} value="operator-feed" class="text-lg flex-grow" on:click={() => activeTab.set('operator-feed')}>Operator Feed</Tabs.Trigger>
<Tabs.Trigger value="audit" class="text-lg flex-grow" on:click={() => activeTab.set('audit')}>Audits</Tabs.Trigger>
</Tabs.List>
<div class="p-4">
Expand Down Expand Up @@ -328,10 +334,19 @@
{/if}
{/if}
{#if item === 'nips'}
{#if CardNips && $nip11 && $nip11?.supportedNips?.length}
<CardNips supportedNips={$nip11.supportedNips} />

{#if CardNips && supportedNips}
<CardNips {supportedNips} />
{:else}
<Skeleton class="h-40 w-full" />
{#if errors?.get('nip11')?.length}
<div><ul>
{#each errors?.get('nip11') as nip11Error}
<li>{nip11Error}</li>
{/each}
</ul> </div>
{:else}
<!-- <Skeleton class="h-40 w-full" /> -->
{/if}
{/if}
{/if}
{#if item === 'checks'}
Expand All @@ -358,7 +373,7 @@
{#if item === 'operator'}
{#if CardOperator && $operatorProfile && operatorPubkey}
<CardOperator {relayUrl} pubkey={operatorPubkey} profile={$operatorProfile} monitors={$monitors} />
{:else}
{:else if !$operatorMetaReady}
<Skeleton class="h-36 w-full" />
{/if}
{/if}
Expand All @@ -381,18 +396,20 @@
{/if}

<Tabs.Content value="nip11">
{$nip11s.get(relayUrl)?.length ?? 0} NIP-11s from NIP-66 events [{$nip11s.get(relayUrl)?.[0] ? true : false}] <br />
{#if $nip11sLocal?.get(relayUrl)}
<!-- {$nip11s.get(relayUrl)?.length ?? 0} NIP-11s from NIP-66 events [{$nip11s.get(relayUrl)?.[0] ? true : false}] <br /> -->
<!-- {#if $nip11sLocal?.get(relayUrl)}
NIP-11 found locally <br />
{/if}
{/if} -->
<pre class="py-6 px-8 bg-white/5 rounded-lg">{JSON.stringify($nip11?.json, null, 4)}</pre>
</Tabs.Content>

{#if OperatorFeed && operatorPubkey && $activeTab === 'operator-feed'}
<Tabs.Content value="operator-feed">

<Tabs.Content value="operator-feed">
{#if OperatorFeed && operatorPubkey && $activeTab === 'operator-feed'}
<OperatorFeed pubkey={operatorPubkey} />
</Tabs.Content>
{/if}
{/if}
</Tabs.Content>


{#if RelayAudits}
<Tabs.Content value="audit">
Expand Down Expand Up @@ -442,7 +459,7 @@
word-wrap: break-word;
}
.relay-card {
body .relay-card {
@apply bg-white/5;
}
</style>
11 changes: 8 additions & 3 deletions apps/gui/vite.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'vite';
import { sveltekit } from '@sveltejs/kit/vite';
import path from 'path';
import fs from 'fs';
import fetch from 'node-fetch';
import nodePolyfills from 'rollup-plugin-polyfill-node';

function patchSvelteSpeedometer() {
return {
Expand Down Expand Up @@ -33,11 +33,13 @@ export default defineConfig({
worker: {
plugins: [
sveltekit(),
patchSvelteSpeedometer()
patchSvelteSpeedometer(),
nodePolyfills()
]
},
build: {
minify: 'terser',
sourcemap: true,
assetsInlineLimit: 0,
rollupOptions: {
output: {
Expand All @@ -63,7 +65,10 @@ export default defineConfig({
target: "esnext",
},
exclude: [
'svelte-speedometer'
'svelte-speedometer',
'@nostrwatch/worker-relays',
"@nostrwatch/auditor",
"@nostrwatch/nocap"
]
},
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion libraries/nip66/src/services/MonitorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class MonitorService extends Service {
this.manager.loadMonitors(monitors);
}

async fetch(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[] | boolean | undefined> {
async fetch(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[]> {
const { filters, relays, options } = args;
const message: WebsocketRequestBody = { filters, relays, options };
return this._fetch(message, callbacks);
Expand Down
7 changes: 2 additions & 5 deletions libraries/nip66/src/services/RelayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class RelayService extends Service {
keepAlive: false,
stream: false
}
const events: IEvent[] | boolean | undefined = await this._fetch( { relays, filters, options } );
const events: IEvent[] = await this.fetch( { relays, filters, options } );
if(!events) return;
const checks: Nip66Event[] = events.map((event: IEvent) => new Nip66Event(event));
return checks;
Expand All @@ -100,10 +100,7 @@ export class RelayService extends Service {
keepAlive: false,
stream: false
}
if(callbacks){
options.stream = true;
}
return this._fetch( { relays, filters, options }, callbacks );
return this.fetch( { relays, filters, options }, callbacks );
}

async monitorInstancesFromChecks(checks: Nip66Event[], type: 'map' | 'array' = 'map'): Promise<Map<string, Monitor> | Monitor[] | undefined> {
Expand Down
7 changes: 4 additions & 3 deletions libraries/nip66/src/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Service {
return filters;
}

async subscribe(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[] | boolean | undefined> {
async subscribe(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[]> {
let { filters, relays, options, hash } = args;
if(!hash) {
hash = deterministicHash(args)
Expand All @@ -75,7 +75,7 @@ export class Service {
this.subscriptions.add(hash)
const result = await this.websocketAdapter.subscribe(message, callbacks);
this.subscriptions.delete(hash)
return result;
return typeof result === 'boolean'? []: result;
}

async unsubscribe(hash: string) {
Expand All @@ -92,7 +92,7 @@ export class Service {
this.websocketAdapter.unsubscribeAll();
}

async fetch(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[] | boolean | undefined> {
async fetch(args: FetchOptions, callbacks?: SubscribeHandlers): Promise<IEvent[]> {
if(!args.hash) {
args.hash = deterministicHash(args);
}
Expand Down Expand Up @@ -193,6 +193,7 @@ export class Service {
}

const websocketEvents = await this.fetchFromWebsocket(args, _callbacks);
console.log('fetchFromWebsocket resolved')
websocketEvents.forEach(maybeAddEventToMap);

const finalEvents = Array.from(events.values());
Expand Down
Loading

0 comments on commit 092390d

Please sign in to comment.