Skip to content

Commit

Permalink
Fetch description + logo from chain.json (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x authored Feb 7, 2024
1 parent 915464f commit 06b4ee2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 24 deletions.
33 changes: 9 additions & 24 deletions api/src/providers/templateReposProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fs from "fs";
import { Octokit } from "@octokit/rest";
import { getLogoFromPath } from "./templateReposLogos";
import { dataFolderPath } from "@src/utils/constants";
import { GithubChainRegistryAssetListResponse } from "@src/types";
import { GithubChainRegistryChainResponse } from "@src/types";
import { GithubDirectoryItem } from "@src/types/github";

let generatingTasks = {};
Expand Down Expand Up @@ -157,31 +157,16 @@ async function fetchOmnibusTemplates(octokit: Octokit, repoVersion: string) {

for (const template of templates) {
try {
const assetListResponse = await fetch(`https://raw.githubusercontent.com/cosmos/chain-registry/master/${template.path}/assetlist.json`);
const chainResponse = await fetch(`https://raw.githubusercontent.com/cosmos/chain-registry/master/${template.path}/chain.json`);

if (assetListResponse.status !== 200) throw "Could not fetch assetlist.json";
if (chainResponse.status !== 200) throw "Could not fetch chain.json for " + template.path;

const assetList = (await assetListResponse.json()) as GithubChainRegistryAssetListResponse;
if (assetList.assets.length === 0) {
throw "No asset found";
}

if (assetList.assets.length > 1) {
const asset = assetList.assets.find((a) => a.name.toLowerCase() === template.name.toLocaleLowerCase());
if (!asset) {
throw "More than one asset found";
}

template.name = asset.name;
template.logoUrl = Object.values(asset.logo_URIs)[0];
} else {
const asset = assetList.assets[0];
template.name = asset.name;
template.summary = asset.description;
template.logoUrl = Object.values(asset.logo_URIs)[0];
}
const chainData = (await chainResponse.json()) as GithubChainRegistryChainResponse;
template.name = chainData.pretty_name;
template.summary = chainData.description ?? template.summary;
template.logoUrl = Object.values(chainData.logo_URIs ?? {})[0];
} catch (err) {
console.log("Could not fetch assetlist for", template.path);
console.log("Could not fetch chain for", template.path);
console.error(err);
}
}
Expand Down Expand Up @@ -430,7 +415,7 @@ export async function fetchTemplatesInfo(octokit: Octokit, categories: Category[
const deploy = await findFileContentAsync(["deploy.yaml", "deploy.yml"], response.data);
const guide = await findFileContentAsync("GUIDE.md", response.data);

template.readme = replaceLinks(readme, template.repoOwner, template.repoName, template.repoVersion, template.path);
template.readme = readme && replaceLinks(readme, template.repoOwner, template.repoName, template.repoVersion, template.path);
template.deploy = deploy;
template.persistentStorageEnabled = deploy && (deploy.includes("persistent: true") || deploy.includes("persistent:true"));
template.guide = guide;
Expand Down
79 changes: 79 additions & 0 deletions api/src/types/chainRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,82 @@ export type GithubChainRegistryAssetListResponse = {
coingecko_id: string;
}[];
};

export type GithubChainRegistryChainResponse = {
$schema: string;
chain_name: string;
status: string;
network_type: string;
website: string;
pretty_name: string;
chain_id: string;
bech32_prefix: string;
daemon_name: string;
node_home: string;
slip44: number;
fees: {
fee_tokens: {
denom: string;
fixed_min_gas_price: number;
low_gas_price: number;
average_gas_price: number;
high_gas_price: number;
}[];
};
staking: {
staking_tokens: {
denom: string;
}[];
};
codebase: {
git_repo: string;
recommended_version: string;
compatible_versions: string[];
binaries: { [key: string]: string };
genesis: {
genesis_url: string;
};
versions: [
{
name: string;
recommended_version: string;
compatible_versions: string[];
binaries: { [key: string]: string };
next_version_name: string;
}
];
};
logo_URIs: { [key: string]: string };
description: string;
peers: {
seeds: {
id: string;
address: string;
}[];
persistent_peers: {
id: string;
address: string;
}[];
};
apis: {
rpc: {
address: string;
provider: string;
}[];
rest: {
address: string;
provider: string;
}[];
grpc: {
address: string;
provider: string;
}[];
};
explorers: {
kind: string;
url: string;
tx_page: string;
account_page: string;
}[];
images: { [key: string]: string }[];
};

0 comments on commit 06b4ee2

Please sign in to comment.