From b9cfe87974038a3eda79a40e728f37da2f2a26ed Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 26 Jun 2025 13:37:30 -0400 Subject: [PATCH] wallet: remove unnecessary mut Signed-off-by: kernelkind --- crates/notedeck/src/lib.rs | 2 +- crates/notedeck/src/wallet.rs | 11 ++++------- crates/notedeck/src/zaps/cache.rs | 5 ++--- crates/notedeck_columns/src/actionbar.rs | 6 +++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs index b61fb8f..f0bc064 100644 --- a/crates/notedeck/src/lib.rs +++ b/crates/notedeck/src/lib.rs @@ -69,7 +69,7 @@ pub use unknowns::{get_unknown_note_ids, NoteRefsUnkIdAction, SingleUnkIdAction, pub use urls::{supported_mime_hosted_at_url, SupportedMimeType, UrlMimes}; pub use user_account::UserAccount; pub use wallet::{ - get_current_wallet, get_wallet_for_mut, GlobalWallet, Wallet, WalletError, WalletType, + get_current_wallet, get_wallet_for, GlobalWallet, Wallet, WalletError, WalletType, WalletUIState, ZapWallet, }; pub use zaps::{ diff --git a/crates/notedeck/src/wallet.rs b/crates/notedeck/src/wallet.rs index 363c053..6969c4d 100644 --- a/crates/notedeck/src/wallet.rs +++ b/crates/notedeck/src/wallet.rs @@ -10,18 +10,18 @@ use tokio::sync::RwLock; use crate::{zaps::UserZapMsats, Accounts, DataPath, DefaultZapMsats, TokenHandler}; -pub fn get_wallet_for_mut<'a>( +pub fn get_wallet_for<'a>( accounts: &'a mut Accounts, global_wallet: &'a mut GlobalWallet, account_pk: &'a [u8; 32], -) -> Option<&'a mut ZapWallet> { +) -> Option<&'a ZapWallet> { let cur_acc = accounts.get_account_mut_optimized(account_pk)?; if let Some(wallet) = &mut cur_acc.wallet { return Some(wallet); } - global_wallet.wallet.as_mut() + global_wallet.wallet.as_ref() } pub fn get_current_wallet<'a>( @@ -98,10 +98,7 @@ impl Wallet { } } - pub fn pay_invoice( - &mut self, - invoice: &str, - ) -> Promise> { + pub fn pay_invoice(&self, invoice: &str) -> Promise> { pay_invoice( self.wallet.clone(), PayInvoiceRequest::new(invoice.to_owned()), diff --git a/crates/notedeck/src/zaps/cache.rs b/crates/notedeck/src/zaps/cache.rs index 24569d5..5af9443 100644 --- a/crates/notedeck/src/zaps/cache.rs +++ b/crates/notedeck/src/zaps/cache.rs @@ -4,7 +4,7 @@ use nwc::nostr::nips::nip47::PayInvoiceResponse; use poll_promise::Promise; use tokio::task::JoinError; -use crate::{get_wallet_for_mut, Accounts, GlobalWallet, ZapError}; +use crate::{get_wallet_for, Accounts, GlobalWallet, ZapError}; use super::{ networking::{fetch_invoice_lnurl, fetch_invoice_lud16, FetchedInvoice, FetchingInvoice}, @@ -43,8 +43,7 @@ fn process_event( req_noteid, invoice, } => { - let Some(wallet) = get_wallet_for_mut(accounts, global_wallet, &zap_ctx.key.sender) - else { + let Some(wallet) = get_wallet_for(accounts, global_wallet, &zap_ctx.key.sender) else { return NextState::Event(EventResponse { id, event: Err(ZappingError::SenderNoWallet), diff --git a/crates/notedeck_columns/src/actionbar.rs b/crates/notedeck_columns/src/actionbar.rs index deb8a25..f18c1a3 100644 --- a/crates/notedeck_columns/src/actionbar.rs +++ b/crates/notedeck_columns/src/actionbar.rs @@ -13,8 +13,8 @@ use crate::{ use enostr::{NoteId, Pubkey, RelayPool}; use nostrdb::{Ndb, NoteKey, Transaction}; use notedeck::{ - get_wallet_for_mut, note::ZapTargetAmount, Accounts, GlobalWallet, Images, NoteAction, - NoteCache, NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps, + get_wallet_for, note::ZapTargetAmount, Accounts, GlobalWallet, Images, NoteAction, NoteCache, + NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps, }; use tracing::error; @@ -106,7 +106,7 @@ fn execute_note_action( match &zap_action { ZapAction::Send(target) => 'a: { - let Some(wallet) = get_wallet_for_mut(accounts, global_wallet, sender.bytes()) + let Some(wallet) = get_wallet_for(accounts, global_wallet, sender.bytes()) else { zaps.send_error( sender.bytes(),