Skip to content

Commit 8cdc7c2

Browse files
committed
fix network detection issues with ibc
1 parent f7d9ae8 commit 8cdc7c2

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

chains/mainnet/xion.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"chain_name": "xion",
3+
"chain_id": "xion-mainnet-1",
34
"registry_name": "xion",
45
"coingecko": "xion",
56
"network_type": "mainnet",
@@ -32,7 +33,7 @@
3233
}
3334
],
3435
"snapshot_provider": "",
35-
"sdk_version": "0.50.13",
36+
"sdk_version": "0.53.3",
3637
"coin_type": "118",
3738
"min_tx_fee": "100",
3839
"addr_prefix": "xion",

src/modules/[chain]/ibc/connStore.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import router from '@/router';
77
import fetch from 'cross-fetch';
88

99
const IBC_USE_GITHUB_API = import.meta.env.VITE_IBC_USE_GITHUB_API === 'true';
10-
const PINGPUB_API_URL = import.meta.env.VITE_PINGPUB_API_URL || 'https://registry.ping.pub'
11-
const GITHUB_API_URL = import.meta.env.VITE_GITHUB_API_URL || 'https://api.github.com/repos/cosmos/chain-registry/contents';
10+
const PINGPUB_API_URL = import.meta.env.VITE_PINGPUB_API_URL || 'https://registry.ping.pub';
11+
const GITHUB_API_URL =
12+
import.meta.env.VITE_GITHUB_API_URL || 'https://api.github.com/repos/cosmos/chain-registry/contents';
1213
const IBC_API_URL = IBC_USE_GITHUB_API ? GITHUB_API_URL : PINGPUB_API_URL;
1314

