Skip to content

Commit

Permalink
refactor out unnecessary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pablof7z committed Aug 19, 2023
1 parent df3b23d commit 457a88a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/lib/user/Npub.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { NDKUser } from "@nostr-dev-kit/ndk";
import type NDK from "@nostr-dev-kit/ndk";
import { truncatedNpub, copyToClipboard } from "$lib/utils";
import { copyToClipboard, truncatedBech32 } from "$lib/utils";
import { Copy, Check } from "lucide-svelte";
import { fade } from "svelte/transition";
Expand All @@ -25,6 +25,11 @@
*/
export let user: NDKUser | undefined = undefined;
/**
* Optionally specify the maximum length of the npub to display
*/
export let npubMaxLength: number | undefined = undefined;
if (!user) {
let opts = npub ? { npub } : { hexpubkey: pubkey };
user = ndk.getUser(opts);
Expand All @@ -49,7 +54,7 @@
<span class="name">
{#if user && user.npub}
<span class="npub {$$props.class}" style={$$props.style}>
{truncatedNpub(user)}
{npubMaxLength ? truncatedBech32(user.npub, npubMaxLength) : user.npub}
<button on:click|preventDefault={copyNpub} class="npub--copyButton">
<Copy size="16" />
</button>
Expand Down
4 changes: 0 additions & 4 deletions src/lib/utils/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ export function prettifyNip05(nip05: string): string {
return nip05;
}
}

export function truncatedNpub(user: NDKUser): string {
return user.npub ? truncatedBech32(user.npub, 16) : "";
}

0 comments on commit 457a88a

Please sign in to comment.