From 1dddc9971ff249a8ce5d233546e8587720dfd55b Mon Sep 17 00:00:00 2001 From: findolor Date: Tue, 29 Oct 2024 13:43:40 +0300 Subject: [PATCH] feat: update orders list function to take in multiple subgraphs --- tauri-app/src-tauri/src/commands/order.rs | 35 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tauri-app/src-tauri/src/commands/order.rs b/tauri-app/src-tauri/src/commands/order.rs index 0a121b535..0f6429923 100644 --- a/tauri-app/src-tauri/src/commands/order.rs +++ b/tauri-app/src-tauri/src/commands/order.rs @@ -1,6 +1,7 @@ use crate::error::CommandResult; use crate::{toast::toast_error, transaction_status::TransactionStatusNoticeRwLock}; use alloy::primitives::Bytes; +use futures::future::join_all; use rain_orderbook_app_settings::{deployment::Deployment, scenario::Scenario}; use rain_orderbook_common::{ add_order::AddOrderArgs, csv::TryIntoCsv, dotrain_order::DotrainOrder, @@ -14,16 +15,36 @@ use tauri::AppHandle; #[tauri::command] pub async fn orders_list( - subgraph_args: SubgraphArgs, + subgraph_args_list: Vec, filter_args: OrdersListFilterArgs, pagination_args: PaginationArgs, ) -> CommandResult> { - let orders = subgraph_args - .to_subgraph_client() - .await? - .orders_list(filter_args, pagination_args) - .await?; - Ok(orders) + let clients_futures = subgraph_args_list + .into_iter() + .map(|args| async move { args.to_subgraph_client().await }); + let clients = join_all(clients_futures).await; + let valid_clients: Vec<_> = clients.into_iter().filter_map(Result::ok).collect(); + + let futures = valid_clients.into_iter().map(|client| { + let filter_args = filter_args.clone(); + let pagination_args = pagination_args.clone(); + async move { client.orders_list(filter_args, pagination_args).await } + }); + let results = join_all(futures).await; + + let mut all_orders: Vec = results + .into_iter() + .filter_map(Result::ok) + .flatten() + .collect(); + + all_orders.sort_by(|a, b| { + let a_timestamp = a.timestamp_added.0.parse::().unwrap_or(0); + let b_timestamp = b.timestamp_added.0.parse::().unwrap_or(0); + b_timestamp.cmp(&a_timestamp) + }); + + Ok(all_orders) } #[tauri::command]