diff --git a/package.json b/package.json index ef0ebd10..6faca93c 100644 --- a/package.json +++ b/package.json @@ -13,19 +13,20 @@ "type-check": "vue-tsc --noEmit" }, "dependencies": { - "@chain-registry/types": "^0.50.162", + "@chain-registry/client": "^1.53.184", + "@chain-registry/types": "^0.50.184", "@chenfengyuan/vue-countdown": "2", "@cosmjs/amino": "^0.32.3", "@cosmjs/crypto": "^0.32.3", "@cosmjs/encoding": "^0.32.3", "@cosmjs/stargate": "^0.32.3", + "@cosmjs/cosmwasm-stargate": "^0.30.0", "@iconify/vue": "^4.1.0", "@intlify/unplugin-vue-i18n": "^0.8.2", "@leapwallet/cosmos-snap-provider": "^0.1.20", "@leapwallet/name-matcha": "^2.0.0", "@osmonauts/lcd": "^0.8.0", "@personaxyz/ad-sdk": "0.0.25", - "@ping-pub/chain-registry-client": "^0.0.25", "@vitejs/plugin-vue-jsx": "^3.0.0", "@vueuse/core": "^9.12.0", "@vueuse/integrations": "^10.1.2", @@ -33,11 +34,14 @@ "apexcharts": "^3.37.1", "autoprefixer": "^10.4.14", "axios": "^1.3.2", + "bech32": "^1.1.4", "buffer": "^6.0.3", "build": "^0.1.4", "cross-fetch": "^3.1.5", "daisyui": "^3.1.0", "dayjs": "^1.11.7", + "idna-uts46-hx": "^5.0.7", + "js-sha3": "^0.8.0", "lazy-load-vue3": "^1.3.0", "long": "^5.2.1", "md-editor-v3": "^2.8.1", @@ -67,7 +71,7 @@ "@vue/tsconfig": "^0.1.3", "husky": "^9.1.7", "npm-run-all": "^4.1.5", - "prettier": "^2.7.1", + "prettier": "^3.0.0", "pretty-quick": "^4.2.2", "sass": "^1.58.0", "shiki": "^1.0.0-beta.0", diff --git a/src/modules/[chain]/ibc/connStore.ts b/src/modules/[chain]/ibc/connStore.ts index 9d6eeaad..4c4bd91f 100644 --- a/src/modules/[chain]/ibc/connStore.ts +++ b/src/modules/[chain]/ibc/connStore.ts @@ -1,67 +1,87 @@ + import { defineStore } from 'pinia'; -import { useBlockchain } from '@/stores'; -import ChainRegistryClient from '@ping-pub/chain-registry-client'; -import type { IBCPath, IBCInfo } from '@ping-pub/chain-registry-client/dist/types'; -import type { Channel } from '@/types'; +import { useBlockchain } from '@/stores' +import { ChainRegistryClient } from '@chain-registry/client'; +import type { IBCData } from '@chain-registry/types/ibc_data.schema'; import router from '@/router'; +import fetch from 'cross-fetch'; export const useIBCModule = defineStore('module-ibc', { state: () => { return { - paths: [] as IBCPath[], - connectionId: '' as string, - registryConf: {} as IBCInfo, + info: [] as IBCData[], + connectionId: "" as string, + registryConf: {} as IBCData, }; }, getters: { chain() { - return useBlockchain(); + return useBlockchain() }, - commonIBCs(): any { - return this.paths.filter( - (x: IBCPath) => x.path.search(this.chain.current?.prettyName || this.chain.chainName) > -1 - ); + chainName(): string { + return this.chain.chainName; }, sourceField(): string { - return this.registryConf?.chain_1?.chain_name === this.chain.current?.prettyName || this.chain.chainName - ? 'chain_1' - : 'chain_2'; + return this.registryConf?.chain_1?.chain_name === this.chainName ? 'chain_1' : 'chain_2' }, destField(): string { - return this.registryConf?.chain_1?.chain_name === this.chain.current?.prettyName || this.chain.chainName - ? 'chain_2' - : 'chain_1'; + return this.registryConf?.chain_1?.chain_name === this.chainName ? 'chain_2' : 'chain_1' }, registryChannels(): any { - return this.registryConf.channels; + return this.registryConf.channels }, }, actions: { load() { - const client = new ChainRegistryClient(); - client.fetchIBCPaths().then((res) => { - this.paths = res; + const client = new ChainRegistryClient({ + chainNames: [this.chainName], }); + this.fetchIBCUrls().then((res) => { + res.forEach((element: any) => { + if (element.download_url) { + client.urls.push(element.download_url); + } + }); + + client.fetchUrls().then(() => { + const info = client.getChainIbcData(this.chainName) + this.info = info.sort((a, b) => { + // Sort by remote chain name (not equal to this.chainName) + const getRemote = (x: any) => x.chain_1.chain_name === this.chainName ? x.chain_2.chain_name : x.chain_1.chain_name; + return getRemote(a).localeCompare(getRemote(b)); + }); + + }) + }); + }, - fetchConnection(path: string) { - const client = new ChainRegistryClient(); - client.fetchIBCPathInfo(path).then((res) => { - const isFirstChain = - res.chain_1.chain_name === this.chain.current?.prettyName || res.chain_1.chain_name === this.chain.chainName; + async fetchIBCUrls(): Promise { + let ibcEndpoint = 'https://api.github.com/repos/cosmos/chain-registry/contents/_IBC' + if (this.chainName.includes("testnet")) { + console.log(this.chainName) + ibcEndpoint = 'https://api.github.com/repos/cosmos/chain-registry/contents/testnets/_IBC' + } + const entries = await fetch(ibcEndpoint).then((res) => res.json()) + return entries.filter((x: any) => x.name.match(this.chainName)); + }, + fetchConnection(index: number) { + const res = this.info[index]; + const isFirstChain = res.chain_1.chain_name === this.chain.current?.prettyName || res.chain_1.chain_name === this.chain.chainName; - const connId = isFirstChain ? res.chain_1.connection_id : res.chain_2.connection_id; + const connId = isFirstChain + ? res.chain_1.connection_id + : res.chain_2.connection_id; - this.registryConf = res; - this.showConnection(connId); - }); + this.registryConf = res; + this.showConnection(connId); }, showConnection(connId?: string | number) { if (!connId) { - this.registryConf = {} as any; + this.registryConf = {} as any } - const path = `/${this.chain.chainName}/ibc/connection/${connId || `connection-${this.connectionId || 0}`}`; - router.push(path); - }, + const path = `/${this.chain.chainName}/ibc/connection/${connId || `connection-${this.connectionId || 0}`}` + router.push(path) + } }, }); diff --git a/src/modules/[chain]/ibc/connection.vue b/src/modules/[chain]/ibc/connection.vue index ff1bfb81..f0a136f3 100644 --- a/src/modules/[chain]/ibc/connection.vue +++ b/src/modules/[chain]/ibc/connection.vue @@ -1,76 +1,64 @@