From 1909da9c60fb107a933cfb31906ee04b8b237e47 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Thu, 9 May 2024 15:48:59 -0500 Subject: [PATCH] Re-enable nwc subscriptions --- mutiny-core/src/lib.rs | 4 +++- mutiny-core/src/nostr/mod.rs | 23 +++++++++++++++++++++++ mutiny-wasm/src/lib.rs | 6 ++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index b87684ded..12ad9fe16 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -2419,7 +2419,9 @@ impl MutinyWallet { self.ensure_mutiny_nwc_profile(subscription_client, autopay) .await?; - // FIXME: switch the subscription from disabled to enabled if it was disabled + // make sure the NWC profile is enabled + self.nostr + .enable_nwc_profile(ReservedProfile::MutinySubscription.info().1)?; self.check_blind_tokens(); diff --git a/mutiny-core/src/nostr/mod.rs b/mutiny-core/src/nostr/mod.rs index 5e5c7b06d..999f81029 100644 --- a/mutiny-core/src/nostr/mod.rs +++ b/mutiny-core/src/nostr/mod.rs @@ -1625,6 +1625,29 @@ impl NostrManager { } } + /// Re-enables a disabled nwc profile + pub fn enable_nwc_profile(&self, index: u32) -> Result<(), MutinyError> { + log_info!(self.logger, "Enabling nwc profile: {index}"); + + let mut vec = self.nwc.write().unwrap(); + + let profile_opt = vec.iter_mut().find(|p| p.profile.index == index); + + match profile_opt { + Some(p) => { + p.profile.enabled = Some(true); + + let profiles = vec.iter().map(|x| x.profile.clone()).collect::>(); + + self.storage + .set_data(NWC_STORAGE_KEY.to_string(), profiles, None)?; + + Ok(()) + } + None => Err(MutinyError::NotFound), + } + } + pub async fn claim_single_use_nwc( &self, amount_sats: u64, diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index de371ae0f..1162b9f02 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -1720,6 +1720,12 @@ impl MutinyWallet { Ok(self.inner.nostr.delete_nwc_profile(profile_index)?) } + /// Re-enables a disabled nwc profile + pub async fn enable_nwc_profile(&self, index: u32) -> Result<(), MutinyJsError> { + self.inner.nostr.enable_nwc_profile(index)?; + Ok(()) + } + /// Set budget for a NWC Profile #[wasm_bindgen] pub async fn set_nwc_profile_budget(