forked from LaconicNetwork/cosmos-explorer
default to use registry.ping.pub for ibc file retrievals
This commit is contained in:
parent
4b6f61f878
commit
f7d9ae88e1
24
.env.example
24
.env.example
@ -1,4 +1,22 @@
|
||||
# rename to .env.local or .env.<your_environment>
|
||||
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
|
||||
|
||||
13
env.d.ts
vendored
13
env.d.ts
vendored
@ -1,3 +1,16 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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<any[]> {
|
||||
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];
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user