From 2ccd3d38b4e69beed8233134a4ea32eeddff7ec5 Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Sat, 1 Mar 2025 20:38:36 -0500 Subject: [PATCH] Add inline note rendering of invoices to pull up wallet selector sheet Changelog-Added: Added inline note rendering of invoices to pull up wallet selector sheet Signed-off-by: Terry Yiu --- damus/Models/NoteContent.swift | 1 + damus/Models/URLHandler.swift | 18 ++++++++++++++++++ damus/Nostr/NostrLink.swift | 12 ++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/damus/Models/NoteContent.swift b/damus/Models/NoteContent.swift index a595c3519..e3d14d120 100644 --- a/damus/Models/NoteContent.swift +++ b/damus/Models/NoteContent.swift @@ -152,6 +152,7 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa func invoice_str(_ invoice: Invoice) -> CompatibleText { // Add foreground color to Lightning invoice but no need to link to anything as the attached preview is sufficient. var attributedString = AttributedString(stringLiteral: abbrev_identifier(invoice.string)) + attributedString.link = URL(string: "damus:lightning:\(invoice.string)") attributedString.foregroundColor = DamusColors.purple return CompatibleText(attributed: attributedString) diff --git a/damus/Models/URLHandler.swift b/damus/Models/URLHandler.swift index 03198d8f1..4feec53d9 100644 --- a/damus/Models/URLHandler.swift +++ b/damus/Models/URLHandler.swift @@ -43,6 +43,18 @@ struct DamusURLHandler { return .route(.Script(script: model)) case .purple(let purple_url): return await damus_state.purple.handle(purple_url: purple_url) + case .invoice(let invoice): + if damus_state.settings.show_wallet_selector { + return .sheet(.select_wallet(invoice: invoice.string)) + } else { + do { + try open_with_wallet(wallet: damus_state.settings.default_wallet.model, invoice: invoice.string) + return .no_action + } + catch { + return .sheet(.select_wallet(invoice: invoice.string)) + } + } case nil: break } @@ -91,6 +103,11 @@ struct DamusURLHandler { return .filter(filt) case .script(let script): return .script(script) + case .invoice(let bolt11): + if let invoice = decode_bolt11(bolt11) { + return .invoice(invoice) + } + return nil } return nil } @@ -103,5 +120,6 @@ struct DamusURLHandler { case wallet_connect(WalletConnectURL) case script([UInt8]) case purple(DamusPurpleURL) + case invoice(Invoice) } } diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift index 160744290..6fd74e0e7 100644 --- a/damus/Nostr/NostrLink.swift +++ b/damus/Nostr/NostrLink.swift @@ -12,6 +12,7 @@ enum NostrLink: Equatable { case ref(RefId) case filter(NostrFilter) case script([UInt8]) + case invoice(String) } func encode_pubkey_uri(_ pubkey: Pubkey) -> String { @@ -93,8 +94,15 @@ func decode_nostr_uri(_ s: String) -> NostrLink? { return } - if parts.count >= 2 && parts[0] == "t" { - return .filter(NostrFilter(hashtag: [parts[1].lowercased()])) + if parts.count >= 2 { + switch parts[0] { + case "t": + return .filter(NostrFilter(hashtag: [parts[1].lowercased()])) + case "lightning": + return .invoice(parts[1]) + default: + break + } } guard parts.count == 1 else {