notedeck

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

commit 5bddf83655ed834304e30bcc00eaaa2282ad07f4
parent 0adaafd52384f5b7a3867eef0a8c797eac4147d9
Author: kernelkind <kernelkind@gmail.com>
Date:   Wed, 16 Apr 2025 16:13:18 -0400

extend `ZapAction`

going to need amounts for configurable zaps

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/lib.rs | 4+++-
Mcrates/notedeck/src/note/action.rs | 8+++++++-
Mcrates/notedeck/src/note/mod.rs | 2+-
Mcrates/notedeck/src/zaps/cache.rs | 11+++++++++++
Mcrates/notedeck_columns/src/actionbar.rs | 15++++++++-------
Mcrates/notedeck_ui/src/note/mod.rs | 6+++++-
6 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs @@ -66,7 +66,9 @@ pub use user_account::UserAccount; pub use wallet::{ get_wallet_for_mut, GlobalWallet, Wallet, WalletError, WalletState, WalletType, WalletUIState, }; -pub use zaps::{AnyZapState, NoteZapTarget, NoteZapTargetOwned, ZapTarget, ZappingError}; +pub use zaps::{ + AnyZapState, NoteZapTarget, NoteZapTargetOwned, ZapTarget, ZapTargetOwned, ZappingError, +}; // export libs pub use enostr; diff --git a/crates/notedeck/src/note/action.rs b/crates/notedeck/src/note/action.rs @@ -28,6 +28,12 @@ pub enum NoteAction { #[derive(Debug, Eq, PartialEq, Clone)] pub enum ZapAction { - Send(NoteZapTargetOwned), + Send(ZapTargetAmount), ClearError(NoteZapTargetOwned), } + +#[derive(Debug, Eq, PartialEq, Clone)] +pub struct ZapTargetAmount { + pub target: NoteZapTargetOwned, + pub specified_msats: Option<u64>, // if None use default amount +} diff --git a/crates/notedeck/src/note/mod.rs b/crates/notedeck/src/note/mod.rs @@ -1,7 +1,7 @@ mod action; mod context; -pub use action::{NoteAction, ZapAction}; +pub use action::{NoteAction, ZapAction, ZapTargetAmount}; pub use context::{BroadcastContext, ContextSelection, NoteContextSelection}; use crate::{notecache::NoteCache, zaps::Zaps, Images}; diff --git a/crates/notedeck/src/zaps/cache.rs b/crates/notedeck/src/zaps/cache.rs @@ -606,6 +606,17 @@ impl From<&ZapTarget<'_>> for ZapTargetOwned { } } +impl<'a> From<&'a ZapTargetOwned> for ZapTarget<'a> { + fn from(value: &'a ZapTargetOwned) -> Self { + match value { + ZapTargetOwned::Profile(pubkey) => ZapTarget::Profile(pubkey.bytes()), + ZapTargetOwned::Note(note_zap_target_owned) => { + ZapTarget::Note(note_zap_target_owned.into()) + } + } + } +} + impl From<&ZapKey<'_>> for ZapKeyOwned { fn from(value: &ZapKey) -> Self { Self { diff --git a/crates/notedeck_columns/src/actionbar.rs b/crates/notedeck_columns/src/actionbar.rs @@ -7,8 +7,8 @@ use crate::{ use enostr::{Pubkey, RelayPool}; use nostrdb::{Ndb, NoteKey, Transaction}; use notedeck::{ - get_wallet_for_mut, Accounts, GlobalWallet, NoteAction, NoteCache, NoteZapTargetOwned, - UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps, + get_wallet_for_mut, note::ZapTargetAmount, Accounts, GlobalWallet, NoteAction, NoteCache, + NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps, }; use tracing::error; @@ -88,7 +88,7 @@ fn execute_note_action( } else { zaps.send_error( sender.bytes(), - ZapTarget::Note(target.into()), + ZapTarget::Note((&target.target).into()), ZappingError::SenderNoWallet, ); } @@ -146,12 +146,13 @@ pub fn execute_and_process_note_action( } } -fn send_zap(sender: &Pubkey, zaps: &mut Zaps, pool: &RelayPool, target: &NoteZapTargetOwned) { - let default_zap_msats = 10_000; // TODO(kernelkind): allow the user to set this default - let zap_target = ZapTarget::Note(target.into()); +fn send_zap(sender: &Pubkey, zaps: &mut Zaps, pool: &RelayPool, target_amount: &ZapTargetAmount) { + let zap_target = ZapTarget::Note((&target_amount.target).into()); + + let msats = target_amount.specified_msats.unwrap_or(10_000); let sender_relays: Vec<String> = pool.relays.iter().map(|r| r.url().to_string()).collect(); - zaps.send_zap(sender.bytes(), sender_relays, zap_target, default_zap_msats); + zaps.send_zap(sender.bytes(), sender_relays, zap_target, msats); } fn clear_zap_error(sender: &Pubkey, zaps: &mut Zaps, target: &NoteZapTargetOwned) { diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs @@ -10,6 +10,7 @@ use crate::{ pub use contents::{render_note_contents, render_note_preview, NoteContents}; pub use context::NoteContextButton; +use notedeck::note::ZapTargetAmount; pub use options::NoteOptions; pub use reply_description::reply_desc; @@ -680,7 +681,10 @@ fn render_note_actionbar( break 's Some(NoteAction::Zap(ZapAction::ClearError(target))); } - Some(NoteAction::Zap(ZapAction::Send(target))) + Some(NoteAction::Zap(ZapAction::Send(ZapTargetAmount { + target, + specified_msats: None, + }))) }) }