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