diff --git a/src/modules/[chain]/indexStore.ts b/src/modules/[chain]/indexStore.ts index a117b09953..faf40646b5 100644 --- a/src/modules/[chain]/indexStore.ts +++ b/src/modules/[chain]/indexStore.ts @@ -27,7 +27,6 @@ export function colorMap(color: string) { export const useIndexModule = defineStore('module-index', { state: () => { return { - transactionCount: 0 as number, days: 14, tickerIndex: 0, coinInfo: { @@ -78,7 +77,8 @@ export const useIndexModule = defineStore('module-index', { }, getters: { txCount(): number { - return this.transactionCount; + const chain = useBlockchain(); + return chain.txCount; }, blockchain() { const chain = useBlockchain(); @@ -214,6 +214,7 @@ export const useIndexModule = defineStore('module-index', { this.$reset(); this.initCoingecko(); useMintStore().fetchInflation(); + useBlockchain().fetchTxCount(); useDistributionStore() .fetchCommunityPool() .then((x) => { @@ -224,22 +225,6 @@ export const useIndexModule = defineStore('module-index', { denom: t.denom, })); }); - // const gov = useGovStore(); - // gov.fetchProposals('2').then((x) => { - // this.proposals = x; - // }); - // Fetch the transaction count - try { - const response = await fetch('https://chain-data.xion-testnet-1.burnt.com/api/txs/count'); - if (!response.ok) { - throw new Error(`HTTP error! Status: ${response.status}`); - } - const data = await response.json(); - this.transactionCount = data.count; - } catch (error) { - console.error('Fetching transaction count failed', error); - this.transactionCount = 0; - } }, tickerColor(color: string) { return colorMap(color); diff --git a/src/stores/useBlockchain.ts b/src/stores/useBlockchain.ts index ac1ae2ccb7..d87f56a889 100644 --- a/src/stores/useBlockchain.ts +++ b/src/stores/useBlockchain.ts @@ -36,6 +36,7 @@ export const useBlockchain = defineStore('blockchain', { address: string; provider: string; }, + tx_count: 0 as number, connErr: '', }; }, @@ -49,6 +50,9 @@ export const useBlockchain = defineStore('blockchain', { } return chain; }, + txCount(): number { + return this.tx_count + }, logo(): string { return this.current?.logo || ''; }, @@ -167,6 +171,29 @@ export const useBlockchain = defineStore('blockchain', { } }, + async fetchTxCount() { + try { + let response; + console.log('fetching tx count', this.chainName); + if (this.chainName === 'xion-testnet-1') { + response = await fetch('https://chain-data.xion-testnet-1.burnt.com/api/txs/count'); + } else { + response = await fetch('https://chain-data.xion-mainnet-1.burnt.com/api/txs/count'); + } + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const data = await response.json(); + this.tx_count = data.count; + + } catch (error) { + console.error('Fetching transaction count failed', error); + this.tx_count = 0; + } + }, + async randomSetupEndpoint() { const endpoint = this.randomEndpoint(this.chainName) if(endpoint) await this.setRestEndpoint(endpoint); @@ -188,8 +215,8 @@ export const useBlockchain = defineStore('blockchain', { } // Find the case-sensitive name for the chainName, else simply use the parameter-value. - const caseSensitiveName = - Object.keys(this.dashboard.chains).find((x) => x.toLowerCase() === name.toLowerCase()) + const caseSensitiveName = + Object.keys(this.dashboard.chains).find((x) => x.toLowerCase() === name.toLowerCase()) || name; // Update chainName if needed