endpoint switch improvement
This commit is contained in:
parent
bae700f822
commit
42009219a7
@ -33,7 +33,7 @@ function changeEndpoint(item: Endpoint) {
|
|||||||
baseStore.latest?.block?.header?.height ||
|
baseStore.latest?.block?.header?.height ||
|
||||||
chainStore.chainName ||
|
chainStore.chainName ||
|
||||||
''
|
''
|
||||||
}}
|
}} <span class="text-error">{{ baseStore.connected ? '' : 'disconnected' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap hidden md:!block"
|
class="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap hidden md:!block"
|
||||||
|
@ -18,12 +18,18 @@ import type { NavGroup, NavLink, NavSectionTitle, VerticalNavItems } from '../ty
|
|||||||
const dashboard = useDashboard();
|
const dashboard = useDashboard();
|
||||||
dashboard.initial();
|
dashboard.initial();
|
||||||
const blockchain = useBlockchain();
|
const blockchain = useBlockchain();
|
||||||
|
blockchain.randomSetupEndpoint();
|
||||||
|
|
||||||
const current = ref('');
|
const current = ref(''); // the current chain
|
||||||
|
const temp = ref('')
|
||||||
blockchain.$subscribe((m, s) => {
|
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) {
|
if (current.value != s.chainName) {
|
||||||
current.value = s.chainName;
|
current.value = s.chainName;
|
||||||
blockchain.initial();
|
blockchain.randomSetupEndpoint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import dayjs from 'dayjs';
|
|||||||
import type { Block } from '@/types';
|
import type { Block } from '@/types';
|
||||||
import { hashTx } from '@/libs';
|
import { hashTx } from '@/libs';
|
||||||
import { fromBase64 } from '@cosmjs/encoding';
|
import { fromBase64 } from '@cosmjs/encoding';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
export const useBaseStore = defineStore('baseStore', {
|
export const useBaseStore = defineStore('baseStore', {
|
||||||
state: () => {
|
state: () => {
|
||||||
@ -15,6 +16,7 @@ export const useBaseStore = defineStore('baseStore', {
|
|||||||
theme: (window.localStorage.getItem('theme') || 'dark') as
|
theme: (window.localStorage.getItem('theme') || 'dark') as
|
||||||
| 'light'
|
| 'light'
|
||||||
| 'dark',
|
| 'dark',
|
||||||
|
connected: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@ -66,13 +68,18 @@ export const useBaseStore = defineStore('baseStore', {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async initial() {
|
async initial() {
|
||||||
this.fetchLatest();
|
this.fetchLatest()
|
||||||
},
|
},
|
||||||
async clearRecentBlocks() {
|
async clearRecentBlocks() {
|
||||||
this.recents = [];
|
this.recents = [];
|
||||||
},
|
},
|
||||||
async fetchLatest() {
|
async fetchLatest() {
|
||||||
|
try{
|
||||||
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
|
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
|
||||||
|
this.connected = true
|
||||||
|
}catch(e) {
|
||||||
|
this.connected = false
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
!this.earlest ||
|
!this.earlest ||
|
||||||
this.earlest?.block?.header?.chain_id !=
|
this.earlest?.block?.header?.chain_id !=
|
||||||
|
@ -139,7 +139,6 @@ export const useBlockchain = defineStore('blockchain', {
|
|||||||
// global.current
|
// global.current
|
||||||
// }
|
// }
|
||||||
useWalletStore().$reset();
|
useWalletStore().$reset();
|
||||||
await this.randomSetupEndpoint();
|
|
||||||
await useStakingStore().init();
|
await useStakingStore().init();
|
||||||
useBankStore().initial();
|
useBankStore().initial();
|
||||||
useBaseStore().initial();
|
useBaseStore().initial();
|
||||||
|
Loading…
Reference in New Issue
Block a user