forked from LaconicNetwork/cosmos-explorer
use basetore blocktime, eliminate redundant block fetching
This commit is contained in:
parent
1bfc76cd3b
commit
9e3f190a66
149
chains/mainnet/xion.json
Normal file
149
chains/mainnet/xion.json
Normal file
@ -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"]
|
||||
}
|
||||
37
src/main.ts
37
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 <blocktime> 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);
|
||||
);
|
||||
|
||||
@ -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)
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import fetch from 'cross-fetch';
|
||||
import { onMounted, ref, computed, onUnmounted } from 'vue';
|
||||
import { useBlockchain, useFormatter, useStakingStore } from '@/stores';
|
||||
import { useBlockchain, useFormatter, useStakingStore, useBaseStore } from '@/stores';
|
||||
import { consensusPubkeyToHexAddress } from '@/libs';
|
||||
|
||||
const format = useFormatter();
|
||||
const chainStore = useBlockchain();
|
||||
const stakingStore = useStakingStore();
|
||||
const baseStore = useBaseStore();
|
||||
const rpcList = ref(chainStore.current?.endpoints?.rpc || [{ address: '', provider: '' }]);
|
||||
let rpc = ref('');
|
||||
const validators = ref(stakingStore.validators);
|
||||
@ -31,7 +32,7 @@ onMounted(async () => {
|
||||
clearTime();
|
||||
timer = setInterval(() => {
|
||||
update();
|
||||
}, 6000);
|
||||
}, Math.round(baseStore.blocktime / 2));
|
||||
});
|
||||
onUnmounted(() => {
|
||||
clearTime();
|
||||
@ -87,7 +88,7 @@ async function onChange() {
|
||||
update();
|
||||
timer = setInterval(() => {
|
||||
update();
|
||||
}, 6000);
|
||||
}, Math.round(baseStore.blocktime / 2));
|
||||
}
|
||||
|
||||
async function fetchPosition() {
|
||||
|
||||
@ -5,7 +5,6 @@ import dayjs from 'dayjs';
|
||||
import type { Block } from '@/types';
|
||||
import { hashTx } from '@/libs';
|
||||
import { fromBase64 } from '@cosmjs/encoding';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
export const useBaseStore = defineStore('baseStore', {
|
||||
state: () => {
|
||||
@ -14,7 +13,6 @@ export const useBaseStore = defineStore('baseStore', {
|
||||
latest: {} as Block,
|
||||
recents: [] as Block[],
|
||||
theme: (window.localStorage.getItem('theme') || 'dark') as 'light' | 'dark',
|
||||
connected: true,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
@ -23,14 +21,17 @@ export const useBaseStore = defineStore('baseStore', {
|
||||
if (this.latest.block?.header?.height !== this.earlest.block?.header?.height) {
|
||||
const diff = dayjs(this.latest.block?.header?.time).diff(this.earlest.block?.header?.time);
|
||||
const blocks = Number(this.latest.block.header.height) - Number(this.earlest.block.header.height);
|
||||
return diff / blocks;
|
||||
return Math.round(diff / blocks);
|
||||
}
|
||||
}
|
||||
return 6000;
|
||||
return 1000; // better to start low and increase
|
||||
},
|
||||
blockchain() {
|
||||
return useBlockchain();
|
||||
},
|
||||
connected(): boolean {
|
||||
return this.blockchain?.rpc as unknown as boolean;
|
||||
},
|
||||
currentChainId(): string {
|
||||
return this.latest.block?.header.chain_id || '';
|
||||
},
|
||||
@ -63,31 +64,31 @@ export const useBaseStore = defineStore('baseStore', {
|
||||
},
|
||||
actions: {
|
||||
async initial() {
|
||||
while (!this.connected) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
this.fetchLatest();
|
||||
},
|
||||
async clearRecentBlocks() {
|
||||
this.recents = [];
|
||||
},
|
||||
async fetchLatest() {
|
||||
try {
|
||||
if (this.connected) {
|
||||
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
|
||||
this.connected = true;
|
||||
} catch (e) {
|
||||
this.connected = false;
|
||||
}
|
||||
if (!this.earlest || this.earlest?.block?.header?.chain_id != this.latest?.block?.header?.chain_id) {
|
||||
//reset earlest and recents
|
||||
this.earlest = this.latest;
|
||||
this.recents = [];
|
||||
}
|
||||
//check if the block exists in recents
|
||||
if (this.recents.findIndex((x) => x?.block_id?.hash === this.latest?.block_id?.hash) === -1) {
|
||||
if (this.recents.length >= 50) {
|
||||
this.recents.shift();
|
||||
if (!this.earlest || this.earlest?.block?.header?.chain_id != this.latest?.block?.header?.chain_id) {
|
||||
//reset earlest and recents
|
||||
this.earlest = this.latest;
|
||||
this.recents = [];
|
||||
}
|
||||
//check if the block exists in recents
|
||||
if (this.recents.findIndex((x) => x?.block_id?.hash === this.latest?.block_id?.hash) === -1) {
|
||||
if (this.recents.length >= 50) {
|
||||
this.recents.shift();
|
||||
}
|
||||
this.recents.push(this.latest);
|
||||
}
|
||||
this.recents.push(this.latest);
|
||||
}
|
||||
return this.latest;
|
||||
return this.latest;
|
||||
},
|
||||
|
||||
async fetchValidatorByHeight(height?: number, offset = 0) {
|
||||
|
||||
@ -159,8 +159,8 @@ export const useDashboard = defineStore('dashboard', {
|
||||
},
|
||||
actions: {
|
||||
async initial() {
|
||||
//await this.loadingFromLocal();
|
||||
await this.loadingFromRegistry()
|
||||
await this.loadingFromLocal();
|
||||
//await this.loadingFromRegistry()
|
||||
},
|
||||
loadingPrices() {
|
||||
const coinIds = [] as string[];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user