From 2982f8e72730ef4b276715fb137b033d47b630d0 Mon Sep 17 00:00:00 2001 From: zenodeapp Date: Mon, 4 Dec 2023 12:10:45 +0100 Subject: [PATCH] Made search include chainName and simplified the url fix --- src/components/ChainSummary.vue | 2 +- src/layouts/components/ChainProfile.vue | 2 +- src/modules/[chain]/uptime/customize.vue | 6 +++--- src/modules/wallet/keplr.vue | 2 +- src/modules/wallet/suggest.vue | 4 ++-- src/pages/index.vue | 3 ++- src/router/index.ts | 10 +++++----- src/stores/useBlockchain.ts | 21 ++++++++++++++++----- src/stores/useDashboard.ts | 19 ++++++++----------- 9 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/components/ChainSummary.vue b/src/components/ChainSummary.vue index dd86afe2..53edb036 100644 --- a/src/components/ChainSummary.vue +++ b/src/components/ChainSummary.vue @@ -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(); diff --git a/src/layouts/components/ChainProfile.vue b/src/layouts/components/ChainProfile.vue index 1674ca3e..caecee91 100644 --- a/src/layouts/components/ChainProfile.vue +++ b/src/layouts/components/ChainProfile.vue @@ -35,7 +35,7 @@ function changeEndpoint(item: Endpoint) { {{ baseStore.latest?.block?.header?.height ? `#${baseStore.latest.block.header.height}` - : chainStore.current?.prettyName || '' + : chainStore.chainName || '' }} {{ baseStore.connected ? '' : 'disconnected' }}
{ @@ -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) {
diff --git a/src/modules/wallet/keplr.vue b/src/modules/wallet/keplr.vue index e30d8388..1f5b2749 100644 --- a/src/modules/wallet/keplr.vue +++ b/src/modules/wallet/keplr.vue @@ -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: { diff --git a/src/modules/wallet/suggest.vue b/src/modules/wallet/suggest.vue index 70dd66bc..818262d5 100644 --- a/src/modules/wallet/suggest.vue +++ b/src/modules/wallet/suggest.vue @@ -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, }, diff --git a/src/pages/index.vue b/src/pages/index.vue index 768b01b0..855b6886 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -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); diff --git a/src/router/index.ts b/src/router/index.ts index 32ed023f..4426b162 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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 diff --git a/src/stores/useBlockchain.ts b/src/stores/useBlockchain.ts index ba85e1d2..c8016fee 100644 --- a/src/stores/useBlockchain.ts +++ b/src/stores/useBlockchain.ts @@ -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) { diff --git a/src/stores/useDashboard.ts b/src/stores/useDashboard.ts index 7820bbd3..6c32ea55 100644 --- a/src/stores/useDashboard.ts +++ b/src/stores/useDashboard.ts @@ -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(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(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()]; - } }, });