From 5f638aec3725b25f1a1b0ce1d9e6e5e683fd4add Mon Sep 17 00:00:00 2001 From: Ross Savage <551697+dangeross@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:18:11 +0200 Subject: [PATCH] Fix list payments filter (#529) --- cli/src/commands.rs | 7 ++++++- lib/core/src/model.rs | 1 + lib/core/src/persist/mod.rs | 14 ++++---------- packages/react-native/example/App.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 0e829ae..39ff2d6 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -86,6 +86,10 @@ pub(crate) enum Command { }, /// List incoming and outgoing payments ListPayments { + /// The optional payment type filter. Either "send" or "receive" + #[clap(name = "filter", short = 'r', long = "filter")] + filters: Option>, + /// The optional from unix timestamp #[clap(name = "from_timestamp", short = 'f', long = "from")] from_timestamp: Option, @@ -445,6 +449,7 @@ pub(crate) async fn handle_command( command_result!(format!("Message was signed by pubkey: {}", res.is_valid)) } Command::ListPayments { + filters, from_timestamp, to_timestamp, limit, @@ -460,7 +465,7 @@ pub(crate) async fn handle_command( let payments = sdk .list_payments(&ListPaymentsRequest { - filters: None, + filters, from_timestamp, to_timestamp, limit, diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 93f6720..f83bd63 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -943,6 +943,7 @@ impl FromSql for PaymentState { } #[derive(Debug, Copy, Clone, Eq, EnumString, Display, Hash, PartialEq, Serialize)] +#[strum(serialize_all = "lowercase")] pub enum PaymentType { Receive = 0, Send = 1, diff --git a/lib/core/src/persist/mod.rs b/lib/core/src/persist/mod.rs index 10a73cc..1446aa8 100644 --- a/lib/core/src/persist/mod.rs +++ b/lib/core/src/persist/mod.rs @@ -478,23 +478,17 @@ fn filter_to_where_clause(req: &ListPaymentsRequest) -> (String, Vec = HashSet::new(); + let mut type_filter_clause: HashSet = HashSet::new(); + for type_filter in filters { - match type_filter { - PaymentType::Send => { - type_filter_clause.insert(PaymentType::Send); - } - PaymentType::Receive => { - type_filter_clause.insert(PaymentType::Receive); - } - } + type_filter_clause.insert(*type_filter as i8); } where_clause.push(format!( "ptx.payment_type in ({})", type_filter_clause .iter() - .map(|t| format!("'{}'", t)) + .map(|t| format!("{}", t)) .collect::>() .join(", ") )); diff --git a/packages/react-native/example/App.js b/packages/react-native/example/App.js index 1678625..2856a90 100644 --- a/packages/react-native/example/App.js +++ b/packages/react-native/example/App.js @@ -76,7 +76,7 @@ const App = () => { addLine("getInfo", JSON.stringify(getInfoRes)) // Historical payments list - let payments = listPayments({}) + let payments = await listPayments({}) // Register for events listenerId = await addEventListener(eventHandler)