From dcf32be914dc586011b0a5292a6dc654b4b5f525 Mon Sep 17 00:00:00 2001 From: Bojan Mojsilovic Date: Thu, 4 Apr 2024 10:35:10 +0200 Subject: [PATCH] Add support for unified addresses --- src/components/ParsedNote/ParsedNote.tsx | 17 ++++++++++++++++- src/constants.ts | 1 + src/lib/notes.tsx | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/ParsedNote/ParsedNote.tsx b/src/components/ParsedNote/ParsedNote.tsx index b89e17d..75f067b 100644 --- a/src/components/ParsedNote/ParsedNote.tsx +++ b/src/components/ParsedNote/ParsedNote.tsx @@ -16,6 +16,7 @@ import { isSpotify, isTagMention, isTwitch, + isUnitifedLnAddress, isUrl, isUserMention, isWavelake, @@ -41,7 +42,7 @@ import { hookForDev } from '../../lib/devTools'; import { getMediaUrl as getMediaUrlDefault } from "../../lib/media"; import NoteImage from '../NoteImage/NoteImage'; import { createStore, unwrap } from 'solid-js/store'; -import { hashtagCharsRegex, Kind, linebreakRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants'; +import { hashtagCharsRegex, Kind, linebreakRegex, lnUnifiedRegex, shortMentionInWords, shortNoteWords, specialCharsRegex, urlExtractRegex } from '../../constants'; import { useIntl } from '@cookbook/solid-intl'; import { actions } from '../../translations'; @@ -398,6 +399,20 @@ const ParsedNote: Component<{ return; } + if (isUnitifedLnAddress(token)) { + lastSignificantContent = 'lnbc'; + + const match = token.match(lnUnifiedRegex); + + let lnbcToken = match?.find(m => m.startsWith('lnbc')); + + lnbcToken ? + updateContent(content, 'lnbc', lnbcToken) : + updateContent(content, 'text', token); + + return; + } + if (isLnbc(token)) { lastSignificantContent = 'lnbc'; updateContent(content, 'lnbc', token); diff --git a/src/constants.ts b/src/constants.ts index 1424dcd..42b1d4d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -258,6 +258,7 @@ export const urlExtractRegex = /https?:\/\/\S+\.[^()]+(?:\([^)]*\))*/; export const interpunctionRegex = /^(\.|,|;|\?|\!)$/; export const emojiRegex = /(?:\s|^)\:\w+\:/; export const lnRegex = /lnbc[a-zA-Z0-9]*/; +export const lnUnifiedRegex = /bitcoin:[a-zA-Z0-9]*(\?.*)lightning=([a-zA-Z0-9]*)(&.*|$)/; export const hashtagRegex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/i; export const linebreakRegex = /(\r\n|\r|\n)/ig; diff --git a/src/lib/notes.tsx b/src/lib/notes.tsx index 8685ef4..bdfaffb 100644 --- a/src/lib/notes.tsx +++ b/src/lib/notes.tsx @@ -3,7 +3,7 @@ import { A } from "@solidjs/router"; import { Relay, relayInit } from "nostr-tools"; import { createStore } from "solid-js/store"; import LinkPreview from "../components/LinkPreview/LinkPreview"; -import { appleMusicRegex, emojiRegex, hashtagRegex, interpunctionRegex, Kind, linebreakRegex, lnRegex, mixCloudRegex, nostrNestsRegex, noteRegex, noteRegexLocal, profileRegex, profileRegexG, soundCloudRegex, spotifyRegex, tagMentionRegex, twitchRegex, urlRegex, urlRegexG, wavlakeRegex, youtubeRegex } from "../constants"; +import { appleMusicRegex, emojiRegex, hashtagRegex, interpunctionRegex, Kind, linebreakRegex, lnRegex, lnUnifiedRegex, mixCloudRegex, nostrNestsRegex, noteRegex, noteRegexLocal, profileRegex, profileRegexG, soundCloudRegex, spotifyRegex, tagMentionRegex, twitchRegex, urlRegex, urlRegexG, wavlakeRegex, youtubeRegex } from "../constants"; import { sendMessage, subscribeTo } from "../sockets"; import { MediaSize, NostrRelays, NostrRelaySignedEvent, PrimalNote, SendNoteResult } from "../types/primal"; import { logError, logInfo, logWarning } from "./logger"; @@ -61,6 +61,7 @@ export const isUserMention = (url: string) => profileRegex.test(url); export const isInterpunction = (url: string) => interpunctionRegex.test(url); export const isCustomEmoji = (url: string) => emojiRegex.test(url); export const isLnbc = (url: string) => lnRegex.test(url); +export const isUnitifedLnAddress = (url: string) => lnUnifiedRegex.test(url); export const isImage = (url: string) => ['.jpg', '.jpeg', '.webp', '.png', '.gif', '.format=png'].some(x => url.includes(x)); export const isMp4Video = (url: string) => ['.mp4', '.mov'].some(x => url.includes(x));