Skip to content

Commit

Permalink
Re-enable nwc subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed May 9, 2024
1 parent 43599f4 commit 1909da9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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

0 comments on commit 1909da9

Please sign in to comment.