From e26d1c50a55539cc58545716f325b60a291a610a Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Wed, 7 Feb 2024 18:46:56 -0700 Subject: [PATCH 1/4] feat(tauri): order clears list page --- tauri-app/src-tauri/Cargo.lock | 20 +++--- tauri-app/src-tauri/src/commands/mod.rs | 1 + .../src-tauri/src/commands/order_clear.rs | 41 ++++++++++++ tauri-app/src-tauri/src/main.rs | 3 + tauri-app/src/lib/components/Sidebar.svelte | 6 ++ tauri-app/src/lib/stores/orderClearsList.ts | 11 ++++ .../src/routes/order-clears/+page.svelte | 63 +++++++++++++++++++ tauri-app/src/routes/vaults/+page.svelte | 2 +- 8 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 tauri-app/src-tauri/src/commands/order_clear.rs create mode 100644 tauri-app/src/lib/stores/orderClearsList.ts create mode 100644 tauri-app/src/routes/order-clears/+page.svelte diff --git a/tauri-app/src-tauri/Cargo.lock b/tauri-app/src-tauri/Cargo.lock index ac507422d..d6ed5b75f 100644 --- a/tauri-app/src-tauri/Cargo.lock +++ b/tauri-app/src-tauri/Cargo.lock @@ -2293,7 +2293,7 @@ dependencies = [ "lsp-types", "magic_string", "once_cell", - "rain-meta 1.0.0 (git+https://github.com/rainprotocol/rain.metadata.git?rev=42712f1469ff7943ba7abe324216c96b8e8c707a)", + "rain-meta", "regex", "revm", "serde", @@ -6454,12 +6454,12 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rain-meta" version = "1.0.0" +source = "git+https://github.com/rainprotocol/rain.metadata.git?rev=42712f1469ff7943ba7abe324216c96b8e8c707a#42712f1469ff7943ba7abe324216c96b8e8c707a" dependencies = [ "alloy-json-abi 0.5.4", "alloy-primitives 0.5.4", "alloy-sol-types 0.5.4", "anyhow", - "clap", "deflate", "futures", "graphql_client", @@ -6468,27 +6468,23 @@ dependencies = [ "once_cell", "regex", "reqwest", - "schemars", "serde", "serde_bytes", "serde_cbor", "serde_json", "strum 0.24.1", - "tokio", - "tracing", - "tracing-subscriber", "validator", ] [[package]] -name = "rain-meta" -version = "1.0.0" -source = "git+https://github.com/rainprotocol/rain.metadata.git?rev=42712f1469ff7943ba7abe324216c96b8e8c707a#42712f1469ff7943ba7abe324216c96b8e8c707a" +name = "rain-metadata" +version = "0.0.2-alpha.2" dependencies = [ "alloy-json-abi 0.5.4", "alloy-primitives 0.5.4", "alloy-sol-types 0.5.4", "anyhow", + "clap", "deflate", "futures", "graphql_client", @@ -6497,11 +6493,15 @@ dependencies = [ "once_cell", "regex", "reqwest", + "schemars", "serde", "serde_bytes", "serde_cbor", "serde_json", "strum 0.24.1", + "tokio", + "tracing", + "tracing-subscriber", "validator", ] @@ -6566,7 +6566,7 @@ dependencies = [ "dotrain", "forker", "once_cell", - "rain-meta 1.0.0", + "rain-metadata", "rain_interpreter_bindings", "rain_interpreter_dispair", "rain_interpreter_parser", diff --git a/tauri-app/src-tauri/src/commands/mod.rs b/tauri-app/src-tauri/src/commands/mod.rs index abe34cef8..d28a6e1d4 100644 --- a/tauri-app/src-tauri/src/commands/mod.rs +++ b/tauri-app/src-tauri/src/commands/mod.rs @@ -3,3 +3,4 @@ pub mod fork; pub mod order; pub mod vault; pub mod wallet; +pub mod order_clear; \ No newline at end of file diff --git a/tauri-app/src-tauri/src/commands/order_clear.rs b/tauri-app/src-tauri/src/commands/order_clear.rs new file mode 100644 index 000000000..2c40bb83f --- /dev/null +++ b/tauri-app/src-tauri/src/commands/order_clear.rs @@ -0,0 +1,41 @@ +use crate::error::CommandResult; +use rain_orderbook_common::subgraph::SubgraphArgs; +use rain_orderbook_subgraph_client::{ + types::{flattened::{OrderClearFlattened, TryIntoFlattenedError}, order_clears_list}, + WriteCsv, + PaginationArgs, +}; +use std::path::PathBuf; + +#[tauri::command] +pub async fn order_clears_list( + subgraph_args: SubgraphArgs, + pagination_args: PaginationArgs, +) -> CommandResult> { + let order_clears = subgraph_args + .to_subgraph_client() + .await? + .order_clears_list(pagination_args) + .await?; + Ok(order_clears) +} + +#[tauri::command] +pub async fn order_clears_list_write_csv( + path: PathBuf, + subgraph_args: SubgraphArgs, + pagination_args: PaginationArgs, +) -> CommandResult<()> { + let order_clears = subgraph_args + .to_subgraph_client() + .await? + .order_clears_list(pagination_args) + .await?; + let order_clears_flattened: Vec = order_clears + .into_iter() + .map(|o| o.try_into()) + .collect::, TryIntoFlattenedError>>()?; + order_clears_flattened.write_csv(path)?; + + Ok(()) +} \ 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 816a61992..77d329461 100644 --- a/tauri-app/src-tauri/src/main.rs +++ b/tauri-app/src-tauri/src/main.rs @@ -13,6 +13,7 @@ use commands::vault::{ vault_deposit, vault_detail, vault_list_balance_changes, vault_list_balance_changes_write_csv, vault_withdraw, vaults_list, vaults_list_write_csv, }; +use commands::order_clear::{order_clears_list, order_clears_list_write_csv}; use commands::wallet::get_address_from_ledger; fn main() { @@ -30,6 +31,8 @@ fn main() { order_detail, order_add, order_remove, + order_clears_list, + order_clears_list_write_csv, get_address_from_ledger, get_chainid, parse_dotrain, diff --git a/tauri-app/src/lib/components/Sidebar.svelte b/tauri-app/src/lib/components/Sidebar.svelte index 3dd2315c2..b413e3117 100644 --- a/tauri-app/src/lib/components/Sidebar.svelte +++ b/tauri-app/src/lib/components/Sidebar.svelte @@ -15,6 +15,7 @@ import { page } from '$app/stores'; import { isSettingsDefinedAndValid } from '$lib/stores/settings'; import ButtonDarkMode from './ButtonDarkMode.svelte'; + import { CashSolid } from 'flowbite-svelte-icons'; $: nonActiveClass = $isSettingsDefinedAndValid ? 'flex items-center p-2 text-base font-normal text-green-900 rounded-lg dark:text-white hover:bg-green-100 dark:hover:bg-green-700' @@ -49,6 +50,11 @@ + + + + + diff --git a/tauri-app/src/lib/stores/orderClearsList.ts b/tauri-app/src/lib/stores/orderClearsList.ts new file mode 100644 index 000000000..fd7e95cf8 --- /dev/null +++ b/tauri-app/src/lib/stores/orderClearsList.ts @@ -0,0 +1,11 @@ +import { get } from 'svelte/store'; +import type { OrderClear } from '$lib/typeshare/orderClearsList'; +import { invoke } from '@tauri-apps/api'; +import { subgraphUrl } from '$lib/stores/settings'; +import { listStore } from '$lib/storesGeneric/listStore'; + +export const orderClearsList = listStore( + 'orderClearsList', + (page) => invoke("order_clears_list", {subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page, page_size: 10 } }), + (path) => invoke("order_clears_list_write_csv", { path, subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page: 1, page_size: 1000 } }) +); \ No newline at end of file diff --git a/tauri-app/src/routes/order-clears/+page.svelte b/tauri-app/src/routes/order-clears/+page.svelte new file mode 100644 index 000000000..a3b9c7233 --- /dev/null +++ b/tauri-app/src/routes/order-clears/+page.svelte @@ -0,0 +1,63 @@ + + + + + +{#if $orderClearsList.currentPage.length === 0} +
No Order Clears found
+{:else} + + + Order Clear ID + Cleared At + Sender + Clearer + Bounty A + Bounty B + + + {#each $orderClearsList.currentPage as orderClear} + {goto(`/order-clears/${orderClear.id}`)}}> + + + {formatTimestampSecondsAsLocal(BigInt(orderClear.timestamp))} + + + + {orderClear.bounty.bounty_amount_adisplay} {orderClear.bounty.bounty_token_a.symbol} + {orderClear.bounty.bounty_amount_bdisplay} {orderClear.bounty.bounty_token_b.symbol} + + {/each} + +
+ +
+ orderClearsList.exportCsv()} loading={$orderClearsList.isExporting}> + + Export to CSV + + +
+{/if} \ No newline at end of file diff --git a/tauri-app/src/routes/vaults/+page.svelte b/tauri-app/src/routes/vaults/+page.svelte index bd75beb94..74e153e97 100644 --- a/tauri-app/src/routes/vaults/+page.svelte +++ b/tauri-app/src/routes/vaults/+page.svelte @@ -38,7 +38,7 @@ -{#if $vaultsList.page.length === 0} +{#if $vaultsList.currentPage.length}
No Vaults found
{:else} From 9843a20d73f8e7a1bce5e0fe91ec6319f1c981cf Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Wed, 7 Feb 2024 18:58:47 -0700 Subject: [PATCH 2/4] fix(tauri/ui): page empty check --- tauri-app/src/routes/vaults/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tauri-app/src/routes/vaults/+page.svelte b/tauri-app/src/routes/vaults/+page.svelte index 74e153e97..a3f7913d9 100644 --- a/tauri-app/src/routes/vaults/+page.svelte +++ b/tauri-app/src/routes/vaults/+page.svelte @@ -38,7 +38,7 @@ -{#if $vaultsList.currentPage.length} +{#if $vaultsList.currentPage.length === 0}
No Vaults found
{:else}
From 68f1bacabb5a4e79a18847084764ceec5d70e407 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Wed, 7 Feb 2024 18:59:38 -0700 Subject: [PATCH 3/4] fix(tauri/ui): antoher page empty check --- tauri-app/src/lib/components/TableOrders.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tauri-app/src/lib/components/TableOrders.svelte b/tauri-app/src/lib/components/TableOrders.svelte index ac1df2180..cf5c06ea5 100644 --- a/tauri-app/src/lib/components/TableOrders.svelte +++ b/tauri-app/src/lib/components/TableOrders.svelte @@ -26,7 +26,7 @@ export let ordersList: PaginatedCachedStore; -{#if $ordersList.page.length === 0} +{#if $ordersList.currentPage.length === 0}
No Orders found
{:else}
From c2e5067c42d8d02adcd79690e9087e1005256304 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Thu, 8 Feb 2024 10:25:57 -0700 Subject: [PATCH 4/4] fix(tauri): write csv from tauri command --- tauri-app/src-tauri/src/commands/order_clear.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tauri-app/src-tauri/src/commands/order_clear.rs b/tauri-app/src-tauri/src/commands/order_clear.rs index 2c40bb83f..4ba17b8e5 100644 --- a/tauri-app/src-tauri/src/commands/order_clear.rs +++ b/tauri-app/src-tauri/src/commands/order_clear.rs @@ -2,10 +2,11 @@ use crate::error::CommandResult; use rain_orderbook_common::subgraph::SubgraphArgs; use rain_orderbook_subgraph_client::{ types::{flattened::{OrderClearFlattened, TryIntoFlattenedError}, order_clears_list}, - WriteCsv, + TryIntoCsv, PaginationArgs, }; use std::path::PathBuf; +use std::fs; #[tauri::command] pub async fn order_clears_list( @@ -35,7 +36,8 @@ pub async fn order_clears_list_write_csv( .into_iter() .map(|o| o.try_into()) .collect::, TryIntoFlattenedError>>()?; - order_clears_flattened.write_csv(path)?; + let csv_text = order_clears_flattened.try_into_csv()?; + fs::write(path, csv_text)?; Ok(()) } \ No newline at end of file