forked from LaconicNetwork/cosmos-explorer
fix network detection issues with ibc
This commit is contained in:
parent
f7d9ae88e1
commit
8cdc7c2e1d
@ -1,5 +1,6 @@
|
||||
{
|
||||
"chain_name": "xion",
|
||||
"chain_id": "xion-mainnet-1",
|
||||
"registry_name": "xion",
|
||||
"coingecko": "xion",
|
||||
"network_type": "mainnet",
|
||||
@ -32,7 +33,7 @@
|
||||
}
|
||||
],
|
||||
"snapshot_provider": "",
|
||||
"sdk_version": "0.50.13",
|
||||
"sdk_version": "0.53.3",
|
||||
"coin_type": "118",
|
||||
"min_tx_fee": "100",
|
||||
"addr_prefix": "xion",
|
||||
|
||||
@ -7,8 +7,9 @@ import router from '@/router';
|
||||
import fetch from 'cross-fetch';
|
||||
|
||||
const IBC_USE_GITHUB_API = import.meta.env.VITE_IBC_USE_GITHUB_API === 'true';
|
||||
const PINGPUB_API_URL = import.meta.env.VITE_PINGPUB_API_URL || 'https://registry.ping.pub'
|
||||
const GITHUB_API_URL = import.meta.env.VITE_GITHUB_API_URL || 'https://api.github.com/repos/cosmos/chain-registry/contents';
|
||||
const PINGPUB_API_URL = import.meta.env.VITE_PINGPUB_API_URL || 'https://registry.ping.pub';
|
||||
const GITHUB_API_URL =
|
||||
import.meta.env.VITE_GITHUB_API_URL || 'https://api.github.com/repos/cosmos/chain-registry/contents';
|
||||
const IBC_API_URL = IBC_USE_GITHUB_API ? GITHUB_API_URL : PINGPUB_API_URL;
|
||||
|
||||
export const useIBCModule = defineStore('module-ibc', {
|
||||
@ -26,15 +27,17 @@ export const useIBCModule = defineStore('module-ibc', {
|
||||
chainName(): string {
|
||||
return this.chain.chainName;
|
||||
},
|
||||
isFirstChain(): boolean {
|
||||
return (
|
||||
this.registryConf?.chain_1?.chain_name === this.chain.current?.prettyName ||
|
||||
this.registryConf?.chain_1?.chain_name === this.chain.chainName
|
||||
);
|
||||
},
|
||||
sourceField(): string {
|
||||
return this.registryConf?.chain_1?.chain_name === this.chainName
|
||||
? 'chain_1'
|
||||
: 'chain_2';
|
||||
return this.isFirstChain ? 'chain_1' : 'chain_2';
|
||||
},
|
||||
destField(): string {
|
||||
return this.registryConf?.chain_1?.chain_name === this.chainName
|
||||
? 'chain_2'
|
||||
: 'chain_1';
|
||||
return this.isFirstChain ? 'chain_2' : 'chain_1';
|
||||
},
|
||||
registryChannels(): any {
|
||||
return this.registryConf.channels;
|
||||
@ -42,9 +45,10 @@ export const useIBCModule = defineStore('module-ibc', {
|
||||
},
|
||||
actions: {
|
||||
load() {
|
||||
const prefix = this.chain.current?.networkType?.includes('testnet') ? 'testnets/' : '';
|
||||
const client = new ChainRegistryClient({
|
||||
chainNames: [this.chainName],
|
||||
baseUrl: IBC_USE_GITHUB_API ? undefined : PINGPUB_API_URL,
|
||||
baseUrl: IBC_USE_GITHUB_API ? undefined : new URL(`${prefix}`, PINGPUB_API_URL + '/').toString(),
|
||||
});
|
||||
this.fetchIBCUrls().then((res) => {
|
||||
res.forEach((element: any) => {
|
||||
@ -58,40 +62,35 @@ export const useIBCModule = defineStore('module-ibc', {
|
||||
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;
|
||||
x.chain_1.chain_name === this.isFirstChain ? x.chain_2.chain_name : x.chain_1.chain_name;
|
||||
return getRemote(a).localeCompare(getRemote(b));
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
async fetchIBCUrls(): Promise<any[]> {
|
||||
const prefix = this.chainName.includes('testnet') ? 'testnets/' : '';
|
||||
const prefix = this.chain.current?.networkType?.includes('testnet') ? 'testnets/' : '';
|
||||
const ibcEndpoint = new URL(`${prefix}_IBC`, IBC_API_URL + '/').toString();
|
||||
console.log('Fetching IBC URLs from:', IBC_API_URL);
|
||||
let entries = await fetch(ibcEndpoint)
|
||||
.then((res) => res.json())
|
||||
.then((data: any) => Array.isArray(data) ? data.filter((x: any) => x.name.match(this.chainName)) : []);
|
||||
.then((data: any) => (Array.isArray(data) ? data.filter((x: any) => x.name.match(this.chainName)) : []));
|
||||
|
||||
// If using PINGPUB_API_URL, add thedownload URLs
|
||||
if (IBC_API_URL == PINGPUB_API_URL) {
|
||||
return entries.map((entry: any) => {
|
||||
entry.download_url = new URL(`${prefix}_IBC/${entry.name}`, PINGPUB_API_URL + '/').toString();
|
||||
entry.download_url = new URL(`${prefix}_IBC/${entry.name}`, PINGPUB_API_URL + '/').toString();
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
return entries
|
||||
return entries;
|
||||
},
|
||||
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 resIsFirstChain =
|
||||
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 = resIsFirstChain ? res.chain_1.connection_id : res.chain_2.connection_id;
|
||||
|
||||
this.registryConf = res;
|
||||
this.showConnection(connId);
|
||||
|
||||
@ -45,6 +45,7 @@ export function convertFromLocal(lc: LocalChainConfig): ChainConfig {
|
||||
conf.bech32Prefix = lc.addr_prefix;
|
||||
conf.bech32ConsensusPrefix = lc.consensus_prefix ?? lc.addr_prefix + 'valcons';
|
||||
conf.chainName = lc.chain_name;
|
||||
conf.networkType = lc.network_type;
|
||||
conf.coinType = lc.coin_type;
|
||||
conf.prettyName = lc.registry_name || lc.chain_name;
|
||||
conf.endpoints = {
|
||||
@ -74,6 +75,7 @@ export function convertFromDirectory(source: DirectoryChainConfig): ChainConfig
|
||||
(conf.chainId = source.chain_id),
|
||||
(conf.chainName = source.chain_name),
|
||||
(conf.prettyName = source.pretty_name),
|
||||
(conf.networkType = source.network_type),
|
||||
(conf.versions = {
|
||||
application: source.versions?.application_version || '',
|
||||
cosmosSdk: source.versions?.cosmos_sdk_version || '',
|
||||
@ -138,7 +140,7 @@ export enum LoadingStatus {
|
||||
|
||||
export const useDashboard = defineStore('dashboard', {
|
||||
state: () => {
|
||||
const favMap = JSON.parse(localStorage.getItem('favoriteMap') || '{"cosmos":true, "osmosis":true}');
|
||||
const favMap = JSON.parse(localStorage.getItem('favoriteMap') || '{"xion":true, "xiontestnet2":true}');
|
||||
return {
|
||||
status: LoadingStatus.Empty,
|
||||
source: ConfigSource.MainnetCosmosDirectory,
|
||||
@ -209,6 +211,9 @@ export const useDashboard = defineStore('dashboard', {
|
||||
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
|
||||
Object.values<LocalChainConfig>(source).forEach((x: LocalChainConfig) => {
|
||||
this.chains[x.chain_name] = convertFromLocal(x);
|
||||
if (!this.chains[x.chain_name].networkType) {
|
||||
this.chains[x.chain_name].networkType = this.networkType.toString().toLowerCase();
|
||||
}
|
||||
});
|
||||
this.setupDefault();
|
||||
this.status = LoadingStatus.Loaded;
|
||||
@ -221,6 +226,9 @@ export const useDashboard = defineStore('dashboard', {
|
||||
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
|
||||
Object.values<LocalChainConfig>(source).forEach((x: LocalChainConfig) => {
|
||||
config[x.chain_name] = convertFromLocal(x);
|
||||
if (!config[x.chain_name].networkType) {
|
||||
config[x.chain_name].networkType = network.toString().toLowerCase();
|
||||
}
|
||||
});
|
||||
return config;
|
||||
},
|
||||
|
||||
@ -41,6 +41,7 @@ export interface LocalChainConfig {
|
||||
symbol: string;
|
||||
}[];
|
||||
chain_name: string;
|
||||
network_type?: string;
|
||||
coin_type: string;
|
||||
logo: string;
|
||||
theme_color?: string;
|
||||
@ -103,6 +104,7 @@ export interface DirectoryChainConfig {
|
||||
export interface ChainConfig {
|
||||
chainName: string;
|
||||
prettyName: string;
|
||||
networkType?: string;
|
||||
bech32Prefix: string;
|
||||
bech32ConsensusPrefix: string;
|
||||
chainId: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user