1415
export const useIBCModule = defineStore('module-ibc', {
@@ -26,25 +27,28 @@ export const useIBCModule = defineStore('module-ibc', {
2627
chainName(): string {
2728
return this.chain.chainName;
2829
},
30+
isFirstChain(): boolean {
31+
return (
32+
this.registryConf?.chain_1?.chain_name === this.chain.current?.prettyName ||
33+
this.registryConf?.chain_1?.chain_name === this.chain.chainName
34+
);
35+
},
2936
sourceField(): string {
30-
return this.registryConf?.chain_1?.chain_name === this.chainName
31-
? 'chain_1'
32-
: 'chain_2';
37+
return this.isFirstChain ? 'chain_1' : 'chain_2';
3338
},
3439
destField(): string {
35-
return this.registryConf?.chain_1?.chain_name === this.chainName
36-
? 'chain_2'
37-
: 'chain_1';
40+
return this.isFirstChain ? 'chain_2' : 'chain_1';
3841
},
3942
registryChannels(): any {
4043
return this.registryConf.channels;
4144
},
4245
},
4346
actions: {
4447
load() {
48+
const prefix = this.chain.current?.networkType?.includes('testnet') ? 'testnets/' : '';
4549
const client = new ChainRegistryClient({
4650
chainNames: [this.chainName],
47-
baseUrl: IBC_USE_GITHUB_API ? undefined : PINGPUB_API_URL,
51+
baseUrl: IBC_USE_GITHUB_API ? undefined : new URL(`${prefix}`, PINGPUB_API_URL + '/').toString(),
4852
});
4953
this.fetchIBCUrls().then((res) => {
5054
res.forEach((element: any) => {
@@ -58,40 +62,35 @@ export const useIBCModule = defineStore('module-ibc', {
5862
this.info = info.sort((a, b) => {
5963
// Sort by remote chain name (not equal to this.chainName)
6064
const getRemote = (x: any) =>
61-
x.chain_1.chain_name === this.chainName
62-
? x.chain_2.chain_name
63-
: x.chain_1.chain_name;
65+
x.chain_1.chain_name === this.isFirstChain ? x.chain_2.chain_name : x.chain_1.chain_name;
6466
return getRemote(a).localeCompare(getRemote(b));
6567
});
6668
});
6769
});
6870
},
6971
async fetchIBCUrls(): Promise<any[]> {
70-
const prefix = this.chainName.includes('testnet') ? 'testnets/' : '';
72+
const prefix = this.chain.current?.networkType?.includes('testnet') ? 'testnets/' : '';
7173
const ibcEndpoint = new URL(`${prefix}_IBC`, IBC_API_URL + '/').toString();
7274
console.log('Fetching IBC URLs from:', IBC_API_URL);
7375
let entries = await fetch(ibcEndpoint)
7476
.then((res) => res.json())
75-
.then((data: any) => Array.isArray(data) ? data.filter((x: any) => x.name.match(this.chainName)) : []);
77+
.then((data: any) => (Array.isArray(data) ? data.filter((x: any) => x.name.match(this.chainName)) : []));
7678

7779
// If using PINGPUB_API_URL, add thedownload URLs
7880
if (IBC_API_URL == PINGPUB_API_URL) {
7981
return entries.map((entry: any) => {
80-
entry.download_url = new URL(`${prefix}_IBC/${entry.name}`, PINGPUB_API_URL + '/').toString();
82+
entry.download_url = new URL(`${prefix}_IBC/${entry.name}`, PINGPUB_API_URL + '/').toString();
8183
return entry;
8284
});
8385
}
84-
return entries
86+
return entries;
8587
},
8688
fetchConnection(index: number) {
8789
const res = this.info[index];
88-
const isFirstChain =
89-
res.chain_1.chain_name === this.chain.current?.prettyName ||
90-
res.chain_1.chain_name === this.chain.chainName;
90+
const resIsFirstChain =
91+
res.chain_1.chain_name === this.chain.current?.prettyName || res.chain_1.chain_name === this.chain.chainName;
9192

92-
const connId = isFirstChain
93-
? res.chain_1.connection_id
94-
: res.chain_2.connection_id;
93+
const connId = resIsFirstChain ? res.chain_1.connection_id : res.chain_2.connection_id;
9594

9695
this.registryConf = res;
9796
this.showConnection(connId);

src/stores/useDashboard.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function convertFromLocal(lc: LocalChainConfig): ChainConfig {
4545
conf.bech32Prefix = lc.addr_prefix;
4646
conf.bech32ConsensusPrefix = lc.consensus_prefix ?? lc.addr_prefix + 'valcons';
4747
conf.chainName = lc.chain_name;
48+
conf.networkType = lc.network_type;
4849
conf.coinType = lc.coin_type;
4950
conf.prettyName = lc.registry_name || lc.chain_name;
5051
conf.endpoints = {
@@ -74,6 +75,7 @@ export function convertFromDirectory(source: DirectoryChainConfig): ChainConfig
7475
(conf.chainId = source.chain_id),
7576
(conf.chainName = source.chain_name),
7677
(conf.prettyName = source.pretty_name),
78+
(conf.networkType = source.network_type),
7779
(conf.versions = {
7880
application: source.versions?.application_version || '',
7981
cosmosSdk: source.versions?.cosmos_sdk_version || '',
@@ -138,7 +140,7 @@ export enum LoadingStatus {
138140

139141
export const useDashboard = defineStore('dashboard', {
140142
state: () => {
141-
const favMap = JSON.parse(localStorage.getItem('favoriteMap') || '{"cosmos":true, "osmosis":true}');
143+
const favMap = JSON.parse(localStorage.getItem('favoriteMap') || '{"xion":true, "xiontestnet2":true}');
142144
return {
143145
status: LoadingStatus.Empty,
144146
source: ConfigSource.MainnetCosmosDirectory,
@@ -209,6 +211,9 @@ export const useDashboard = defineStore('dashboard', {
209211
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
210212
Object.values<LocalChainConfig>(source).forEach((x: LocalChainConfig) => {
211213
this.chains[x.chain_name] = convertFromLocal(x);
214+
if (!this.chains[x.chain_name].networkType) {
215+
this.chains[x.chain_name].networkType = this.networkType.toString().toLowerCase();
216+
}
212217
});
213218
this.setupDefault();
214219
this.status = LoadingStatus.Loaded;
@@ -221,6 +226,9 @@ export const useDashboard = defineStore('dashboard', {
221226
: import.meta.glob('../../chains/testnet/*.json', { eager: true });
222227
Object.values<LocalChainConfig>(source).forEach((x: LocalChainConfig) => {
223228
config[x.chain_name] = convertFromLocal(x);
229+
if (!config[x.chain_name].networkType) {
230+
config[x.chain_name].networkType = network.toString().toLowerCase();
231+
}
224232
});
225233
return config;
226234
},

src/types/chaindata.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface LocalChainConfig {
4141
symbol: string;
4242
}[];
4343
chain_name: string;
44+
network_type?: string;
4445
coin_type: string;
4546
logo: string;
4647
theme_color?: string;
@@ -103,6 +104,7 @@ export interface DirectoryChainConfig {
103104
export interface ChainConfig {
104105
chainName: string;
105106
prettyName: string;
107+
networkType?: string;
106108
bech32Prefix: string;
107109
bech32ConsensusPrefix: string;
108110
chainId: string;

0 commit comments

Comments
 (0)