From a40b9268f6da8763690f802f8c0aecd09c8ebb25 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Tue, 13 Jun 2023 08:38:53 -0700 Subject: [PATCH] Add support for parsing and displaying lnurl invoices --- src/app/shared/Feed.svelte | 2 +- src/app/shared/FeedAdvanced.svelte | 146 +++++++++++++++-------------- src/app/shared/NoteContent.svelte | 15 ++- src/partials/QRCode.svelte | 26 +++-- src/partials/Textarea.svelte | 2 +- src/util/nostr.ts | 16 +++- 6 files changed, 125 insertions(+), 82 deletions(-) diff --git a/src/app/shared/Feed.svelte b/src/app/shared/Feed.svelte index 2fca4440..e61bdf14 100644 --- a/src/app/shared/Feed.svelte +++ b/src/app/shared/Feed.svelte @@ -1,6 +1,6 @@ -
- {modal = modal ? null : 'mini'}} /> +
+ { + modal = modal ? null : "mini" + }} />
{#if modal} - - -
- Search - - - -
- {#if modal === 'maxi'} -
-
- Since - + + +
+ Search + + + +
+ {#if modal === "maxi"} +
+
+ Since + +
+
+ Until + +
-
- Until - + {#if !hide.includes("authors")} +
+ Authors + +
+
+ +
+
+
+
+ {/if} + {#if !hide.includes("#t")} +
+ Topics + +
+
+ #{item.name} +
+
+
+
+ {/if} + {#if !hide.includes("#p")} +
+ Mentions + +
+
+ +
+
+
+
+ {/if} +
+ Apply Filters
-
- {#if !hide.includes('authors')} -
- Authors - -
-
- -
-
-
-
{/if} - {#if !hide.includes('#t')} -
- Topics - -
-
- #{item.name} -
-
-
-
- {/if} - {#if !hide.includes('#p')} -
- Mentions - -
-
- -
-
-
-
- {/if} -
- Apply Filters -
- {/if} -
-
+ + {/if} diff --git a/src/app/shared/NoteContent.svelte b/src/app/shared/NoteContent.svelte index 335752d5..86cd5b42 100644 --- a/src/app/shared/NoteContent.svelte +++ b/src/app/shared/NoteContent.svelte @@ -6,6 +6,7 @@ import {displayPerson, parseContent, getLabelQuality, displayRelay, Tags} from "src/util/nostr" import {modal} from "src/partials/state" import MediaSet from "src/partials/MediaSet.svelte" + import QRCode from "src/partials/QRCode.svelte" import Card from "src/partials/Card.svelte" import Spinner from "src/partials/Spinner.svelte" import Anchor from "src/partials/Anchor.svelte" @@ -29,15 +30,22 @@ let rating = note.kind === 1985 ? getLabelQuality("review/relay", note) : null const links = [] + const invoices = [] const ranges = [] // Find links and preceding whitespace for (let i = 0; i < content.length; i++) { const {type, value} = content[i] - if (type === "link" && !value.startsWith("ws")) { + if (type === "link") { links.push(value) + } + if (type === "lnurl") { + invoices.push(value) + } + + if (["link", "lnurl"].includes(type) && !value.startsWith("ws")) { const prev = content[i - 1] const next = content[i + 1] @@ -197,6 +205,11 @@ {" "} {/each}

+ {#if invoices.length > 0} +
+ +
+ {/if} {#if showMedia && links.length > 0}
diff --git a/src/partials/QRCode.svelte b/src/partials/QRCode.svelte index 4b5fce96..a3164aec 100644 --- a/src/partials/QRCode.svelte +++ b/src/partials/QRCode.svelte @@ -1,4 +1,5 @@
- - - - -
diff --git a/src/partials/Textarea.svelte b/src/partials/Textarea.svelte index 85a99464..495eb9b2 100644 --- a/src/partials/Textarea.svelte +++ b/src/partials/Textarea.svelte @@ -8,7 +8,7 @@ const className = cx( $$props.class, - "rounded shadow-inset py-2 px-4 pr-10 w-full bg-input text-black", + "rounded-xl shadow-inset py-2 px-4 pr-10 w-full bg-input text-black", "placeholder:text-gray-5 border border-solid border-gray-3" ) diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 7c1d82bf..be7dc226 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -265,6 +265,14 @@ export const parseContent = ({content, tags = []}) => { } } + const parseLNUrl = () => { + const lnurl = first(text.match(/^lnbc[\d\w]+/i)) + + if (lnurl) { + return ["lnurl", lnurl, lnurl] + } + } + const parseUrl = () => { const raw = first(text.match(/^([a-z\+:]{2,30}:\/\/)?[^\s]+\.[a-z]{2,6}[^\s]*[^\.!?,:\s]/gi)) @@ -292,7 +300,13 @@ export const parseContent = ({content, tags = []}) => { } while (text) { - const part = parseNewline() || parseMention() || parseTopic() || parseBech32() || parseUrl() + const part = + parseNewline() || + parseMention() || + parseTopic() || + parseBech32() || + parseUrl() || + parseLNUrl() if (part) { if (buffer) {