From 78c9597b1981a97a45ff2bbb5f834366d3f83ca5 Mon Sep 17 00:00:00 2001 From: 2xburnt <169301814+2xburnt@users.noreply.github.com> Date: Wed, 30 Jul 2025 12:13:01 -0500 Subject: [PATCH] make fetch all blocks configurable --- src/stores/useBaseStore.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stores/useBaseStore.ts b/src/stores/useBaseStore.ts index fa1bef85..6c26bea2 100644 --- a/src/stores/useBaseStore.ts +++ b/src/stores/useBaseStore.ts @@ -6,6 +6,9 @@ import type { Block } from '@/types'; import { hashTx } from '@/libs'; import { fromBase64 } from '@cosmjs/encoding'; +const FETCH_ALL_BLOCKS = import.meta.env.VITE_FETCH_ALL_BLOCKS || false; +const RECENT_BLOCKS_LIMIT = import.meta.env.VITE_RECENT_BLOCK_LIMIT || 50; + export const useBaseStore = defineStore('baseStore', { state: () => { return { @@ -91,7 +94,7 @@ export const useBaseStore = defineStore('baseStore', { if (this.recents.findIndex((x) => x?.block_id?.hash === this.latest?.block_id?.hash) === -1) { const newBlocks = await this.fetchNewBlocks(); const combined = [...this.recents, ...newBlocks]; - this.recents = combined.slice(-50); + this.recents = combined.slice(-RECENT_BLOCKS_LIMIT); } return this.latest; }, @@ -102,6 +105,7 @@ export const useBaseStore = defineStore('baseStore', { */ async fetchNewBlocks() { if (!this.latest?.block?.header?.height) return []; + if (!FETCH_ALL_BLOCKS) return [this.latest]; const oldHeight = Number(this.recents[this.recents.length - 1]?.block?.header?.height); const newHeight = Number(this.latest.block.header.height); let newBlocks = [];