mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
wallet: remove unnecessary mut
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -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 urls::{supported_mime_hosted_at_url, SupportedMimeType, UrlMimes};
|
||||||
pub use user_account::UserAccount;
|
pub use user_account::UserAccount;
|
||||||
pub use wallet::{
|
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,
|
WalletUIState, ZapWallet,
|
||||||
};
|
};
|
||||||
pub use zaps::{
|
pub use zaps::{
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ use tokio::sync::RwLock;
|
|||||||
|
|
||||||
use crate::{zaps::UserZapMsats, Accounts, DataPath, DefaultZapMsats, TokenHandler};
|
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,
|
accounts: &'a mut Accounts,
|
||||||
global_wallet: &'a mut GlobalWallet,
|
global_wallet: &'a mut GlobalWallet,
|
||||||
account_pk: &'a [u8; 32],
|
account_pk: &'a [u8; 32],
|
||||||
) -> Option<&'a mut ZapWallet> {
|
) -> Option<&'a ZapWallet> {
|
||||||
let cur_acc = accounts.get_account_mut_optimized(account_pk)?;
|
let cur_acc = accounts.get_account_mut_optimized(account_pk)?;
|
||||||
|
|
||||||
if let Some(wallet) = &mut cur_acc.wallet {
|
if let Some(wallet) = &mut cur_acc.wallet {
|
||||||
return Some(wallet);
|
return Some(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
global_wallet.wallet.as_mut()
|
global_wallet.wallet.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_wallet<'a>(
|
pub fn get_current_wallet<'a>(
|
||||||
@@ -98,10 +98,7 @@ impl Wallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pay_invoice(
|
pub fn pay_invoice(&self, invoice: &str) -> Promise<Result<PayInvoiceResponse, nwc::Error>> {
|
||||||
&mut self,
|
|
||||||
invoice: &str,
|
|
||||||
) -> Promise<Result<PayInvoiceResponse, nwc::Error>> {
|
|
||||||
pay_invoice(
|
pay_invoice(
|
||||||
self.wallet.clone(),
|
self.wallet.clone(),
|
||||||
PayInvoiceRequest::new(invoice.to_owned()),
|
PayInvoiceRequest::new(invoice.to_owned()),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use nwc::nostr::nips::nip47::PayInvoiceResponse;
|
|||||||
use poll_promise::Promise;
|
use poll_promise::Promise;
|
||||||
use tokio::task::JoinError;
|
use tokio::task::JoinError;
|
||||||
|
|
||||||
use crate::{get_wallet_for_mut, Accounts, GlobalWallet, ZapError};
|
use crate::{get_wallet_for, Accounts, GlobalWallet, ZapError};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
networking::{fetch_invoice_lnurl, fetch_invoice_lud16, FetchedInvoice, FetchingInvoice},
|
networking::{fetch_invoice_lnurl, fetch_invoice_lud16, FetchedInvoice, FetchingInvoice},
|
||||||
@@ -43,8 +43,7 @@ fn process_event(
|
|||||||
req_noteid,
|
req_noteid,
|
||||||
invoice,
|
invoice,
|
||||||
} => {
|
} => {
|
||||||
let Some(wallet) = get_wallet_for_mut(accounts, global_wallet, &zap_ctx.key.sender)
|
let Some(wallet) = get_wallet_for(accounts, global_wallet, &zap_ctx.key.sender) else {
|
||||||
else {
|
|
||||||
return NextState::Event(EventResponse {
|
return NextState::Event(EventResponse {
|
||||||
id,
|
id,
|
||||||
event: Err(ZappingError::SenderNoWallet),
|
event: Err(ZappingError::SenderNoWallet),
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use crate::{
|
|||||||
use enostr::{NoteId, Pubkey, RelayPool};
|
use enostr::{NoteId, Pubkey, RelayPool};
|
||||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
get_wallet_for_mut, note::ZapTargetAmount, Accounts, GlobalWallet, Images, NoteAction,
|
get_wallet_for, note::ZapTargetAmount, Accounts, GlobalWallet, Images, NoteAction, NoteCache,
|
||||||
NoteCache, NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps,
|
NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps,
|
||||||
};
|
};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ fn execute_note_action(
|
|||||||
|
|
||||||
match &zap_action {
|
match &zap_action {
|
||||||
ZapAction::Send(target) => 'a: {
|
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 {
|
else {
|
||||||
zaps.send_error(
|
zaps.send_error(
|
||||||
sender.bytes(),
|
sender.bytes(),
|
||||||
|
|||||||
Reference in New Issue
Block a user