From fcfc888f266b98da73d41ed7d1da9253cc2482c3 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sat, 27 Jan 2024 19:36:38 -0700 Subject: [PATCH 1/2] feat(tauri): list orders backend --- crates/subgraph/src/types/orders.rs | 15 ++++++++------- tauri-app/src-tauri/src/commands/mod.rs | 1 + tauri-app/src-tauri/src/commands/order.rs | 17 +++++++++++++++++ tauri-app/src-tauri/src/main.rs | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 tauri-app/src-tauri/src/commands/order.rs diff --git a/crates/subgraph/src/types/orders.rs b/crates/subgraph/src/types/orders.rs index e62cfad56..51c4c284e 100644 --- a/crates/subgraph/src/types/orders.rs +++ b/crates/subgraph/src/types/orders.rs @@ -1,4 +1,5 @@ use crate::schema; +use serde::Serialize; use typeshare::typeshare; #[typeshare] @@ -10,7 +11,7 @@ pub struct OrdersQuery { } #[typeshare] -#[derive(cynic::QueryFragment, Debug)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] pub struct Order { pub id: cynic::Id, pub timestamp: BigInt, @@ -29,13 +30,13 @@ pub struct Order { } #[typeshare] -#[derive(cynic::QueryFragment, Debug)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] pub struct Transaction { pub id: cynic::Id, } #[typeshare] -#[derive(cynic::QueryFragment, Debug, Clone)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] #[cynic(graphql_type = "IO")] pub struct Io { pub token: Erc20, @@ -44,19 +45,19 @@ pub struct Io { } #[typeshare] -#[derive(cynic::QueryFragment, Debug, Clone)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] pub struct Vault { pub id: cynic::Id, } #[typeshare] -#[derive(cynic::QueryFragment, Debug, Clone)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] pub struct TokenVault { pub balance: BigInt, } #[typeshare] -#[derive(cynic::QueryFragment, Debug, Clone)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] #[cynic(graphql_type = "ERC20")] pub struct Erc20 { pub id: cynic::Id, @@ -65,7 +66,7 @@ pub struct Erc20 { } #[typeshare] -#[derive(cynic::QueryFragment, Debug)] +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] pub struct Account { pub id: Bytes, } diff --git a/tauri-app/src-tauri/src/commands/mod.rs b/tauri-app/src-tauri/src/commands/mod.rs index 35eecf896..12c404239 100644 --- a/tauri-app/src-tauri/src/commands/mod.rs +++ b/tauri-app/src-tauri/src/commands/mod.rs @@ -1,3 +1,4 @@ pub mod chain; pub mod vault; pub mod wallet; +pub mod order; \ No newline at end of file diff --git a/tauri-app/src-tauri/src/commands/order.rs b/tauri-app/src-tauri/src/commands/order.rs new file mode 100644 index 000000000..e77e84a4e --- /dev/null +++ b/tauri-app/src-tauri/src/commands/order.rs @@ -0,0 +1,17 @@ +use rain_orderbook_common::{ + subgraph::SubgraphArgs +}; +use rain_orderbook_subgraph_queries::types::{ + orders::Order as OrdersListItem, +}; + +#[tauri::command] +pub async fn orders_list(subgraph_args: SubgraphArgs) -> Result, String> { + subgraph_args + .to_subgraph_client() + .await + .map_err(|_| String::from("Subgraph URL is invalid"))? + .orders() + .await + .map_err(|e| e.to_string()) +} \ No newline at end of file diff --git a/tauri-app/src-tauri/src/main.rs b/tauri-app/src-tauri/src/main.rs index 06219162a..3992ebe6e 100644 --- a/tauri-app/src-tauri/src/main.rs +++ b/tauri-app/src-tauri/src/main.rs @@ -7,6 +7,7 @@ pub mod transaction_status; mod commands; use commands::chain::get_chainid; use commands::vault::{vault_deposit, vault_detail, vault_withdraw, vaults_list}; +use commands::order::{orders_list}; use commands::wallet::get_address_from_ledger; fn main() { @@ -16,6 +17,7 @@ fn main() { vault_detail, vault_deposit, vault_withdraw, + orders_list, get_address_from_ledger, get_chainid ]) From 5c34ddb2b8b67801d4891281a6c344f2483e6764 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sat, 27 Jan 2024 19:53:25 -0700 Subject: [PATCH 2/2] feat(tauri/ui): orders list page --- tauri-app/src/lib/stores/ordersList.ts | 30 +++++++++ tauri-app/src/routes/orders/+page.svelte | 86 +++++++++++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 tauri-app/src/lib/stores/ordersList.ts diff --git a/tauri-app/src/lib/stores/ordersList.ts b/tauri-app/src/lib/stores/ordersList.ts new file mode 100644 index 000000000..30a479a96 --- /dev/null +++ b/tauri-app/src/lib/stores/ordersList.ts @@ -0,0 +1,30 @@ +import { get, writable } from 'svelte/store'; +import type { Order as OrdersListItem } from '$lib/typeshare/orders'; +import { invoke } from '@tauri-apps/api'; +import { subgraphUrl } from './settings'; + +function useOrdersListStore() { + const STORAGE_KEY = "orders.ordersList"; + + const { subscribe, set } = writable>(localStorage.getItem(STORAGE_KEY) ? JSON.parse(localStorage.getItem(STORAGE_KEY) as string) : []); + + subscribe(value => { + if(value) { + localStorage.setItem(STORAGE_KEY, JSON.stringify(value)); + } else { + localStorage.setItem(STORAGE_KEY, JSON.stringify([])); + } + }); + + async function refetch() { + const res: Array = await invoke("orders_list", {subgraphArgs: { url: get(subgraphUrl)} }); + set(res); + } + + return { + subscribe, + refetch + } +} + +export const ordersList = useOrdersListStore(); \ No newline at end of file diff --git a/tauri-app/src/routes/orders/+page.svelte b/tauri-app/src/routes/orders/+page.svelte index e7f7f5bff..aeb45d8a0 100644 --- a/tauri-app/src/routes/orders/+page.svelte +++ b/tauri-app/src/routes/orders/+page.svelte @@ -1,8 +1,90 @@ -Orders +
+
+

Orders

+
+
+ + +
+
+
+ +{#if $ordersList.length === 0} +
No Orders found
+{:else} + + + Active + Order ID + Owner + Added At + Input Token(s) + Output Token(s) + + + {#each $ordersList as order} + gotoOrder(order.id)}> + + {#if order.order_active} + Active + {:else} + Inactive + {/if} + + {order.id} + {order.owner.id} + + {dayjs(BigInt(order.timestamp) * BigInt('1000')) + .utc(true) + .local() + .format('DD/MM/YYYY h:mm A')} + + + {order.valid_inputs?.map((t) => t.token.symbol)} + + + {order.valid_outputs?.map((t) => t.token.symbol)} + + + {/each} + +
+{/if}