diff --git a/tauri-app/src/lib/stores/orderDetail.ts b/tauri-app/src/lib/stores/orderDetail.ts index 6a51e014d..409d417ed 100644 --- a/tauri-app/src/lib/stores/orderDetail.ts +++ b/tauri-app/src/lib/stores/orderDetail.ts @@ -2,6 +2,6 @@ import { get } from 'svelte/store'; import type { Order } from '$lib/typeshare/orderDetail'; import { invoke } from '@tauri-apps/api'; import { subgraphUrl } from '$lib/stores/settings'; -import { useDetailStore } from '$lib/storesGeneric/detailStore'; +import { detailStore } from '$lib/storesGeneric/detailStore'; -export const orderDetail = useDetailStore("orders.orderDetail", (id: string) => invoke("order_detail", {id, subgraphArgs: { url: get(subgraphUrl)} })); \ No newline at end of file +export const orderDetail = detailStore("orders.orderDetail", (id: string) => invoke("order_detail", {id, subgraphArgs: { url: get(subgraphUrl)} })); \ No newline at end of file diff --git a/tauri-app/src/lib/stores/ordersList.ts b/tauri-app/src/lib/stores/ordersList.ts index ef6c3f18d..42ee59ca8 100644 --- a/tauri-app/src/lib/stores/ordersList.ts +++ b/tauri-app/src/lib/stores/ordersList.ts @@ -2,9 +2,9 @@ import { get } from 'svelte/store'; import type { Order } from '$lib/typeshare/ordersList'; import { invoke } from '@tauri-apps/api'; import { subgraphUrl } from '$lib/stores/settings'; -import { usePaginatedCachedStore } from '$lib/storesGeneric/paginatedStore'; +import { listStore } from '$lib/storesGeneric/listStore'; -export const ordersList = usePaginatedCachedStore( +export const ordersList = listStore( 'ordersList', (page) => invoke("orders_list", {subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page, page_size: 10 } }), (path) => invoke("orders_list_write_csv", { path, subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page: 1, page_size: 1000 } }) diff --git a/tauri-app/src/lib/stores/settings.ts b/tauri-app/src/lib/stores/settings.ts index 18dc18269..c7f9dd61d 100644 --- a/tauri-app/src/lib/stores/settings.ts +++ b/tauri-app/src/lib/stores/settings.ts @@ -3,7 +3,7 @@ import { derived } from 'svelte/store'; import every from 'lodash/every'; import { isAddress } from 'viem'; import { updateChainId } from '$lib/stores/chain'; -import { cachedWritableInt, cachedWritableString } from '$lib/storesGeneric/cachedWritable'; +import { cachedWritableInt, cachedWritableString } from '$lib/storesGeneric/cachedWritableStore'; export const rpcUrl = cachedWritableString("settings.rpcUrl", ''); export const subgraphUrl = cachedWritableString("settings.subgraphUrl", ''); diff --git a/tauri-app/src/lib/stores/vaultDetail.ts b/tauri-app/src/lib/stores/vaultDetail.ts index a06cf880b..68c6f0794 100644 --- a/tauri-app/src/lib/stores/vaultDetail.ts +++ b/tauri-app/src/lib/stores/vaultDetail.ts @@ -2,6 +2,6 @@ import type { TokenVault } from '$lib/typeshare/vaultDetail'; import { get } from 'svelte/store'; import { invoke } from '@tauri-apps/api'; import { subgraphUrl } from '$lib/stores/settings'; -import { useDetailStore } from '$lib/storesGeneric/detailStore'; +import { detailStore } from '$lib/storesGeneric/detailStore'; -export const vaultDetail = useDetailStore("vaults.vaultsDetail", (id: string) => invoke("vault_detail", {id, subgraphArgs: { url: get(subgraphUrl)} })); \ No newline at end of file +export const vaultDetail = detailStore("vaults.vaultsDetail", (id: string) => invoke("vault_detail", {id, subgraphArgs: { url: get(subgraphUrl)} })); \ No newline at end of file diff --git a/tauri-app/src/lib/stores/vaultListBalanceChanges.ts b/tauri-app/src/lib/stores/vaultListBalanceChanges.ts index 658896972..972f1908e 100644 --- a/tauri-app/src/lib/stores/vaultListBalanceChanges.ts +++ b/tauri-app/src/lib/stores/vaultListBalanceChanges.ts @@ -1,9 +1,10 @@ import { get } from 'svelte/store'; import { invoke } from '@tauri-apps/api'; import { subgraphUrl } from '$lib/stores/settings'; -import { usePaginatedCachedStore } from '$lib/storesGeneric/paginatedStore'; +import { listStore } from '$lib/storesGeneric/listStore'; import type { VaultBalanceChange } from '$lib/typeshare/vaultListBalanceChanges'; -export const useVaultListBalanceChanges = (id: string) => usePaginatedCachedStore( + +export const useVaultListBalanceChanges = (id: string) => listStore( `vaultListBalanceChanges-${id}`, (page) => invoke("vault_list_balance_changes", {subgraphArgs: { url: get(subgraphUrl)}, id, paginationArgs: { page, page_size: 10 } }), (path) => invoke("vault_list_balance_changes_write_csv", {path, subgraphArgs: { url: get(subgraphUrl)}, id, paginationArgs: { page: 1, page_size: 1000 } }) diff --git a/tauri-app/src/lib/stores/vaultsList.ts b/tauri-app/src/lib/stores/vaultsList.ts index 52aba406f..ab40015c0 100644 --- a/tauri-app/src/lib/stores/vaultsList.ts +++ b/tauri-app/src/lib/stores/vaultsList.ts @@ -2,10 +2,10 @@ import { get } from 'svelte/store'; import type { TokenVault } from '$lib/typeshare/vaultsList'; import { invoke } from '@tauri-apps/api'; import { subgraphUrl } from '$lib/stores/settings'; -import { usePaginatedCachedStore } from '$lib/storesGeneric/paginatedStore'; +import { listStore } from '$lib/storesGeneric/listStore'; -export const vaultsList = usePaginatedCachedStore( +export const vaultsList = listStore( 'vaultsList', (page) => invoke("vaults_list", {subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page, page_size: 10 } }), (path) => invoke("vaults_list_write_csv", {path, subgraphArgs: { url: get(subgraphUrl)}, paginationArgs: { page: 1, page_size: 1000 } }) diff --git a/tauri-app/src/lib/storesGeneric/cachedWritable.ts b/tauri-app/src/lib/storesGeneric/cachedWritableStore.ts similarity index 64% rename from tauri-app/src/lib/storesGeneric/cachedWritable.ts rename to tauri-app/src/lib/storesGeneric/cachedWritableStore.ts index cfbe9f1d0..2b3f4b582 100644 --- a/tauri-app/src/lib/storesGeneric/cachedWritable.ts +++ b/tauri-app/src/lib/storesGeneric/cachedWritableStore.ts @@ -1,6 +1,6 @@ import { writable } from "svelte/store"; -export function useCachedWritable( +export function cachedWritableStore( key: string, defaultValue: T, serialize: (value: T) => string, @@ -27,15 +27,15 @@ export function useCachedWritable( return data; } -export const cachedWritableString = (key: string, defaultValue = '') => useCachedWritable(key, defaultValue, (v) => v, (v) => v); -export const cachedWritableInt = (key: string, defaultValue = 0) => useCachedWritable(key, defaultValue, (v) => v.toString(), (v) => parseInt(v)); +export const cachedWritableString = (key: string, defaultValue = '') => cachedWritableStore(key, defaultValue, (v) => v, (v) => v); +export const cachedWritableInt = (key: string, defaultValue = 0) => cachedWritableStore(key, defaultValue, (v) => v.toString(), (v) => parseInt(v)); -export const useCachedWritableOptional = ( +export const cachedWritableOptionalStore = ( key: string, defaultValue: T | undefined = undefined, serialize: (value: T) => string, deserialize: (serialized: string) => T -) => useCachedWritable(key, defaultValue, (v) => v ? serialize(v) : '', (v) => v ? deserialize(v) : undefined); +) => cachedWritableStore(key, defaultValue, (v) => v ? serialize(v) : '', (v) => v ? deserialize(v) : undefined); -export const cachedWritableIntOptional = (key: string, defaultValue = undefined) => useCachedWritableOptional(key, defaultValue, (v) => v.toString(), (v) => parseInt(v)); +export const cachedWritableIntOptional = (key: string, defaultValue = undefined) => cachedWritableOptionalStore(key, defaultValue, (v) => v.toString(), (v) => parseInt(v)); diff --git a/tauri-app/src/lib/storesGeneric/detailStore.ts b/tauri-app/src/lib/storesGeneric/detailStore.ts index 198e1119e..743cb9836 100644 --- a/tauri-app/src/lib/storesGeneric/detailStore.ts +++ b/tauri-app/src/lib/storesGeneric/detailStore.ts @@ -1,7 +1,7 @@ -import { useCachedWritable } from '$lib/storesGeneric/cachedWritable'; +import { cachedWritableStore } from '$lib/storesGeneric/cachedWritableStore'; -export function useDetailStore(key: string, fetchById: (id: string) => Promise) { - const {subscribe, update} = useCachedWritable<{[id: string]: T}>(key, {}, (value) => JSON.stringify(value), (value) => JSON.parse(value)); +export function detailStore(key: string, fetchById: (id: string) => Promise) { + const {subscribe, update} = cachedWritableStore<{[id: string]: T}>(key, {}, (value) => JSON.stringify(value), (value) => JSON.parse(value)); subscribe(value => { if(value) { diff --git a/tauri-app/src/lib/storesGeneric/paginatedStore.ts b/tauri-app/src/lib/storesGeneric/listStore.ts similarity index 88% rename from tauri-app/src/lib/storesGeneric/paginatedStore.ts rename to tauri-app/src/lib/storesGeneric/listStore.ts index 4b9c009b3..e5a2e4f4e 100644 --- a/tauri-app/src/lib/storesGeneric/paginatedStore.ts +++ b/tauri-app/src/lib/storesGeneric/listStore.ts @@ -3,7 +3,7 @@ import { toasts } from '../stores/toasts'; import { save } from '@tauri-apps/api/dialog'; import dayjs from 'dayjs'; import { ToastMessageType } from '$lib/typeshare/toast'; -import { useCachedWritable } from '$lib/storesGeneric/cachedWritable'; +import { cachedWritableStore } from '$lib/storesGeneric/cachedWritableStore'; type Unsubscriber = () => void; @@ -28,9 +28,9 @@ export interface AllPages { } -const cachedWritablePages = (key: string) => useCachedWritable>(key, [], (value) => JSON.stringify(value), (value) => JSON.parse(value)); +const cachedWritablePages = (key: string) => cachedWritableStore>(key, [], (value) => JSON.stringify(value), (value) => JSON.parse(value)); -export function usePaginatedCachedStore(key: string, fetchPageHandler: (page: number) => Promise>, writeCsvHandler: (path: string) => Promise) { +export function listStore(key: string, fetchPageHandler: (page: number) => Promise>, writeCsvHandler: (path: string) => Promise) { const allPages = cachedWritablePages(key); const pageIndex = writable(1); const isFetching = writable(false);