notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit ff0428550b73af1670d26b3873959f18f2588304
parent 56cbf68ea510e325831471bc340e9eb4deb26b41
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 23 Jul 2025 10:30:35 -0700

fix missing zap button

Changelog-Fixed: Fix missing zap button
Fixes: 397bfce8173c ("add `Accounts` to `NoteContext`")
Fixes: https://github.com/damus-io/notedeck/issues/1021
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mcrates/notedeck/src/account/accounts.rs | 4++++
Mcrates/notedeck/src/lib.rs | 4++--
Mcrates/notedeck/src/note/mod.rs | 2++
Mcrates/notedeck/src/wallet.rs | 13++++++++++++-
Mcrates/notedeck_columns/src/nav.rs | 1+
Mcrates/notedeck_columns/src/ui/note/post.rs | 1+
Mcrates/notedeck_columns/src/ui/wallet.rs | 6+++---
Mcrates/notedeck_dave/src/ui/dave.rs | 1+
Mcrates/notedeck_ui/src/note/mod.rs | 50++++++++++++++++++++++++++++----------------------
9 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/crates/notedeck/src/account/accounts.rs b/crates/notedeck/src/account/accounts.rs @@ -207,6 +207,10 @@ impl Accounts { self.cache.selected_mut() } + pub fn get_selected_wallet(&self) -> Option<&ZapWallet> { + self.cache.selected().wallet.as_ref() + } + pub fn get_selected_wallet_mut(&mut self) -> Option<&mut ZapWallet> { self.cache.selected_mut().wallet.as_mut() } diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs @@ -72,8 +72,8 @@ 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, GlobalWallet, Wallet, WalletError, WalletType, - WalletUIState, ZapWallet, + get_current_wallet, get_current_wallet_mut, get_wallet_for, GlobalWallet, Wallet, WalletError, + WalletType, WalletUIState, ZapWallet, }; pub use zaps::{ get_current_default_msats, AnyZapState, DefaultZapError, DefaultZapMsats, NoteZapTarget, diff --git a/crates/notedeck/src/note/mod.rs b/crates/notedeck/src/note/mod.rs @@ -5,6 +5,7 @@ pub use action::{MediaAction, NoteAction, ScrollInfo, ZapAction, ZapTargetAmount pub use context::{BroadcastContext, ContextSelection, NoteContextSelection}; use crate::Accounts; +use crate::GlobalWallet; use crate::JobPool; use crate::Localization; use crate::UnknownIds; @@ -20,6 +21,7 @@ use std::fmt; pub struct NoteContext<'d> { pub ndb: &'d Ndb, pub accounts: &'d Accounts, + pub global_wallet: &'d GlobalWallet, pub i18n: &'d mut Localization, pub img_cache: &'d mut Images, pub note_cache: &'d mut NoteCache, diff --git a/crates/notedeck/src/wallet.rs b/crates/notedeck/src/wallet.rs @@ -24,7 +24,7 @@ pub fn get_wallet_for<'a>( global_wallet.wallet.as_ref() } -pub fn get_current_wallet<'a>( +pub fn get_current_wallet_mut<'a>( accounts: &'a mut Accounts, global_wallet: &'a mut GlobalWallet, ) -> Option<&'a mut ZapWallet> { @@ -35,6 +35,17 @@ pub fn get_current_wallet<'a>( Some(wallet) } +pub fn get_current_wallet<'a>( + accounts: &'a Accounts, + global_wallet: &'a GlobalWallet, +) -> Option<&'a ZapWallet> { + let Some(wallet) = accounts.get_selected_wallet() else { + return global_wallet.wallet.as_ref(); + }; + + Some(wallet) +} + #[derive(Clone, Eq, PartialEq, Debug)] pub enum WalletType { Auto, diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -514,6 +514,7 @@ fn render_nav_body( unknown_ids: ctx.unknown_ids, clipboard: ctx.clipboard, i18n: ctx.i18n, + global_wallet: ctx.global_wallet, }; match top { Route::Timeline(kind) => { diff --git a/crates/notedeck_columns/src/ui/note/post.rs b/crates/notedeck_columns/src/ui/note/post.rs @@ -802,6 +802,7 @@ mod preview { let mut note_context = NoteContext { ndb: app.ndb, accounts: app.accounts, + global_wallet: app.global_wallet, img_cache: app.img_cache, note_cache: app.note_cache, zaps: app.zaps, diff --git a/crates/notedeck_columns/src/ui/wallet.rs b/crates/notedeck_columns/src/ui/wallet.rs @@ -1,6 +1,6 @@ use egui::{vec2, CornerRadius, Layout}; use notedeck::{ - get_current_wallet, tr, Accounts, DefaultZapMsats, GlobalWallet, Localization, + get_current_wallet_mut, tr, Accounts, DefaultZapMsats, GlobalWallet, Localization, NotedeckTextStyle, PendingDefaultZapState, Wallet, WalletError, WalletUIState, ZapWallet, }; @@ -103,7 +103,7 @@ impl WalletAction { } WalletAction::SetDefaultZapSats(new_default) => 's: { let sats = { - let Some(wallet) = get_current_wallet(accounts, global_wallet) else { + let Some(wallet) = get_current_wallet_mut(accounts, global_wallet) else { break 's; }; @@ -138,7 +138,7 @@ impl WalletAction { global_wallet.save_wallet(); } WalletAction::EditDefaultZaps => 's: { - let Some(wallet) = get_current_wallet(accounts, global_wallet) else { + let Some(wallet) = get_current_wallet_mut(accounts, global_wallet) else { break 's; }; diff --git a/crates/notedeck_dave/src/ui/dave.rs b/crates/notedeck_dave/src/ui/dave.rs @@ -220,6 +220,7 @@ impl<'a> DaveUi<'a> { unknown_ids: ctx.unknown_ids, clipboard: ctx.clipboard, i18n: ctx.i18n, + global_wallet: ctx.global_wallet, }; let txn = Transaction::new(note_context.ndb).unwrap(); diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs @@ -13,9 +13,12 @@ use crate::{ pub use contents::{render_note_contents, render_note_preview, NoteContents}; pub use context::NoteContextButton; +use notedeck::get_current_wallet; use notedeck::note::MediaAction; use notedeck::note::ZapTargetAmount; use notedeck::ui::is_narrow; +use notedeck::Accounts; +use notedeck::GlobalWallet; use notedeck::Images; use notedeck::Localization; pub use options::NoteOptions; @@ -451,18 +454,13 @@ impl<'a, 'd> NoteView<'a, 'd> { note_action = contents.action.or(note_action); if self.options().contains(NoteOptions::ActionBar) { - let zapper = { - let cur_acc = self.note_context.accounts.get_selected_account(); - let has_wallet = cur_acc.wallet.is_some(); - - has_wallet.then_some(Zapper { - zaps: self.note_context.zaps, - cur_acc: cur_acc.keypair(), - }) - }; note_action = render_note_actionbar( ui, - zapper, + get_zapper( + self.note_context.accounts, + self.note_context.global_wallet, + self.note_context.zaps, + ), self.note.id(), self.note.pubkey(), note_key, @@ -531,20 +529,14 @@ impl<'a, 'd> NoteView<'a, 'd> { note_action = contents.action.or(note_action); - let zapper = { - let cur_acc = self.note_context.accounts.get_selected_account(); - let has_wallet = cur_acc.wallet.is_some(); - - has_wallet.then_some(Zapper { - zaps: self.note_context.zaps, - cur_acc: cur_acc.keypair(), - }) - }; - if self.options().contains(NoteOptions::ActionBar) { note_action = render_note_actionbar( ui, - zapper, + get_zapper( + self.note_context.accounts, + self.note_context.global_wallet, + self.note_context.zaps, + ), self.note.id(), self.note.pubkey(), note_key, @@ -611,6 +603,20 @@ impl<'a, 'd> NoteView<'a, 'd> { } } +fn get_zapper<'a>( + accounts: &'a Accounts, + global_wallet: &'a GlobalWallet, + zaps: &'a Zaps, +) -> Option<Zapper<'a>> { + let has_wallet = get_current_wallet(accounts, global_wallet).is_some(); + let cur_acc = accounts.get_selected_account(); + + has_wallet.then_some(Zapper { + zaps, + cur_acc: cur_acc.keypair(), + }) +} + fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option<Note<'a>> { if note.kind() != 6 { return None; @@ -769,7 +775,7 @@ struct Zapper<'a> { #[profiling::function] fn render_note_actionbar( ui: &mut egui::Ui, - zapper: Option<Zapper>, + zapper: Option<Zapper<'_>>, note_id: &[u8; 32], note_pubkey: &[u8; 32], note_key: NoteKey,