Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Re-enable nwc subscriptions #1179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,9 @@ impl<S: MutinyStorage> MutinyWallet<S> {
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();

Expand Down
23 changes: 23 additions & 0 deletions mutiny-core/src/nostr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,29 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
}
}

/// 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::<Vec<_>>();

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,
Expand Down
6 changes: 6 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading