Skip to content

Commit

Permalink
endpoint switch improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
liangping committed Sep 20, 2023
1 parent bae700f commit 4200921
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/layouts/components/ChainProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function changeEndpoint(item: Endpoint) {
baseStore.latest?.block?.header?.height ||
chainStore.chainName ||
''
}}
}} <span class="text-error">{{ baseStore.connected ? '' : 'disconnected' }}</span>
</div>
<div
class="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap hidden md:!block"
Expand Down
10 changes: 8 additions & 2 deletions src/layouts/components/DefaultLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ import type { NavGroup, NavLink, NavSectionTitle, VerticalNavItems } from '../ty
const dashboard = useDashboard();
dashboard.initial();
const blockchain = useBlockchain();
blockchain.randomSetupEndpoint();
const current = ref('');
const current = ref(''); // the current chain
const temp = ref('')
blockchain.$subscribe((m, s) => {
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();
}
});
Expand Down
11 changes: 9 additions & 2 deletions src/stores/useBaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand All @@ -15,6 +16,7 @@ export const useBaseStore = defineStore('baseStore', {
theme: (window.localStorage.getItem('theme') || 'dark') as
| 'light'
| 'dark',
connected: true,
};
},
getters: {
Expand Down Expand Up @@ -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 !=
Expand Down
1 change: 0 additions & 1 deletion src/stores/useBlockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export const useBlockchain = defineStore('blockchain', {
// global.current
// }
useWalletStore().$reset();
await this.randomSetupEndpoint();
await useStakingStore().init();
useBankStore().initial();
useBaseStore().initial();
Expand Down

0 comments on commit 4200921

Please sign in to comment.