Skip to content

Commit 6d85f2f

Browse files
authored
Merge pull request #647 from burnt-labs/feat/blocktime
add optional basestore features, eliminate redundant block fetching
2 parents 1bfc76c + 20325c0 commit 6d85f2f

File tree

13 files changed

+274
-112
lines changed

13 files changed

+274
-112
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# rename to .env.local or .env.<your_environment>
2+
VITE_REFRESH_INTERVAL=2000
3+
VITE_FETCH_ALL_BLOCKS=true
4+
VITE_RECENT_BLOCK_LIMIT=100

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ node_modules/
22
**/.vscode
33
yarn-error.log
44
dist
5-
.idea
5+
.idea
6+
7+
.env*
8+
!.env.example

chains/mainnet/xion.json

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"chain_name": "xion",
3+
"registry_name": "xion",
4+
"coingecko": "xion",
5+
"network_type": "mainnet",
6+
"rpc": [
7+
{
8+
"address": "https://rpc.xion-mainnet-1.burnt.com",
9+
"provider": "🔥BurntLabs🔥"
10+
},
11+
{
12+
"address": "https://rpc-burnt.imperator.co/",
13+
"provider": "Imperator.co"
14+
},
15+
{
16+
"address": "https://xion-rpc.polkachu.com",
17+
"provider": "Polkachu"
18+
}
19+
],
20+
"api": [
21+
{
22+
"address": "https://api.xion-mainnet-1.burnt.com",
23+
"provider": "🔥BurntLabs🔥"
24+
},
25+
{
26+
"address": "https://lcd-burnt.imperator.co/",
27+
"provider": "Imperator.co"
28+
},
29+
{
30+
"address": "https://xion-api.polkachu.com",
31+
"provider": "Polkachu"
32+
}
33+
],
34+
"snapshot_provider": "",
35+
"sdk_version": "0.50.13",
36+
"coin_type": "118",
37+
"min_tx_fee": "100",
38+
"addr_prefix": "xion",
39+
"theme_color": "#96b325",
40+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png",
41+
"assets": [
42+
{
43+
"base": "uxion",
44+
"symbol": "XION",
45+
"exponent": "6",
46+
"coingecko_id": "xion-2",
47+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png"
48+
},
49+
{
50+
"base": "ibc/0471F1C4E7AFD3F07702BEF6DC365268D64570F7C1FDC98EA6098DD6DE59817B",
51+
"symbol": "OSMO",
52+
"exponent": "6",
53+
"coingecko_id": "osmosis",
54+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png"
55+
},
56+
{
57+
"base": "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349",
58+
"symbol": "USDC",
59+
"exponent": "6",
60+
"coingecko_id": "usd-coin",
61+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png"
62+
},
63+
{
64+
"base": "ibc/CC7B293B3F08EA7DB96AFD4765BD0C7F95ABD7ECEAF21C74F3ACCBF7CEFB6591",
65+
"symbol": "OSMO",
66+
"exponent": "6",
67+
"coingecko_id": "osmosis",
68+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png"
69+
},
70+
{
71+
"base": "ibc/9463E39D230614B313B487836D13A392BD1731928713D4C8427A083627048DB3",
72+
"symbol": "AXL",
73+
"exponent": "6",
74+
"coingecko_id": "axelar",
75+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"
76+
},
77+
{
78+
"base": "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4",
79+
"symbol": "axlUSDC",
80+
"exponent": "6",
81+
"coingecko_id": "usd-coin",
82+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png"
83+
},
84+
{
85+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
86+
"symbol": "axlUSDT",
87+
"exponent": "6",
88+
"coingecko_id": "tether",
89+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png"
90+
},
91+
{
92+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
93+
"symbol": "axlDAI",
94+
"exponent": "18",
95+
"coingecko_id": "dai",
96+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axldai.png"
97+
},
98+
{
99+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
100+
"symbol": "axlFRAX",
101+
"exponent": "6",
102+
"coingecko_id": "frax",
103+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlfrax.png"
104+
},
105+
{
106+
"base": "ibc/AAD7136DD626569C3DDE7C5F764968BB2E939875EFC568AE5712B62081850814",
107+
"symbol": "axlWETH",
108+
"exponent": "18",
109+
"coingecko_id": "axlweth",
110+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"
111+
},
112+
{
113+
"base": "ibc/056EA54C3D9B49B3C0418955A27980A91DD4F210914BFE240A1DB19E27895ECA",
114+
"symbol": "KYVE",
115+
"exponent": "6",
116+
"coingecko_id": "kyve-network",
117+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/kyve/images/kyve-token.png"
118+
},
119+
{
120+
"base": "ibc/DBE9697AC1044255A305A2034AD360B4152632BFBFB5785234731F60196B9645",
121+
"symbol": "ELYS",
122+
"exponent": "6",
123+
"coingecko_id": "elys",
124+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/elys/images/elys.png"
125+
},
126+
{
127+
"base": "ibc/E706A0C6CACB374ADC2BCF6A74FE1B260840FC822E45DCB776DEA962A57FED30",
128+
"symbol": "axlARB",
129+
"exponent": "18",
130+
"coingecko_id": "arb",
131+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/arbitrum/images/arb.png"
132+
}
133+
],
134+
"features": [
135+
"dashboard",
136+
"governance",
137+
"staking",
138+
"blocks",
139+
"tx",
140+
"uptime",
141+
"ibc",
142+
"supply",
143+
"parameters",
144+
"consensus",
145+
"cosmwasm",
146+
"account"
147+
],
148+
"keplr_features": ["ibc-go", "ibc-transfer", "no-legacy-stdTx"]
149+
}

