From 85e9b9d8a8b03728121fa2fe86a679a1195c8cdc Mon Sep 17 00:00:00 2001 From: findolor Date: Tue, 8 Oct 2024 09:53:50 +0300 Subject: [PATCH 1/2] refactor: move trades count to trade query and update the UI at the same time --- .../tables/OrderTradesListTable.svelte | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte index 6a9df33fc..ca1f6b4d9 100644 --- a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte +++ b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte @@ -23,8 +23,11 @@ $: orderTradesQuery = createInfiniteQuery({ queryKey: [id, QKEY_ORDER_TRADES_LIST + id], - queryFn: ({ pageParam }: { pageParam: number }) => { - return orderTradesList( + queryFn: async ({ pageParam }: { pageParam: number }) => { + tradesCount = undefined; + + const count = await orderTradesCount(id, $subgraphUrl || '', startTimestamp, endTimestamp); + const trades = await orderTradesList( id, $subgraphUrl || '', pageParam, @@ -32,6 +35,12 @@ startTimestamp, endTimestamp, ); + + if (typeof count === 'number') { + tradesCount = count; + } + + return trades; }, initialPageParam: 0, getNextPageParam: (lastPage: Trade[], _allPages: Trade[][], lastPageParam: number) => { @@ -39,11 +48,6 @@ }, enabled: !!$subgraphUrl, }); - - $: $orderTradesQuery.isFetching || $orderTradesQuery.isLoading, - orderTradesCount(id, $subgraphUrl || '', startTimestamp, endTimestamp) - .then((v) => (typeof v === 'number' ? (tradesCount = v) : (tradesCount = undefined))) - .catch(() => (tradesCount = undefined)); From d8eb7c1c040491c2b64ce57bce37d3c2620dbc74 Mon Sep 17 00:00:00 2001 From: findolor Date: Tue, 15 Oct 2024 11:12:44 +0300 Subject: [PATCH 2/2] refactor: put two queries into a single promise --- .../components/tables/OrderTradesListTable.svelte | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte index ca1f6b4d9..29f131c33 100644 --- a/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte +++ b/tauri-app/src/lib/components/tables/OrderTradesListTable.svelte @@ -26,15 +26,10 @@ queryFn: async ({ pageParam }: { pageParam: number }) => { tradesCount = undefined; - const count = await orderTradesCount(id, $subgraphUrl || '', startTimestamp, endTimestamp); - const trades = await orderTradesList( - id, - $subgraphUrl || '', - pageParam, - undefined, - startTimestamp, - endTimestamp, - ); + const [count, trades] = await Promise.all([ + orderTradesCount(id, $subgraphUrl || '', startTimestamp, endTimestamp), + orderTradesList(id, $subgraphUrl || '', pageParam, undefined, startTimestamp, endTimestamp), + ]); if (typeof count === 'number') { tradesCount = count;