Skip to content

Commit

Permalink
Merge pull request #1934 from dusk-network/feature-1933
Browse files Browse the repository at this point in the history
explorer: Give defaults to data fetch intervals
  • Loading branch information
ascartabelli authored Jul 5, 2024
2 parents b28bd04 + 435ba61 commit 26b1824
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
28 changes: 23 additions & 5 deletions explorer/src/lib/stores/__tests__/appStore.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { describe, expect, it } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { get } from "svelte/store";

import { appStore } from "..";

describe("appStore", () => {
it("should be a readable store holding the information needed throughout the whole application", () => {
beforeEach(() => {
vi.resetModules();
});

it("should be a readable store holding the information needed throughout the whole application", async () => {
const { appStore } = await import("..");
const { env } = import.meta;
const expectedNetworks = [
{ label: "Testnet", value: env.VITE_DUSK_TESTNET_NODE },
Expand All @@ -24,7 +27,22 @@ describe("appStore", () => {
});
});

it("should expose a service method to set the selected network", () => {
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", "");

const { appStore } = await import("..");
const { fetchInterval, marketDataFetchInterval } = get(appStore);

expect(fetchInterval).toBe(1000);
expect(marketDataFetchInterval).toBe(120000);

vi.unstubAllEnvs();
});

it("should expose a service method to set the selected network", async () => {
const { appStore } = await import("..");

appStore.setNetwork("some-network");

expect(get(appStore).network).toBe("some-network");
Expand Down
7 changes: 3 additions & 4 deletions explorer/src/lib/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ const networks = [
const initialState = {
blocksListEntries: Number(import.meta.env.VITE_BLOCKS_LIST_ENTRIES),
chainInfoEntries: Number(import.meta.env.VITE_CHAIN_INFO_ENTRIES),
fetchInterval: Number(import.meta.env.VITE_REFETCH_INTERVAL),
marketDataFetchInterval: Number(
import.meta.env.VITE_MARKET_DATA_REFETCH_INTERVAL
),
fetchInterval: Number(import.meta.env.VITE_REFETCH_INTERVAL) || 1000,
marketDataFetchInterval:
Number(import.meta.env.VITE_MARKET_DATA_REFETCH_INTERVAL) || 120000,
network: networks[0].value,
networks,
transactionsListEntries: Number(
Expand Down

0 comments on commit 26b1824

Please sign in to comment.