From 42009219a745de71795e863cbfef66240e96b562 Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Wed, 20 Sep 2023 10:12:57 +0800
Subject: [PATCH] endpoint switch improvement
---
src/layouts/components/ChainProfile.vue | 2 +-
src/layouts/components/DefaultLayout.vue | 10 ++++++++--
src/stores/useBaseStore.ts | 11 +++++++++--
src/stores/useBlockchain.ts | 1 -
4 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/layouts/components/ChainProfile.vue b/src/layouts/components/ChainProfile.vue
index d1d3bebcaf..affc1cb3c4 100644
--- a/src/layouts/components/ChainProfile.vue
+++ b/src/layouts/components/ChainProfile.vue
@@ -33,7 +33,7 @@ function changeEndpoint(item: Endpoint) {
baseStore.latest?.block?.header?.height ||
chainStore.chainName ||
''
- }}
+ }} {{ baseStore.connected ? '' : 'disconnected' }}
{
+ if(current.value ===s.chainName && temp.value != s.endpoint.address) {
+ temp.value = s.endpoint.address
+ blockchain.initial();
+ }
if (current.value != s.chainName) {
current.value = s.chainName;
- blockchain.initial();
+ blockchain.randomSetupEndpoint();
}
});
diff --git a/src/stores/useBaseStore.ts b/src/stores/useBaseStore.ts
index 7641dd1361..48109eb443 100644
--- a/src/stores/useBaseStore.ts
+++ b/src/stores/useBaseStore.ts
@@ -5,6 +5,7 @@ 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: () => {
@@ -15,6 +16,7 @@ export const useBaseStore = defineStore('baseStore', {
theme: (window.localStorage.getItem('theme') || 'dark') as
| 'light'
| 'dark',
+ connected: true,
};
},
getters: {
@@ -66,13 +68,18 @@ export const useBaseStore = defineStore('baseStore', {
},
actions: {
async initial() {
- this.fetchLatest();
+ this.fetchLatest()
},
async clearRecentBlocks() {
this.recents = [];
},
async fetchLatest() {
- this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
+ try{
+ this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
+ this.connected = true
+ }catch(e) {
+ this.connected = false
+ }
if (
!this.earlest ||
this.earlest?.block?.header?.chain_id !=
diff --git a/src/stores/useBlockchain.ts b/src/stores/useBlockchain.ts
index 5dbb0dfc2c..3af2e5f7f7 100644
--- a/src/stores/useBlockchain.ts
+++ b/src/stores/useBlockchain.ts
@@ -139,7 +139,6 @@ export const useBlockchain = defineStore('blockchain', {
// global.current
// }
useWalletStore().$reset();
- await this.randomSetupEndpoint();
await useStakingStore().init();
useBankStore().initial();
useBaseStore().initial();