src/components/ChainSummary.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { useDashboard } from '@/stores/useDashboard';
2+
import { useDashboard } from '@/stores';
33
import { computed } from 'vue';
44
import { Icon } from '@iconify/vue';
55

src/components/charts/TxsInBlocksChart.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const options = computed(() => {
2828
},
2929
show: false,
3030
categories: baseStore.recents
31+
.slice(0, 50)
3132
.map((x) => x.block.header.height)
32-
.concat(Array(50 - baseStore.recents.length).fill('')),
33+
.concat(Array(Math.max(0, 50)).fill('')),
3334
},
3435
};
3536
});

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createPinia } from 'pinia';
77
import LazyLoad from 'lazy-load-vue3';
88

99
import router from './router';
10-
import { useBaseStore } from './stores/useBaseStore';
10+
import { useBaseStore } from '@/stores';
1111

1212
// Create vue app
1313
const app = createApp(App);
@@ -19,6 +19,8 @@ app.use(LazyLoad, { component: true });
1919
// Mount vue app
2020
app.mount('#app');
2121

22+
const REFRESH_INTERVAL = import.meta.env.VITE_REFRESH_INTERVAL || 6000; // 6 seconds
23+
2224
// fetch latest block every 6s
2325
const blockStore = useBaseStore();
2426
const requestCounter = ref(0);
@@ -28,4 +30,4 @@ setInterval(() => {
2830
// max allowed request
2931
blockStore.fetchLatest().finally(() => (requestCounter.value -= 1));
3032
}
31-
}, 6000);
33+
}, REFRESH_INTERVAL);

src/modules/[chain]/block/block.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,42 @@
11
import { defineStore } from 'pinia';
2-
import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing';
3-
import { useBlockchain } from '@/stores';
4-
import { hashTx } from '@/libs';
5-
import type { Block } from '@/types';
2+
import { useBaseStore, useBlockchain } from '@/stores';
63

