wallet: remove unnecessary mut

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-06-26 13:37:30 -04:00
parent 84026824b2
commit b9cfe87974
4 changed files with 10 additions and 14 deletions

View File

@@ -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::{

View File

@@ -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<Result<PayInvoiceResponse, nwc::Error>> {
pub fn pay_invoice(&self, invoice: &str) -> Promise<Result<PayInvoiceResponse, nwc::Error>> {
pay_invoice(
self.wallet.clone(),
PayInvoiceRequest::new(invoice.to_owned()),

View File

@@ -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),

View File

@@ -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(),