Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explorer: Give defaults to data fetch intervals #1934

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading