Skip to content

Commit

Permalink
Include non-swap state in list payments query (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross authored Jan 21, 2025
1 parent 9599801 commit 16ac13e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,32 @@ fn filter_to_where_clause(req: &ListPaymentsRequest) -> (String, Vec<Box<dyn ToS

if let Some(states) = &req.states {
if !states.is_empty() {
let states_hash: HashSet<i8> = HashSet::from_iter(states.iter().map(|s| *s as i8));
where_clause.push(format!(
"COALESCE(rs.state, ss.state, cs.state) in ({})",
states_hash
.iter()
.map(|t| format!("{}", t))
.collect::<Vec<_>>()
.join(", ")
));
let deduped_states: Vec<PaymentState> = states
.clone()
.into_iter()
.collect::<HashSet<PaymentState>>()
.into_iter()
.collect();
let states_param = deduped_states
.iter()
.map(|t| (*t as i8).to_string())
.collect::<Vec<_>>()
.join(", ");
let tx_comfirmed_param = deduped_states
.iter()
.filter_map(|state| match state {
PaymentState::Pending | PaymentState::Complete => {
Some(((*state == PaymentState::Complete) as i8).to_string())
}
_ => None,
})
.collect::<Vec<_>>()
.join(", ");
let states_query = match tx_comfirmed_param.is_empty() {
true => format!("COALESCE(rs.state, ss.state, cs.state) in ({states_param})"),
false => format!("(COALESCE(rs.id, ss.id, cs.id) IS NULL AND ptx.is_confirmed in ({tx_comfirmed_param}) OR COALESCE(rs.state, ss.state, cs.state) in ({states_param}))"),
};
where_clause.push(states_query);
}
}

Expand Down

0 comments on commit 16ac13e

Please sign in to comment.