forked from cerc-io/cosmos-explorer
Made search include chainName and simplified the url fix
This commit is contained in:
parent
b01588c94d
commit
2982f8e727
@ -11,7 +11,7 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const dashboardStore = useDashboard();
|
||||
const conf = computed(() => dashboardStore.getChainConfig(props.name) || {});
|
||||
const conf = computed(() => dashboardStore.chains[props.name] || {});
|
||||
|
||||
const addFavor = (e: Event) => {
|
||||
e.stopPropagation();
|
||||
|
@ -35,7 +35,7 @@ function changeEndpoint(item: Endpoint) {
|
||||
{{
|
||||
baseStore.latest?.block?.header?.height
|
||||
? `#${baseStore.latest.block.header.height}`
|
||||
: chainStore.current?.prettyName || ''
|
||||
: chainStore.chainName || ''
|
||||
}} <span class="text-error">{{ baseStore.connected ? '' : 'disconnected' }}</span>
|
||||
</div>
|
||||
<div
|
||||
|
@ -30,7 +30,7 @@ const validators = ref(stakingStore.validators)
|
||||
const keyword = ref("")
|
||||
|
||||
function loadSigningInfo(chainName: string) {
|
||||
const chain = dashboard.getChainConfig(chainName)
|
||||
const chain = dashboard.chains[chainName]
|
||||
if(chain && chain.endpoints.rest) {
|
||||
const client = CosmosRestClient.newDefault(chain.endpoints.rest[0].address)
|
||||
client.getSlashingSigningInfos().then( resp => {
|
||||
@ -95,7 +95,7 @@ function add() {
|
||||
|
||||
function changeChain() {
|
||||
validators.value = []
|
||||
const endpoint = dashboard.getChainConfig(selectChain.value).endpoints.rest?.at(0)?.address
|
||||
const endpoint = dashboard.chains[selectChain.value].endpoints.rest?.at(0)?.address
|
||||
if(!endpoint) return
|
||||
|
||||
const client = CosmosRestClient.newDefault(endpoint)
|
||||
@ -193,7 +193,7 @@ function color(v: string) {
|
||||
<div class="input-group input-group-md">
|
||||
<select v-model="selectChain" class="select select-bordered capitalize" @change="changeChain">
|
||||
<option v-for="v in dashboard.chains" :value="v.chainName">
|
||||
{{ v.prettyName }}
|
||||
{{ v.chainName }}
|
||||
</option>
|
||||
</select>
|
||||
<input v-model="keyword" type="text" class="input w-full" placeholder="keywords to filter validator">
|
||||
|
@ -29,7 +29,7 @@ async function initParamsForKeplr() {
|
||||
const coinDecimals = chain.assets[0].denom_units.find(x => x.denom === chain.assets[0].symbol.toLowerCase())?.exponent || 6
|
||||
conf.value = JSON.stringify({
|
||||
chainId: chainid,
|
||||
chainName: chain.prettyName,
|
||||
chainName: chain.chainName,
|
||||
rpc: chain.endpoints?.rpc?.at(0)?.address,
|
||||
rest: chain.endpoints?.rest?.at(0)?.address,
|
||||
bip44: {
|
||||
|
@ -49,7 +49,7 @@ async function initParamsForKeplr() {
|
||||
const coinDecimals = chain.assets[0].denom_units.find(x => x.denom === chain.assets[0].symbol.toLowerCase())?.exponent || 6
|
||||
conf.value = JSON.stringify({
|
||||
chainId: chainid,
|
||||
chainName: chain.prettyName,
|
||||
chainName: chain.chainName,
|
||||
rpc: chain.endpoints?.rpc?.at(0)?.address,
|
||||
rest: chain.endpoints?.rest?.at(0)?.address,
|
||||
bip44: {
|
||||
@ -103,7 +103,7 @@ async function initSnap() {
|
||||
|
||||
conf.value = JSON.stringify({
|
||||
chainId,
|
||||
chainName: chain.prettyName,
|
||||
chainName: chain.chainName,
|
||||
bech32Config: {
|
||||
bech32PrefixAccAddr: chain.bech32Prefix,
|
||||
},
|
||||
|
@ -17,7 +17,8 @@ const chains = computed(() => {
|
||||
const lowercaseKeywords = keywords.value.toLowerCase();
|
||||
|
||||
return Object.values(dashboard.chains).filter(
|
||||
(x: ChainConfig) => x.prettyName.toLowerCase().indexOf(lowercaseKeywords) > -1
|
||||
(x: ChainConfig) => x.chainName.toLowerCase().indexOf(lowercaseKeywords) > -1
|
||||
|| x.prettyName.toLowerCase().indexOf(lowercaseKeywords) > -1
|
||||
);
|
||||
} else {
|
||||
return Object.values(dashboard.chains);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useBlockchain } from "@/stores";
|
||||
import { useBlockchain, useDashboard } from "@/stores";
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
// @ts-ignore
|
||||
import { setupLayouts } from "virtual:generated-layouts";
|
||||
@ -15,10 +15,10 @@ router.beforeEach((to) => {
|
||||
const { chain } = to.params
|
||||
if(chain){
|
||||
const blockchain = useBlockchain()
|
||||
const lowercaseChain = chain.toString().toLowerCase();
|
||||
if(lowercaseChain !== blockchain.chainName)
|
||||
blockchain.setCurrent(lowercaseChain)
|
||||
}
|
||||
if(chain !== blockchain.chainName) {
|
||||
blockchain.setCurrent(chain.toString())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Docs: https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards
|
||||
|
@ -41,7 +41,7 @@ export const useBlockchain = defineStore('blockchain', {
|
||||
},
|
||||
getters: {
|
||||
current(): ChainConfig | undefined {
|
||||
return this.dashboard.getChainConfig(this.chainName);
|
||||
return this.dashboard.chains[this.chainName];
|
||||
},
|
||||
logo(): string {
|
||||
return this.current?.logo || '';
|
||||
@ -99,7 +99,7 @@ export const useBlockchain = defineStore('blockchain', {
|
||||
// compute favorite menu
|
||||
const favNavItems: VerticalNavItems = [];
|
||||
Object.keys(this.dashboard.favoriteMap).forEach((name) => {
|
||||
const ch = this.dashboard.getChainConfig(name);
|
||||
const ch = this.dashboard.chains[name];
|
||||
if (ch && this.dashboard.favoriteMap?.[name]) {
|
||||
favNavItems.push({
|
||||
title: ch.prettyName || ch.chainName || name,
|
||||
@ -175,9 +175,20 @@ export const useBlockchain = defineStore('blockchain', {
|
||||
JSON.stringify(endpoint)
|
||||
);
|
||||
},
|
||||
setCurrent(name: string) {
|
||||
if (name !== this.chainName) {
|
||||
this.chainName = name;
|
||||
async setCurrent(name: string) {
|
||||
// Ensure chains are loaded due to asynchronous calls.
|
||||
if(this.dashboard.length === 0) {
|
||||
await this.dashboard.initial();
|
||||
}
|
||||
|
||||
// Find the case-sensitive name for the chainName, else simply use the parameter-value.
|
||||
const caseSensitiveName =
|
||||
Object.keys(this.dashboard.chains).find((x) => x.toLowerCase() === name.toLowerCase())
|
||||
|| name;
|
||||
|
||||
// Update chainName if needed
|
||||
if (caseSensitiveName !== this.chainName) {
|
||||
this.chainName = caseSensitiveName;
|
||||
}
|
||||
},
|
||||
supportModule(mod: string) {
|
||||
|
@ -153,7 +153,7 @@ export function fromLocal(lc: LocalConfig): ChainConfig {
|
||||
cosmosSdk: lc.sdk_version
|
||||
}
|
||||
conf.bech32Prefix = lc.addr_prefix;
|
||||
conf.chainName = lc.chain_name.toLowerCase();
|
||||
conf.chainName = lc.chain_name;
|
||||
conf.coinType = lc.coin_type;
|
||||
conf.prettyName = lc.registry_name || lc.chain_name;
|
||||
conf.endpoints = {
|
||||
@ -178,7 +178,7 @@ export function fromDirectory(source: DirectoryChain): ChainConfig {
|
||||
(conf.assets = source.assets),
|
||||
(conf.bech32Prefix = source.bech32_prefix),
|
||||
(conf.chainId = source.chain_id),
|
||||
(conf.chainName = source.chain_name.toLowerCase()),
|
||||
(conf.chainName = source.chain_name),
|
||||
(conf.prettyName = source.pretty_name),
|
||||
(conf.versions = {
|
||||
application: source.versions?.application_version || '',
|
||||
@ -275,9 +275,9 @@ export const useDashboard = defineStore('dashboard', {
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
initial() {
|
||||
this.loadingFromLocal();
|
||||
// this.loadingFromRegistry()
|
||||
async initial() {
|
||||
await this.loadingFromLocal();
|
||||
// await this.loadingFromRegistry()
|
||||
},
|
||||
loadingPrices() {
|
||||
const coinIds = [] as string[]
|
||||
@ -308,7 +308,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
this.status = LoadingStatus.Loading;
|
||||
get(this.source).then((res) => {
|
||||
res.chains.forEach((x: DirectoryChain) => {
|
||||
this.chains[x.chain_name.toLowerCase()] = fromDirectory(x);
|
||||
this.chains[x.chain_name] = fromDirectory(x);
|
||||
});
|
||||
this.status = LoadingStatus.Loaded;
|
||||
});
|
||||
@ -323,7 +323,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
? import.meta.glob('../../chains/mainnet/*.json', { eager: true })
|
||||
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
|
||||
Object.values<LocalConfig>(source).forEach((x: LocalConfig) => {
|
||||
this.chains[x.chain_name.toLowerCase()] = fromLocal(x);
|
||||
this.chains[x.chain_name] = fromLocal(x);
|
||||
});
|
||||
this.setupDefault();
|
||||
this.status = LoadingStatus.Loaded;
|
||||
@ -335,7 +335,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
? import.meta.glob('../../chains/mainnet/*.json', { eager: true })
|
||||
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
|
||||
Object.values<LocalConfig>(source).forEach((x: LocalConfig) => {
|
||||
config[x.chain_name.toLowerCase()] = fromLocal(x);
|
||||
config[x.chain_name] = fromLocal(x);
|
||||
});
|
||||
return config
|
||||
},
|
||||
@ -360,8 +360,5 @@ export const useDashboard = defineStore('dashboard', {
|
||||
this.source = newSource;
|
||||
this.initial();
|
||||
},
|
||||
getChainConfig(chainId: string): ChainConfig {
|
||||
return this.chains[chainId.toLowerCase()];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user