Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/lib/components/TrustScoreCalculator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
} = $props();

let draftTargetPubkey = $state(targetPubkey);
let validationError = $state<string | null>(null);

// Use query for trust score with automatic caching
const trustScoreQuery = $derived(useTrustScore(relatr, serverPubkey, targetPubkey));
Expand All @@ -46,14 +47,21 @@
draftTargetPubkey = targetPubkey;
});

$effect(() => {
// Clear validation error whenever the user edits the input
draftTargetPubkey;
validationError = null;
});

function calculateTrustScore() {
const trimmed = draftTargetPubkey.trim();

if (!validateAndDecodePubkey(trimmed)) {
// We need to handle this validation error separately since the query doesn't validate
validationError = 'Invalid pubkey. Please enter a valid npub1… or hex pubkey.';
return;
}

validationError = null;
onCalculate({
targetPresent: true,
targetPubkey: trimmed
Expand Down Expand Up @@ -118,7 +126,9 @@
{/if}
</Button>

{#if error}
{#if validationError}
<p class="text-sm text-destructive">{validationError}</p>
{:else if error}
<p class="text-sm text-destructive">{error}</p>
{/if}
{:else}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/utils.nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ export function getEventDisplay(identifier: string): string {

/**
* Generate a hex color from a hexadecimal string pubkey
* Takes the first 6 characters and prepends '#' to create a valid hex color
* Takes the first 6 characters and prepends '#' to create a valid hex color.
* Returns a neutral fallback color when pubkey is empty so the function is
* safe to call directly inside template expressions before data has loaded.
*/
export function pubkeyToHexColor(pubkey: string): string {
if (!pubkey) {
throw new Error('Pubkey is required');
return '#888888';
}

const hexColor = pubkey.slice(0, 6);
Expand Down