@@ -726,6 +726,15 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
726726 }
727727
728728 pub fn profiles ( & self ) -> Vec < NwcProfile > {
729+ self . nwc
730+ . read ( )
731+ . unwrap ( )
732+ . iter ( )
733+ . map ( |x| x. nwc_profile ( ) )
734+ . collect ( )
735+ }
736+
737+ pub fn active_profiles ( & self ) -> Vec < NwcProfile > {
729738 self . nwc
730739 . read ( )
731740 . unwrap ( )
@@ -738,7 +747,8 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
738747 pub ( crate ) fn remove_inactive_profiles ( & self ) -> Result < ( ) , MutinyError > {
739748 let mut profiles = self . nwc . write ( ) . unwrap ( ) ;
740749
741- profiles. retain ( |x| x. profile . active ( ) ) ;
750+ let mutiny_plus_index = ReservedProfile :: MutinySubscription . info ( ) . 1 ;
751+ profiles. retain ( |x| x. profile . active ( ) || x. profile . index == mutiny_plus_index) ;
742752
743753 // save to storage
744754 {
@@ -836,6 +846,7 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
836846
837847 // save to storage
838848 {
849+ log_info ! ( self . logger, "Saving nwc to storage" ) ;
839850 let profiles = profiles
840851 . iter ( )
841852 . map ( |x| x. profile . clone ( ) )
@@ -992,6 +1003,8 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
9921003 tag : NwcProfileTag ,
9931004 commands : Vec < Method > ,
9941005 ) -> Result < NwcProfile , MutinyError > {
1006+ log_info ! ( self . logger, "Creating new internal nwc profile" ) ;
1007+
9951008 let mut profiles = self . nwc . try_write ( ) ?;
9961009
9971010 let ( name, index, child_key_index) = get_next_nwc_index ( profile_type, & profiles) ?;
@@ -1569,9 +1582,15 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
15691582 }
15701583
15711584 pub fn delete_nwc_profile ( & self , index : u32 ) -> Result < ( ) , MutinyError > {
1572- let mut vec = self . nwc . write ( ) . unwrap ( ) ;
1585+ log_info ! ( self . logger, "Deleting nwc profile: {index}" ) ;
1586+
1587+ // don't delete mutiny+ profile
1588+ if index == ReservedProfile :: MutinySubscription . info ( ) . 1 {
1589+ return self . disable_mutiny_plus_profile ( ) ;
1590+ }
15731591
15741592 // update the profile
1593+ let mut vec = self . nwc . write ( ) . unwrap ( ) ;
15751594 vec. retain ( |x| x. profile . index != index) ;
15761595
15771596 let profiles = vec. iter ( ) . map ( |x| x. profile . clone ( ) ) . collect :: < Vec < _ > > ( ) ;
@@ -1582,6 +1601,30 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
15821601 Ok ( ( ) )
15831602 }
15841603
1604+ pub fn disable_mutiny_plus_profile ( & self ) -> Result < ( ) , MutinyError > {
1605+ log_info ! ( self . logger, "Disabling mutiny+ subscription" ) ;
1606+
1607+ let mut vec = self . nwc . write ( ) . unwrap ( ) ;
1608+
1609+ let profile_opt = vec
1610+ . iter_mut ( )
1611+ . find ( |p| p. profile . index == ReservedProfile :: MutinySubscription . info ( ) . 1 ) ;
1612+
1613+ match profile_opt {
1614+ Some ( p) => {
1615+ p. profile . enabled = Some ( false ) ;
1616+
1617+ let profiles = vec. iter ( ) . map ( |x| x. profile . clone ( ) ) . collect :: < Vec < _ > > ( ) ;
1618+
1619+ self . storage
1620+ . set_data ( NWC_STORAGE_KEY . to_string ( ) , profiles, None ) ?;
1621+
1622+ Ok ( ( ) )
1623+ }
1624+ None => Err ( MutinyError :: NotFound ) ,
1625+ }
1626+ }
1627+
15851628 pub async fn claim_single_use_nwc (
15861629 & self ,
15871630 amount_sats : u64 ,
0 commit comments