fix: chain network switch

This commit is contained in:
Alisa | Side.one 2023-05-26 15:05:20 +08:00
parent f693684222
commit 6a9823893c

View File

@ -1,28 +1,49 @@
<script setup lang="ts"> <script setup lang="ts">
import router from '@/router';
import { useBlockchain, useBaseStore, type Endpoint } from '@/stores'; import { useBlockchain, useBaseStore, type Endpoint } from '@/stores';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
const chainStore = useBlockchain(); const chainStore = useBlockchain();
const baseStore = useBaseStore(); const baseStore = useBaseStore();
chainStore.initial(); chainStore.initial();
const router = useRouter();
function changeEndpoint(item: Endpoint) { function changeEndpoint(item: Endpoint) {
console.log('change') chainStore.setRestEndpoint(item);
chainStore.setRestEndpoint(item) if (chainStore.current) router.push(`/${chainStore.current.chainName}`);
const router = useRouter()
if(chainStore.current) router.push(`/${chainStore.current.chainName}`)
} }
</script> </script>
<template> <template>
<div class="flex items-center">
<div class="dropdown"> <div class="dropdown">
<div tabindex="0" class="p-1 relative mr-3 cursor-pointer"> <label tabindex="0" class="flex items-center">
<div class="p-1 relative mr-3 cursor-pointer">
<img v-lazy="chainStore.logo" class="w-9 h-9 rounded-full" /> <img v-lazy="chainStore.logo" class="w-9 h-9 rounded-full" />
<div <div
class="w-2 h-2 rounded-full bg-yes absolute right-0 bottom-0 shadow" class="w-2 h-2 rounded-full bg-yes absolute right-0 bottom-0 shadow"
></div> ></div>
</div> </div>
<div class="flex-1 w-0">
<div <div
:key="
baseStore.latest?.block?.header?.height ||
chainStore.chainName ||
''
"
class="capitalize whitespace-nowrap text-base font-semibold text-gray-600 dark:text-gray-200 hidden md:!block"
>
#{{
baseStore.latest?.block?.header?.height ||
chainStore.chainName ||
''
}}
</div>
<div
class="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap hidden md:!block"
>
{{ chainStore.connErr || chainStore.endpoint.address }}
</div>
</div>
</label>
<div
tabindex="0"
class="dropdown-content w-80 menu shadow bg-base-200 rounded-box max-h-[300px] overflow-auto" class="dropdown-content w-80 menu shadow bg-base-200 rounded-box max-h-[300px] overflow-auto"
> >
<!-- rest --> <!-- rest -->
@ -32,13 +53,13 @@ function changeEndpoint(item: Endpoint) {
> >
Rest Endpoint Rest Endpoint
</div> </div>
<label <div
v-for="(item, index) in chainStore.current?.endpoints?.rest" v-for="(item, index) in chainStore.current?.endpoints?.rest"
class="px-4 py-2 w-full hover:bg-gray-100 dark:bg-[#384059] cursor-pointer" class="px-4 py-2 w-full hover:bg-gray-100 dark:hover:bg-[#384059] cursor-pointer"
:key="index" :key="index"
@click="changeEndpoint(item)"
> >
<div class="flex flex-col" <div class="flex flex-col">
@click="changeEndpoint(item)">
<div class="flex items-center justify-between w-full"> <div class="flex items-center justify-between w-full">
<div class="text-gray-500 dark:text-gray-200 capitalize"> <div class="text-gray-500 dark:text-gray-200 capitalize">
{{ item.provider }} {{ item.provider }}
@ -52,12 +73,11 @@ function changeEndpoint(item: Endpoint) {
{{ item.address }} {{ item.address }}
</div> </div>
</div> </div>
</label>
<!-- rest -->
<div class="px-4 py-2 text-sm text-gray-400">
Information
</div> </div>
<div class="w-full hover:bg-gray-100 dark:bg-[#384059]">
<!-- rest -->
<div class="px-4 py-2 text-sm text-gray-400">Information</div>
<div class="w-full">
<div class="py-2 px-4"> <div class="py-2 px-4">
Chain Id: {{ baseStore.latest.block?.header.chain_id }} Chain Id: {{ baseStore.latest.block?.header.chain_id }}
</div> </div>
@ -67,19 +87,4 @@ function changeEndpoint(item: Endpoint) {
</div> </div>
</div> </div>
</div> </div>
<div class="flex-1 w-0">
<div :key="baseStore.latest?.block?.header?.height || chainStore.chainName || ''"
class="capitalize whitespace-nowrap text-base font-semibold text-gray-600 dark:text-gray-200 hidden md:!block"
>
#{{
baseStore.latest?.block?.header?.height || chainStore.chainName || ''
}}
</div>
<div
class="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap hidden md:!block"
>
{{ chainStore.connErr || chainStore.endpoint.address }}
</div>
</div>
</div>
</template> </template>