From eb79884c078591e3fffd1f4b611b4cb506c86f3d Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 14 May 2023 09:23:18 +0800 Subject: [PATCH] atomatically load latest --- src/layouts/components/ChainProfile.vue | 4 +-- src/main.ts | 4 +-- src/modules/[chain]/block/[height].vue | 22 +++++++++------- src/modules/[chain]/block/index.vue | 21 +++++++-------- src/modules/[chain]/index.vue | 21 +++++++-------- src/modules/[chain]/staking/index.vue | 25 ++++++++---------- src/stores/useBaseStore.ts | 34 ++++++++++++++++++++++--- src/stores/useFormatter.ts | 7 ++--- 8 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/layouts/components/ChainProfile.vue b/src/layouts/components/ChainProfile.vue index 0b88819c..b1049d80 100644 --- a/src/layouts/components/ChainProfile.vue +++ b/src/layouts/components/ChainProfile.vue @@ -86,8 +86,8 @@ chainStore.$subscribe((m, s) => {
- {{ - baseStore.latest.block?.header?.chain_id || chainStore.chainName || '' + #{{ + baseStore.latest?.block?.header?.height || chainStore.chainName || '' }}
{blockStore.fetchLatest()}, 6000) +const blockStore = useBaseStore() +setInterval(() => {blockStore.fetchLatest()}, 6000) diff --git a/src/modules/[chain]/block/[height].vue b/src/modules/[chain]/block/[height].vue index a0b3a3f8..bbc8b232 100644 --- a/src/modules/[chain]/block/[height].vue +++ b/src/modules/[chain]/block/[height].vue @@ -5,19 +5,23 @@ import { useBlockModule } from './block'; import DynamicComponent from '@/components/dynamic/DynamicComponent.vue'; import { computed } from '@vue/reactivity'; import { onBeforeRouteUpdate } from 'vue-router'; +import { useBaseStore } from '@/stores'; +import { ref } from 'vue'; +import type { Block } from '@/types'; const props = defineProps(['height', 'chain']); -const store = useBlockModule(); -store.fetchBlock(props.height); +const store = useBaseStore(); const tab = ref('summary'); +const current = ref({} as Block) +store.fetchBlock(props.height).then(x => current.value = x) const height = computed(() => { - return Number(store.current.block?.header?.height || props.height || 0); + return Number(current.value.block?.header?.height || props.height || 0); }); onBeforeRouteUpdate(async (to, from, next) => { if (from.path !== to.path) { - store.fetchBlock(String(to.params.height)); + store.fetchBlock(String(to.params.height)).then(x => current.value = x); next(); } }); @@ -26,7 +30,7 @@ onBeforeRouteUpdate(async (to, from, next) => {

-

#{{ store.current.block?.header?.height }}

+

#{{ current.block?.header?.height }}

{

- +

Block Header

- +

Transactions

- +

Last Commit

- +
diff --git a/src/modules/[chain]/block/index.vue b/src/modules/[chain]/block/index.vue index 78c0f946..6c952852 100644 --- a/src/modules/[chain]/block/index.vue +++ b/src/modules/[chain]/block/index.vue @@ -1,13 +1,12 @@