From a97177340f8edc090c4d8d18af6409222408a33c Mon Sep 17 00:00:00 2001 From: Andrea Scartabelli Date: Wed, 10 Jul 2024 14:42:49 +0200 Subject: [PATCH] explorer: Add a separate variable for stats fetch interval Resolves #1728 --- explorer/README.md | 1 + .../lib/containers/__tests__/StatisticsPanel.spec.js | 10 ++++++---- .../containers/statistics-panel/StatisticsPanel.svelte | 2 +- explorer/src/lib/stores/__tests__/appStore.spec.js | 6 +++++- explorer/src/lib/stores/appStore.js | 2 ++ explorer/src/lib/stores/stores.d.ts | 1 + explorer/vite.config.js | 2 ++ 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/explorer/README.md b/explorer/README.md index 074b537ab9..b2b3d2a438 100644 --- a/explorer/README.md +++ b/explorer/README.md @@ -31,6 +31,7 @@ VITE_DUSK_TESTNET_NODE="nodes.dusk.network" VITE_DUSK_DEVNET_NODE="devnet.nodes.dusk.network" VITE_MARKET_DATA_REFETCH_INTERVAL=120000 VITE_REFETCH_INTERVAL=1000 +VITE_STATS_REFETCH_INTERVAL=1000 VITE_TRANSACTIONS_LIST_ENTRIES=100 ``` diff --git a/explorer/src/lib/containers/__tests__/StatisticsPanel.spec.js b/explorer/src/lib/containers/__tests__/StatisticsPanel.spec.js index 5811033028..bc148b156a 100644 --- a/explorer/src/lib/containers/__tests__/StatisticsPanel.spec.js +++ b/explorer/src/lib/containers/__tests__/StatisticsPanel.spec.js @@ -35,7 +35,7 @@ vi.mock("$lib/services", async (importOriginal) => { }); describe("StatisticsPanel", () => { - const { fetchInterval, network } = get(appStore); + const { statsFetchInterval, network } = get(appStore); afterEach(cleanup); @@ -58,19 +58,21 @@ describe("StatisticsPanel", () => { // snapshot with received data from APIs expect(container.firstChild).toMatchSnapshot(); - await vi.advanceTimersByTimeAsync(fetchInterval - marketDataSettleTime); + await vi.advanceTimersByTimeAsync( + statsFetchInterval - marketDataSettleTime + ); expect(duskAPI.getStats).toHaveBeenCalledTimes(2); expect(duskAPI.getStats).toHaveBeenNthCalledWith(2, network); - await vi.advanceTimersByTimeAsync(fetchInterval); + await vi.advanceTimersByTimeAsync(statsFetchInterval); expect(duskAPI.getStats).toHaveBeenCalledTimes(3); expect(duskAPI.getStats).toHaveBeenNthCalledWith(3, network); unmount(); - await vi.advanceTimersByTimeAsync(fetchInterval * 10); + await vi.advanceTimersByTimeAsync(statsFetchInterval * 10); expect(duskAPI.getStats).toHaveBeenCalledTimes(3); expect(duskAPI.getNodeLocations).toHaveBeenCalledTimes(1); diff --git a/explorer/src/lib/containers/statistics-panel/StatisticsPanel.svelte b/explorer/src/lib/containers/statistics-panel/StatisticsPanel.svelte index caa02f9a9d..dcfec95eee 100644 --- a/explorer/src/lib/containers/statistics-panel/StatisticsPanel.svelte +++ b/explorer/src/lib/containers/statistics-panel/StatisticsPanel.svelte @@ -37,7 +37,7 @@ const nodeLocationsStore = createDataStore(duskAPI.getNodeLocations); const pollingStatsDataStore = createPollingDataStore( duskAPI.getStats, - $appStore.fetchInterval + $appStore.statsFetchInterval ); onNetworkChange((network) => { diff --git a/explorer/src/lib/stores/__tests__/appStore.spec.js b/explorer/src/lib/stores/__tests__/appStore.spec.js index edfcff71be..f52230995a 100644 --- a/explorer/src/lib/stores/__tests__/appStore.spec.js +++ b/explorer/src/lib/stores/__tests__/appStore.spec.js @@ -23,6 +23,7 @@ describe("appStore", () => { marketDataFetchInterval: Number(env.VITE_MARKET_DATA_REFETCH_INTERVAL), network: expectedNetworks[0].value, networks: expectedNetworks, + statsFetchInterval: Number(env.VITE_STATS_REFETCH_INTERVAL), transactionsListEntries: Number(env.VITE_TRANSACTIONS_LIST_ENTRIES), }); }); @@ -30,12 +31,15 @@ describe("appStore", () => { it("should use default values for the fetch intervals if the env vars are missing", async () => { vi.stubEnv("VITE_REFETCH_INTERVAL", ""); vi.stubEnv("VITE_MARKET_DATA_REFETCH_INTERVAL", ""); + vi.stubEnv("VITE_STATS_REFETCH_INTERVAL", ""); const { appStore } = await import(".."); - const { fetchInterval, marketDataFetchInterval } = get(appStore); + const { fetchInterval, marketDataFetchInterval, statsFetchInterval } = + get(appStore); expect(fetchInterval).toBe(1000); expect(marketDataFetchInterval).toBe(120000); + expect(statsFetchInterval).toBe(1000); vi.unstubAllEnvs(); }); diff --git a/explorer/src/lib/stores/appStore.js b/explorer/src/lib/stores/appStore.js index 9d57bca55c..1d8b87255e 100644 --- a/explorer/src/lib/stores/appStore.js +++ b/explorer/src/lib/stores/appStore.js @@ -15,6 +15,8 @@ const initialState = { Number(import.meta.env.VITE_MARKET_DATA_REFETCH_INTERVAL) || 120000, network: networks[0].value, networks, + statsFetchInterval: + Number(import.meta.env.VITE_STATS_REFETCH_INTERVAL) || 1000, transactionsListEntries: Number( import.meta.env.VITE_TRANSACTIONS_LIST_ENTRIES ), diff --git a/explorer/src/lib/stores/stores.d.ts b/explorer/src/lib/stores/stores.d.ts index 2c0926734d..3f3d3d3e3c 100644 --- a/explorer/src/lib/stores/stores.d.ts +++ b/explorer/src/lib/stores/stores.d.ts @@ -9,6 +9,7 @@ type AppStoreContent = { marketDataFetchInterval: number; network: string; networks: NetworkOption[]; + statsFetchInterval: number; transactionsListEntries: number; }; diff --git a/explorer/vite.config.js b/explorer/vite.config.js index d7024ccbad..2598fe0a36 100644 --- a/explorer/vite.config.js +++ b/explorer/vite.config.js @@ -35,6 +35,7 @@ export default defineConfig(({ mode }) => { VITE_MARKET_DATA_REFETCH_INTERVAL: env.VITE_MARKET_DATA_REFETCH_INTERVAL, VITE_REFETCH_INTERVAL: env.VITE_REFETCH_INTERVAL, + VITE_STATS_REFETCH_INTERVAL: env.VITE_STATS_REFETCH_INTERVAL, VITE_TRANSACTIONS_LIST_ENTRIES: env.VITE_TRANSACTIONS_LIST_ENTRIES, }, }, @@ -57,6 +58,7 @@ export default defineConfig(({ mode }) => { VITE_DUSK_TESTNET_NODE: "nodes.dusk.network", VITE_MARKET_DATA_REFETCH_INTERVAL: "120000", VITE_REFETCH_INTERVAL: "1000", + VITE_STATS_REFETCH_INTERVAL: "1000", VITE_TRANSACTIONS_LIST_ENTRIES: "100", }, environment: "jsdom",