From 9e3f190a66f22f11d50c6905001d1a5474f02f3a Mon Sep 17 00:00:00 2001 From: 2xburnt <169301814+2xburnt@users.noreply.github.com> Date: Tue, 29 Jul 2025 17:43:34 -0500 Subject: [PATCH 1/9] use basetore blocktime, eliminate redundant block fetching --- chains/mainnet/xion.json | 149 ++++++++++++++++++++++++ src/main.ts | 37 ++++-- src/modules/[chain]/block/block.ts | 62 +++------- src/modules/[chain]/consensus/index.vue | 7 +- src/stores/useBaseStore.ts | 41 +++---- src/stores/useDashboard.ts | 4 +- 6 files changed, 222 insertions(+), 78 deletions(-) create mode 100644 chains/mainnet/xion.json diff --git a/chains/mainnet/xion.json b/chains/mainnet/xion.json new file mode 100644 index 00000000..5e82d72d --- /dev/null +++ b/chains/mainnet/xion.json @@ -0,0 +1,149 @@ +{ + "chain_name": "xion", + "registry_name": "xion", + "coingecko": "xion", + "network_type": "mainnet", + "rpc": [ + { + "address": "https://rpc.xion-mainnet-1.burnt.com", + "provider": "🔥BurntLabs🔥" + }, + { + "address": "https://rpc-burnt.imperator.co/", + "provider": "Imperator.co" + }, + { + "address": "https://xion-rpc.polkachu.com", + "provider": "Polkachu" + } + ], + "api": [ + { + "address": "https://api.xion-mainnet-1.burnt.com", + "provider": "🔥BurntLabs🔥" + }, + { + "address": "https://lcd-burnt.imperator.co/", + "provider": "Imperator.co" + }, + { + "address": "https://xion-api.polkachu.com", + "provider": "Polkachu" + } + ], + "snapshot_provider": "", + "sdk_version": "0.50.13", + "coin_type": "118", + "min_tx_fee": "100", + "addr_prefix": "xion", + "theme_color": "#96b325", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png", + "assets": [ + { + "base": "uxion", + "symbol": "XION", + "exponent": "6", + "coingecko_id": "xion-2", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png" + }, + { + "base": "ibc/0471F1C4E7AFD3F07702BEF6DC365268D64570F7C1FDC98EA6098DD6DE59817B", + "symbol": "OSMO", + "exponent": "6", + "coingecko_id": "osmosis", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png" + }, + { + "base": "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349", + "symbol": "USDC", + "exponent": "6", + "coingecko_id": "usd-coin", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png" + }, + { + "base": "ibc/CC7B293B3F08EA7DB96AFD4765BD0C7F95ABD7ECEAF21C74F3ACCBF7CEFB6591", + "symbol": "OSMO", + "exponent": "6", + "coingecko_id": "osmosis", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png" + }, + { + "base": "ibc/9463E39D230614B313B487836D13A392BD1731928713D4C8427A083627048DB3", + "symbol": "AXL", + "exponent": "6", + "coingecko_id": "axelar", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png" + }, + { + "base": "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4", + "symbol": "axlUSDC", + "exponent": "6", + "coingecko_id": "usd-coin", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png" + }, + { + "base": "ibc/0000000000000000000000000000000000000000000000000000000000000000", + "symbol": "axlUSDT", + "exponent": "6", + "coingecko_id": "tether", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png" + }, + { + "base": "ibc/0000000000000000000000000000000000000000000000000000000000000000", + "symbol": "axlDAI", + "exponent": "18", + "coingecko_id": "dai", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axldai.png" + }, + { + "base": "ibc/0000000000000000000000000000000000000000000000000000000000000000", + "symbol": "axlFRAX", + "exponent": "6", + "coingecko_id": "frax", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlfrax.png" + }, + { + "base": "ibc/AAD7136DD626569C3DDE7C5F764968BB2E939875EFC568AE5712B62081850814", + "symbol": "axlWETH", + "exponent": "18", + "coingecko_id": "axlweth", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png" + }, + { + "base": "ibc/056EA54C3D9B49B3C0418955A27980A91DD4F210914BFE240A1DB19E27895ECA", + "symbol": "KYVE", + "exponent": "6", + "coingecko_id": "kyve-network", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/kyve/images/kyve-token.png" + }, + { + "base": "ibc/DBE9697AC1044255A305A2034AD360B4152632BFBFB5785234731F60196B9645", + "symbol": "ELYS", + "exponent": "6", + "coingecko_id": "elys", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/elys/images/elys.png" + }, + { + "base": "ibc/E706A0C6CACB374ADC2BCF6A74FE1B260840FC822E45DCB776DEA962A57FED30", + "symbol": "axlARB", + "exponent": "18", + "coingecko_id": "arb", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/arbitrum/images/arb.png" + } + ], + "features": [ + "dashboard", + "governance", + "staking", + "blocks", + "tx", + "uptime", + "ibc", + "supply", + "parameters", + "consensus", + "cosmwasm", + "account" + ], + "keplr_features": ["ibc-go", "ibc-transfer", "no-legacy-stdTx"] +} diff --git a/src/main.ts b/src/main.ts index f0d9b263..cc2194db 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ import App from '@/App.vue'; import i18n from '@/plugins/i18n'; import '@/style.css'; -import { createApp, ref } from 'vue'; +import { createApp, ref, watch } from 'vue'; import { createPinia } from 'pinia'; import LazyLoad from 'lazy-load-vue3'; @@ -19,13 +19,32 @@ app.use(LazyLoad, { component: true }); // Mount vue app app.mount('#app'); -// fetch latest block every 6s -const blockStore = useBaseStore(); +// fetch latest block every ms +const baseStore = useBaseStore(); const requestCounter = ref(0); -setInterval(() => { - requestCounter.value += 1; - if (requestCounter.value < 5) { - // max allowed request - blockStore.fetchLatest().finally(() => (requestCounter.value -= 1)); + +let intervalId: NodeJS.Timeout; + +const startInterval = () => { + clearInterval(intervalId); // Clear any existing interval + // console.log('Starting interval with blocktime:', baseStore.blocktime); + + intervalId = setInterval(() => { + requestCounter.value += 1; + if (requestCounter.value < 5) { + // max allowed request + baseStore.fetchLatest().finally(() => (requestCounter.value -= 1)); + } + }, baseStore.blocktime); +}; + +// Call startInterval initially +startInterval(); + +// Watch for changes to baseStore.blocktime +watch( + () => baseStore.blocktime, + () => { + startInterval(); // Restart the interval when baseStore.blocktime changes } -}, 6000); +); diff --git a/src/modules/[chain]/block/block.ts b/src/modules/[chain]/block/block.ts index ead62cb3..de16412e 100644 --- a/src/modules/[chain]/block/block.ts +++ b/src/modules/[chain]/block/block.ts @@ -1,68 +1,42 @@ import { defineStore } from 'pinia'; -import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing'; -import { useBlockchain } from '@/stores'; -import { hashTx } from '@/libs'; -import type { Block } from '@/types'; +import { useBaseStore, useBlockchain } from '@/stores'; export const useBlockModule = defineStore('blockModule', { - state: () => { - return { - latest: {} as Block, - current: {} as Block, - recents: [] as Block[], - }; - }, getters: { + baseStore() { + return useBaseStore(); + }, blockchain() { return useBlockchain(); }, blocktime() { - if (this.recents.length < 2) return 6000; - return 6000; // todo later + return useBaseStore().blocktime; }, txsInRecents() { - const txs = [] as { hash: string; tx: DecodedTxRaw }[]; - this.recents.forEach((x) => - x.block?.data?.txs.forEach((tx: Uint8Array) => { - if (tx) { - try { - txs.push({ - hash: hashTx(tx), - tx: decodeTxRaw(tx), - }); - } catch (e) {} - } - }) - ); - return txs; + return useBaseStore().txsInRecents; }, + latest(){ + return useBaseStore().latest; + }, + earliest() { + return useBaseStore().earlest; + }, + recents() { + return useBaseStore().recents; + } }, actions: { initial() { this.clearRecentBlocks(); - this.autoFetch(); }, async clearRecentBlocks() { - this.recents = []; - }, - autoFetch() { - this.fetchLatest().then((x) => { - const timer = this.autoFetch; - this.latest = x; - // if(this.recents.length >= 50) this.recents.pop() - // this.recents.push(x) - // setTimeout(timer, 6000) - }); + return this.baseStore.clearRecentBlocks() }, async fetchLatest() { - this.latest = await this.blockchain.rpc?.getBaseBlockLatest(); - if (this.recents.length >= 50) this.recents.shift(); - this.recents.push(this.latest); - return this.latest; + return this.baseStore.fetchLatest() }, async fetchBlock(height: string) { - this.current = await this.blockchain.rpc?.getBaseBlockAt(height); - return this.current; + return this.baseStore.fetchBlock(height) }, }, }); diff --git a/src/modules/[chain]/consensus/index.vue b/src/modules/[chain]/consensus/index.vue index d839c1a8..bb4fca1c 100644 --- a/src/modules/[chain]/consensus/index.vue +++ b/src/modules/[chain]/consensus/index.vue @@ -1,12 +1,13 @@