From f7d9ae88e1e367ce32c06361c1ab5f58eb6290f3 Mon Sep 17 00:00:00 2001 From: 2xburnt <169301814+2xburnt@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:19:02 -0500 Subject: [PATCH] default to use registry.ping.pub for ibc file retrievals --- .env.example | 24 +++++++++++++++++++++--- env.d.ts | 13 +++++++++++++ src/modules/[chain]/ibc/connStore.ts | 28 ++++++++++++++++++++-------- src/types/ibc.ts | 7 ------- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 3e4e5051..4921ff88 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,22 @@ # rename to .env.local or .env. -VITE_REFRESH_INTERVAL=2000 -VITE_FETCH_ALL_BLOCKS=true -VITE_RECENT_BLOCK_LIMIT=100 + +# Refresh interval for the app to query api for new blocks +VITE_REFRESH_INTERVAL=6000 + +# Enable fetching all blocks (this can increase api calls to public nodes resulting in rate limiting) +VITE_FETCH_ALL_BLOCKS=false + +# Limit for recent blocks and associated transactions displayed in the UI +VITE_RECENT_BLOCK_LIMIT=50 + +# URL for CoinGecko API or custom proxy +VITE_COINGECKO_URL=https://api.coingecko.com + +# GITHUB_API_URL default +VITE_GITHUB_API_URL=https://api.github.com/repos/cosmos/chain-registry/contents + +# PINGPUB_API_URL default +VITE_PINGPUB_API_URL=https://registry.ping.pub + +# IBC use PINGPUB_API_URL by Default (false) or GITHUB_API_URL (true) +VITE_IBC_USE_GITHUB_API=false diff --git a/env.d.ts b/env.d.ts index 33f49a00..68dc2b97 100644 --- a/env.d.ts +++ b/env.d.ts @@ -1,3 +1,16 @@ /// declare module '@personaxyz/ad-sdk'; +interface ImportMetaEnv { + readonly VITE_REFRESH_INTERVAL?: number, + readonly VITE_FETCH_ALL_BLOCKS?: boolean, + readonly VITE_RECENT_BLOCK_LIMIT?: number, + readonly VITE_COINGECKO_URL?: string, + readonly VITE_GITHUB_API_URL?: string, + readonly VITE_PINGPUB_API_URL?: string, + readonly VITE_IBC_USE_GITHUB_API?: string, +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/src/modules/[chain]/ibc/connStore.ts b/src/modules/[chain]/ibc/connStore.ts index 01498056..898a3855 100644 --- a/src/modules/[chain]/ibc/connStore.ts +++ b/src/modules/[chain]/ibc/connStore.ts @@ -6,6 +6,11 @@ import type { IBCData } from '@chain-registry/types/ibc_data.schema'; 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 IBC_API_URL = IBC_USE_GITHUB_API ? GITHUB_API_URL : PINGPUB_API_URL; + export const useIBCModule = defineStore('module-ibc', { state: () => { return { @@ -39,6 +44,7 @@ export const useIBCModule = defineStore('module-ibc', { load() { const client = new ChainRegistryClient({ chainNames: [this.chainName], + baseUrl: IBC_USE_GITHUB_API ? undefined : PINGPUB_API_URL, }); this.fetchIBCUrls().then((res) => { res.forEach((element: any) => { @@ -61,15 +67,21 @@ export const useIBCModule = defineStore('module-ibc', { }); }, 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 prefix = this.chainName.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)) : []); + + // 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(); + return entry; + }); } - const entries = await fetch(ibcEndpoint).then((res) => res.json()); - return entries.filter((x: any) => x.name.match(this.chainName)); + return entries }, fetchConnection(index: number) { const res = this.info[index]; diff --git a/src/types/ibc.ts b/src/types/ibc.ts index c68b9d01..1f831326 100644 --- a/src/types/ibc.ts +++ b/src/types/ibc.ts @@ -3,13 +3,6 @@ import type { IBCInfo as RegistryIBCInfo } from "@chain-registry/types" export interface IBCInfo extends RegistryIBCInfo { } -export interface IBCPath { - path: string, - from?: string, - to?: string, - url?: string -} - export interface DenomTrace { path: string; base_denom: string;