From 092f5b6f95dc5b567bcc789db4eece59c8d2a141 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 9 Jan 2024 16:17:31 +0000 Subject: [PATCH] Add comments to zaps & lnurl pay --- mutiny-core/src/lib.rs | 20 +++++++++++--------- mutiny-wasm/src/lib.rs | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 3233195cd..9835a856e 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -68,7 +68,7 @@ use crate::{ }; use crate::{nostr::NostrManager, utils::sleep}; use ::nostr::key::XOnlyPublicKey; -use ::nostr::{Event, EventBuilder, JsonUtil, Keys, Kind, Metadata, Tag, TagKind}; +use ::nostr::{Event, EventBuilder, JsonUtil, Keys, Kind, Metadata, Tag}; use async_lock::RwLock; use bdk_chain::ConfirmationTime; use bip39::Mnemonic; @@ -1449,6 +1449,7 @@ impl MutinyWallet { amount_sats: u64, zap_npub: Option, mut labels: Vec, + comment: Option, ) -> Result { let response = self.lnurl_client.make_request(&lnurl.url).await?; @@ -1457,7 +1458,7 @@ impl MutinyWallet { let msats = amount_sats * 1000; // if user's npub is given, do an anon zap - let zap_request = match zap_npub { + let (zap_request, comment) = match zap_npub { Some(zap_npub) => { let tags = vec![ Tag::PublicKey { @@ -1471,19 +1472,20 @@ impl MutinyWallet { }, Tag::Lnurl(lnurl.to_string()), Tag::Relays(vec!["wss://nostr.mutinywallet.com".into()]), - Tag::Generic(TagKind::Custom("anon".to_string()), vec![]), + Tag::Anon { msg: comment }, ]; - EventBuilder::new(Kind::ZapRequest, "", tags) - .to_event(&Keys::generate()) - .ok() - .map(|z| z.as_json()) + let event = EventBuilder::new(Kind::ZapRequest, "", tags) + .to_event(&Keys::generate())? + .as_json(); + + (Some(event), None) } - None => None, + None => (None, comment.filter(|c| !c.is_empty())), }; let invoice = self .lnurl_client - .get_invoice(&pay, msats, zap_request, None) + .get_invoice(&pay, msats, zap_request, comment.as_deref()) .await?; let invoice = Bolt11Invoice::from_str(invoice.invoice())?; diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index 716ae7dc8..28576ec88 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -796,6 +796,7 @@ impl MutinyWallet { amount_sats: u64, zap_npub: Option, labels: Vec, + comment: Option, ) -> Result { let lnurl = LnUrl::from_str(&lnurl)?; @@ -806,7 +807,7 @@ impl MutinyWallet { Ok(self .inner - .lnurl_pay(&lnurl, amount_sats, zap_npub, labels) + .lnurl_pay(&lnurl, amount_sats, zap_npub, labels, comment) .await? .into()) }