Skip to content

Commit

Permalink
Add inline note rendering of invoices to pull up wallet selector sheet
Browse files Browse the repository at this point in the history
Changelog-Added: Added inline note rendering of invoices to pull up wallet selector sheet
Signed-off-by: Terry Yiu <[email protected]>
  • Loading branch information
tyiu committed Mar 2, 2025
1 parent 9241039 commit d1a7961
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions damus/Models/NoteContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func reduce_text_block(blocks: [Block], ind: Int, txt: String, one_preview_ref:
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)
Expand Down
18 changes: 18 additions & 0 deletions damus/Models/URLHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -103,5 +120,6 @@ struct DamusURLHandler {
case wallet_connect(WalletConnectURL)
case script([UInt8])
case purple(DamusPurpleURL)
case invoice(Invoice)
}
}
12 changes: 10 additions & 2 deletions damus/Nostr/NostrLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d1a7961

Please sign in to comment.