mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-22 02:34:20 +01:00
extend ZapAction
going to need amounts for configurable zaps Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -66,7 +66,9 @@ pub use user_account::UserAccount;
|
|||||||
pub use wallet::{
|
pub use wallet::{
|
||||||
get_wallet_for_mut, GlobalWallet, Wallet, WalletError, WalletState, WalletType, WalletUIState,
|
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
|
// export libs
|
||||||
pub use enostr;
|
pub use enostr;
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ pub enum NoteAction {
|
|||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum ZapAction {
|
pub enum ZapAction {
|
||||||
Send(NoteZapTargetOwned),
|
Send(ZapTargetAmount),
|
||||||
ClearError(NoteZapTargetOwned),
|
ClearError(NoteZapTargetOwned),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
|
pub struct ZapTargetAmount {
|
||||||
|
pub target: NoteZapTargetOwned,
|
||||||
|
pub specified_msats: Option<u64>, // if None use default amount
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
mod action;
|
mod action;
|
||||||
mod context;
|
mod context;
|
||||||
|
|
||||||
pub use action::{NoteAction, ZapAction};
|
pub use action::{NoteAction, ZapAction, ZapTargetAmount};
|
||||||
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
|
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
|
||||||
|
|
||||||
use crate::{notecache::NoteCache, zaps::Zaps, Images};
|
use crate::{notecache::NoteCache, zaps::Zaps, Images};
|
||||||
|
|||||||
@@ -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 {
|
impl From<&ZapKey<'_>> for ZapKeyOwned {
|
||||||
fn from(value: &ZapKey) -> Self {
|
fn from(value: &ZapKey) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ use crate::{
|
|||||||
use enostr::{Pubkey, RelayPool};
|
use enostr::{Pubkey, RelayPool};
|
||||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
get_wallet_for_mut, Accounts, GlobalWallet, NoteAction, NoteCache, NoteZapTargetOwned,
|
get_wallet_for_mut, note::ZapTargetAmount, Accounts, GlobalWallet, NoteAction, NoteCache,
|
||||||
UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps,
|
NoteZapTargetOwned, UnknownIds, ZapAction, ZapTarget, ZappingError, Zaps,
|
||||||
};
|
};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ fn execute_note_action(
|
|||||||
} else {
|
} else {
|
||||||
zaps.send_error(
|
zaps.send_error(
|
||||||
sender.bytes(),
|
sender.bytes(),
|
||||||
ZapTarget::Note(target.into()),
|
ZapTarget::Note((&target.target).into()),
|
||||||
ZappingError::SenderNoWallet,
|
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) {
|
fn send_zap(sender: &Pubkey, zaps: &mut Zaps, pool: &RelayPool, target_amount: &ZapTargetAmount) {
|
||||||
let default_zap_msats = 10_000; // TODO(kernelkind): allow the user to set this default
|
let zap_target = ZapTarget::Note((&target_amount.target).into());
|
||||||
let zap_target = ZapTarget::Note(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();
|
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) {
|
fn clear_zap_error(sender: &Pubkey, zaps: &mut Zaps, target: &NoteZapTargetOwned) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::{
|
|||||||
|
|
||||||
pub use contents::{render_note_contents, render_note_preview, NoteContents};
|
pub use contents::{render_note_contents, render_note_preview, NoteContents};
|
||||||
pub use context::NoteContextButton;
|
pub use context::NoteContextButton;
|
||||||
|
use notedeck::note::ZapTargetAmount;
|
||||||
pub use options::NoteOptions;
|
pub use options::NoteOptions;
|
||||||
pub use reply_description::reply_desc;
|
pub use reply_description::reply_desc;
|
||||||
|
|
||||||
@@ -680,7 +681,10 @@ fn render_note_actionbar(
|
|||||||
break 's Some(NoteAction::Zap(ZapAction::ClearError(target)));
|
break 's Some(NoteAction::Zap(ZapAction::ClearError(target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(NoteAction::Zap(ZapAction::Send(target)))
|
Some(NoteAction::Zap(ZapAction::Send(ZapTargetAmount {
|
||||||
|
target,
|
||||||
|
specified_msats: None,
|
||||||
|
})))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user