From f3ef3140bbe0219ec081a98f0072eaab748fa768 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sat, 13 Jan 2024 01:15:53 +0000 Subject: [PATCH] Search Improvements Adds ability to send to users who only have a lnurl set. Now shows users without any payment info, but disabled and greyed out. --- src/i18n/en/translations.ts | 1 + src/routes/Search.tsx | 89 ++++++++++++++++++++++--------------- src/utils/fetchZaps.ts | 2 + 3 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index c74a8cdf..bd09e4fa 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -120,6 +120,7 @@ export default { payment_initiated: "Payment Initiated", payment_sent: "Payment Sent", destination: "Destination", + no_payment_info: "No payment info", progress_bar: { of: "of", sats_sent: "sats sent" diff --git a/src/routes/Search.tsx b/src/routes/Search.tsx index 8b84c612..f3921e60 100644 --- a/src/routes/Search.tsx +++ b/src/routes/Search.tsx @@ -91,10 +91,10 @@ function ActualSearch() { return ( contacts()?.filter((c) => { return ( - c.ln_address && - (c.name.toLowerCase().includes(s) || - c.ln_address?.toLowerCase().includes(s) || - c.npub?.includes(s)) + c.name.toLowerCase().includes(s) || + c.ln_address?.toLowerCase().includes(s) || + c.lnurl?.toLowerCase().includes(s) || + c.npub?.includes(s) ); }) || [] ); @@ -279,27 +279,10 @@ function ActualSearch() { 0}> {(contact) => ( - + /> )} @@ -327,12 +310,12 @@ function GlobalSearch(props: { foundNpubs: (string | undefined)[]; }) { const hexpubs = createMemo(() => { - const hexpubs: string[] = []; + const hexpubs: Set = new Set(); for (const npub of props.foundNpubs) { hexpubFromNpub(npub) .then((h) => { if (h) { - hexpubs.push(h); + hexpubs.add(h); } }) .catch((e) => { @@ -342,10 +325,13 @@ function GlobalSearch(props: { return hexpubs; }); - async function searchFetcher(args: { value?: string; hexpubs?: string[] }) { + async function searchFetcher(args: { + value?: string; + hexpubs?: Set; + }) { try { // Handling case when value starts with "npub" - if (args.value?.startsWith("npub")) { + if (args.value?.toLowerCase().startsWith("npub")) { const hexpub = await hexpubFromNpub(args.value); if (!hexpub) return []; @@ -353,14 +339,12 @@ function GlobalSearch(props: { if (!profile) return []; const contact = profileToPseudoContact(profile); - return contact.ln_address ? [contact] : []; + return [contact]; } // Handling case for other values (name, nip-05, whatever else primal searches) const contacts = await searchProfiles(args.value!.toLowerCase()); - return contacts.filter( - (c) => c.ln_address && !args.hexpubs?.includes(c.hexpub) - ); + return contacts.filter((c) => !args.hexpubs?.has(c.hexpub)); } catch (e) { console.error(e); return []; @@ -415,6 +399,7 @@ function SingleContact(props: { sendToContact: (contact: TagItem) => void; }) { const [state, _actions] = useMegaStore(); + async function createContactFromSearchResult(contact: PseudoContact) { try { const contactId = await state.mutiny_wallet?.create_new_contact( @@ -442,9 +427,30 @@ function SingleContact(props: { } return ( - diff --git a/src/utils/fetchZaps.ts b/src/utils/fetchZaps.ts index d5df0b25..f2a85894 100644 --- a/src/utils/fetchZaps.ts +++ b/src/utils/fetchZaps.ts @@ -326,6 +326,7 @@ export type PseudoContact = { name: string; hexpub: string; ln_address?: string; + lnurl?: string; image_url?: string; }; @@ -372,6 +373,7 @@ export function profileToPseudoContact(profile: NostrProfile): PseudoContact { }; contact.name = content.display_name || content.name || profile.pubkey; contact.ln_address = content.lud16 || undefined; + contact.lnurl = content.lud06 || undefined; contact.image_url = content.picture || undefined; return contact as PseudoContact; }