@@ -51,7 +51,9 @@ pub use crate::ldkstorage::{CHANNEL_MANAGER_KEY, MONITORS_PREFIX_KEY};
5151
5252use crate :: auth:: MutinyAuthClient ;
5353use crate :: labels:: { Contact , LabelStorage } ;
54- use crate :: nostr:: nwc:: { NwcProfileTag , SpendingConditions } ;
54+ use crate :: nostr:: nwc:: {
55+ BudgetPeriod , BudgetedSpendingConditions , NwcProfileTag , SpendingConditions ,
56+ } ;
5557use crate :: storage:: { MutinyStorage , DEVICE_ID_KEY , EXPECTED_NETWORK_KEY , NEED_FULL_SYNC_KEY } ;
5658use crate :: { error:: MutinyError , nostr:: ReservedProfile } ;
5759use crate :: { nodemanager:: NodeManager , nostr:: ProfileType } ;
@@ -357,7 +359,8 @@ impl<S: MutinyStorage> MutinyWallet<S> {
357359 // account for 3 day grace period
358360 if expired_time + 86_400 * 3 > crate :: utils:: now ( ) . as_secs ( ) {
359361 // now submit the NWC string if never created before
360- self . ensure_mutiny_nwc_profile ( subscription_client) . await ?;
362+ self . ensure_mutiny_nwc_profile ( subscription_client, false )
363+ . await ?;
361364 }
362365 }
363366 Ok ( expired)
@@ -367,7 +370,11 @@ impl<S: MutinyStorage> MutinyWallet<S> {
367370 }
368371
369372 /// Pay the subscription invoice. This will post a NWC automatically afterwards.
370- pub async fn pay_subscription_invoice ( & self , inv : & Bolt11Invoice ) -> Result < ( ) , MutinyError > {
373+ pub async fn pay_subscription_invoice (
374+ & self ,
375+ inv : & Bolt11Invoice ,
376+ autopay : bool ,
377+ ) -> Result < ( ) , MutinyError > {
371378 if let Some ( subscription_client) = self . node_manager . subscription_client . clone ( ) {
372379 let nodes = self . node_manager . nodes . lock ( ) . await ;
373380 let first_node_pubkey = if let Some ( node) = nodes. values ( ) . next ( ) {
@@ -388,7 +395,8 @@ impl<S: MutinyStorage> MutinyWallet<S> {
388395 . await ?;
389396
390397 // now submit the NWC string if never created before
391- self . ensure_mutiny_nwc_profile ( subscription_client) . await ?;
398+ self . ensure_mutiny_nwc_profile ( subscription_client, autopay)
399+ . await ?;
392400
393401 Ok ( ( ) )
394402 } else {
@@ -399,6 +407,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
399407 async fn ensure_mutiny_nwc_profile (
400408 & self ,
401409 subscription_client : Arc < subscription:: MutinySubscriptionClient > ,
410+ autopay : bool ,
402411 ) -> Result < ( ) , MutinyError > {
403412 let nwc_profiles = self . nostr . profiles ( ) ;
404413 let reserved_profile_index = ReservedProfile :: MutinySubscription . info ( ) . 1 ;
@@ -409,16 +418,33 @@ impl<S: MutinyStorage> MutinyWallet<S> {
409418 match profile_opt {
410419 None => {
411420 // profile with the reserved index does not exist, create a new one
412- let profile = self
413- . nostr
414- . create_new_nwc_profile (
415- ProfileType :: Reserved ( ReservedProfile :: MutinySubscription ) ,
416- SpendingConditions :: RequireApproval ,
417- NwcProfileTag :: Subscription ,
418- )
419- . await ?;
421+ let nwc = if autopay {
422+ self . nostr
423+ . create_new_nwc_profile (
424+ ProfileType :: Reserved ( ReservedProfile :: MutinySubscription ) ,
425+ SpendingConditions :: Budget ( BudgetedSpendingConditions {
426+ budget : 21_000 ,
427+ single_max : None ,
428+ payments : vec ! [ ] ,
429+ period : BudgetPeriod :: Month ,
430+ } ) ,
431+ NwcProfileTag :: Subscription ,
432+ )
433+ . await ?
434+ . nwc_uri
435+ } else {
436+ self . nostr
437+ . create_new_nwc_profile (
438+ ProfileType :: Reserved ( ReservedProfile :: MutinySubscription ) ,
439+ SpendingConditions :: RequireApproval ,
440+ NwcProfileTag :: Subscription ,
441+ )
442+ . await ?
443+ . nwc_uri
444+ } ;
445+
420446 // only should have to submit the NWC if never created locally before
421- subscription_client. submit_nwc ( profile . nwc_uri ) . await ?;
447+ subscription_client. submit_nwc ( nwc ) . await ?;
422448 }
423449 Some ( profile) => {
424450 if profile. tag != NwcProfileTag :: Subscription {
0 commit comments