74
export const useBlockModule = defineStore('blockModule', {
8-
state: () => {
9-
return {
10-
latest: {} as Block,
11-
current: {} as Block,
12-
recents: [] as Block[],
13-
};
14-
},
155
getters: {
6+
baseStore() {
7+
return useBaseStore();
8+
},
169
blockchain() {
1710
return useBlockchain();
1811
},
1912
blocktime() {
20-
if (this.recents.length < 2) return 6000;
21-
return 6000; // todo later
13+
return useBaseStore().blocktime;
2214
},
2315
txsInRecents() {
24-
const txs = [] as { hash: string; tx: DecodedTxRaw }[];
25-
this.recents.forEach((x) =>
26-
x.block?.data?.txs.forEach((tx: Uint8Array) => {
27-
if (tx) {
28-
try {
29-
txs.push({
30-
hash: hashTx(tx),
31-
tx: decodeTxRaw(tx),
32-
});
33-
} catch (e) {}
34-
}
35-
})
36-
);
37-
return txs;
16+
return useBaseStore().txsInRecents;
17+
},
18+
latest(){
19+
return useBaseStore().latest;
3820
},
21+
earliest() {
22+
return useBaseStore().earliest;
23+
},
24+
recents() {
25+
return useBaseStore().recents;
26+
}
3927
},
4028
actions: {
4129
initial() {
4230
this.clearRecentBlocks();
43-
this.autoFetch();
4431
},
4532
async clearRecentBlocks() {
46-
this.recents = [];
47-
},
48-
autoFetch() {
49-
this.fetchLatest().then((x) => {
50-
const timer = this.autoFetch;
51-
this.latest = x;
52-
// if(this.recents.length >= 50) this.recents.pop()
53-
// this.recents.push(x)
54-
// setTimeout(timer, 6000)
55-
});
33+
return this.baseStore.clearRecentBlocks()
5634
},
5735
async fetchLatest() {
58-
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
59-
if (this.recents.length >= 50) this.recents.shift();
60-
this.recents.push(this.latest);
61-
return this.latest;
36+
return this.baseStore.fetchLatest()
6237
},
6338
async fetchBlock(height: string) {
64-
this.current = await this.blockchain.rpc?.getBaseBlockAt(height);
65-
return this.current;
39+
return this.baseStore.fetchBlock(height)
6640
},
6741
},
6842
});

src/modules/[chain]/consensus/index.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts" setup>
22
import fetch from 'cross-fetch';
33
import { onMounted, ref, computed, onUnmounted } from 'vue';
4-
import { useBlockchain, useFormatter, useStakingStore } from '@/stores';
4+
import { useBlockchain, useFormatter, useStakingStore, useBaseStore } from '@/stores';
55
import { consensusPubkeyToHexAddress } from '@/libs';
66
77
const format = useFormatter();
88
const chainStore = useBlockchain();
99
const stakingStore = useStakingStore();
10+
const baseStore = useBaseStore();
1011
const rpcList = ref(chainStore.current?.endpoints?.rpc || [{ address: '', provider: '' }]);
1112
let rpc = ref('');
1213
const validators = ref(stakingStore.validators);
@@ -31,7 +32,7 @@ onMounted(async () => {
3132
clearTime();
3233
timer = setInterval(() => {
3334
update();
34-
}, 6000);
35+
}, Math.round(baseStore.blocktime / 2));
3536
});
3637
onUnmounted(() => {
3738
clearTime();
@@ -87,7 +88,7 @@ async function onChange() {
8788
update();
8889
timer = setInterval(() => {
8990
update();
90-
}, 6000);
91+
}, Math.round(baseStore.blocktime / 2));
9192
}
9293
9394
async function fetchPosition() {

src/modules/[chain]/indexStore.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { useBlockchain, useCoingecko, useBaseStore, useBankStore, useFormatter, useGovStore } from '@/stores';
2-
import { useDistributionStore } from '@/stores/useDistributionStore';
3-
import { useMintStore } from '@/stores/useMintStore';
4-
import { useStakingStore } from '@/stores/useStakingStore';
1+
import {
2+
useBlockchain,
3+
useCoingecko,
4+
useBaseStore,
5+
useBankStore,
6+
useFormatter,
7+
useGovStore,
8+
useDistributionStore,
9+
useMintStore,
10+
useStakingStore,
11+
} from '@/stores';
512
import type { Coin, Tally } from '@/types';
613
import numeral from 'numeral';
714
import { defineStore } from 'pinia';
@@ -157,9 +164,7 @@ export const useIndexModule = defineStore('module-index', {
157164
title: 'Validators',
158165
color: 'error',
159166
icon: 'mdi-human-queue',
160-
stats: String(
161-
base?.latest?.block?.last_commit?.signatures.length || 0
162-
),
167+
stats: String(base?.latest?.block?.last_commit?.signatures.length || 0),
163168
change: 0,
164169
},
165170
{
@@ -256,11 +261,7 @@ export const useIndexModule = defineStore('module-index', {
256261
* @param value - The value to set for the parameter.
257262
* @returns The new URL with the parameter added or replaced.
258263
*/
259-
export function addOrReplaceUrlParam(
260-
url: string,
261-
param: string,
262-
value: string
263-
): string {
264+
export function addOrReplaceUrlParam(url: string, param: string, value: string): string {
264265
// Parse the URL
265266
const urlObj = new URL(url, window.location.origin);
266267

0 commit comments

Comments
 (0)