@@ -6,6 +6,7 @@ use crate::nostr::nwc::{
66 PendingNwcInvoice , Profile , SingleUseSpendingConditions , SpendingConditions ,
77 PENDING_NWC_EVENTS_KEY ,
88} ;
9+ use crate :: notifications:: MutinyNotificationClient ;
910use crate :: storage:: MutinyStorage ;
1011use crate :: { error:: MutinyError , utils:: get_random_bip32_child_index} ;
1112use crate :: { utils, HTLCStatus } ;
@@ -69,6 +70,8 @@ pub struct NostrManager<S: MutinyStorage> {
6970 pub storage : S ,
7071 /// Lock for pending nwc invoices
7172 pending_nwc_lock : Arc < Mutex < ( ) > > ,
73+ /// Notification Client
74+ pub notifications : Option < Arc < MutinyNotificationClient > > ,
7275 /// Logger
7376 pub logger : Arc < MutinyLogger > ,
7477}
@@ -350,6 +353,17 @@ impl<S: MutinyStorage> NostrManager<S> {
350353 let _ = client. disconnect ( ) . await ;
351354 }
352355
356+ // register for subscriptions
357+ if let Some ( notifications) = & self . notifications {
358+ // just created, unwrap is safe
359+ let uri = NostrWalletConnectURI :: from_str ( & profile. nwc_uri ) . expect ( "invalid uri" ) ;
360+ let author = uri. secret . x_only_public_key ( nostr:: SECP256K1 ) . 0 ;
361+
362+ notifications
363+ . register_nwc ( author, uri. public_key , & profile. relay , & profile. name )
364+ . await ?;
365+ }
366+
353367 Ok ( profile)
354368 }
355369
@@ -840,6 +854,7 @@ impl<S: MutinyStorage> NostrManager<S> {
840854 pub fn from_mnemonic (
841855 xprivkey : ExtendedPrivKey ,
842856 storage : S ,
857+ notifications : Option < Arc < MutinyNotificationClient > > ,
843858 logger : Arc < MutinyLogger > ,
844859 ) -> Result < Self , MutinyError > {
845860 let context = Secp256k1 :: new ( ) ;
@@ -862,6 +877,7 @@ impl<S: MutinyStorage> NostrManager<S> {
862877 nwc : Arc :: new ( RwLock :: new ( nwc) ) ,
863878 storage,
864879 pending_nwc_lock : Arc :: new ( Mutex :: new ( ( ) ) ) ,
880+ notifications,
865881 logger,
866882 } )
867883 }
0 commit comments