Skip to content

Commit 78c9597

Browse files
committed
make fetch all blocks configurable
1 parent 8f02a1f commit 78c9597

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/stores/useBaseStore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import type { Block } from '@/types';
66
import { hashTx } from '@/libs';
77
import { fromBase64 } from '@cosmjs/encoding';
88

9+
const FETCH_ALL_BLOCKS = import.meta.env.VITE_FETCH_ALL_BLOCKS || false;
10+
const RECENT_BLOCKS_LIMIT = import.meta.env.VITE_RECENT_BLOCK_LIMIT || 50;
11+
912
export const useBaseStore = defineStore('baseStore', {
1013
state: () => {
1114
return {
@@ -91,7 +94,7 @@ export const useBaseStore = defineStore('baseStore', {
9194
if (this.recents.findIndex((x) => x?.block_id?.hash === this.latest?.block_id?.hash) === -1) {
9295
const newBlocks = await this.fetchNewBlocks();
9396
const combined = [...this.recents, ...newBlocks];
94-
this.recents = combined.slice(-50);
97+
this.recents = combined.slice(-RECENT_BLOCKS_LIMIT);
9598
}
9699
return this.latest;
97100
},
@@ -102,6 +105,7 @@ export const useBaseStore = defineStore('baseStore', {
102105
*/
103106
async fetchNewBlocks() {
104107
if (!this.latest?.block?.header?.height) return [];
108+
if (!FETCH_ALL_BLOCKS) return [this.latest];
105109
const oldHeight = Number(this.recents[this.recents.length - 1]?.block?.header?.height);
106110
const newHeight = Number(this.latest.block.header.height);
107111
let newBlocks = [];

0 commit comments

Comments
 (0)