cosmos-explorer/src/main.ts

38 lines
1.1 KiB
TypeScript

// import 'ping-widget';
import App from '@/App.vue';
import i18n from '@/plugins/i18n';
import '@/style.css';
import { createApp, ref } from 'vue';
import { createPinia } from 'pinia';
import LazyLoad from 'lazy-load-vue3';
import router from './router';
import { useBaseStore } from './stores/useBaseStore';
// Create vue app
const app = createApp(App);
// Use plugins
app.use(i18n);
app.use(createPinia());
app.use(router);
app.use(LazyLoad, { component: true });
// Mount vue app
app.mount('#app');
// fetch new block(s) on this interval, specified in miliseconds
// note that the design of the block fetching code is such that it
// will MISS BLOCKS if this interval is longer than the block time
// TODO: make this configurable
const blockFetchInterval = 2 * 1000;
// fetch latest block every 6s
const blockStore = useBaseStore();
const requestCounter = ref(0);
setInterval(() => {
requestCounter.value += 1;
if (requestCounter.value < 5) {
// max allowed request
blockStore.fetchLatest().finally(() => (requestCounter.value -= 1));
}
}, blockFetchInterval);