Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alibabaedge committed Dec 17, 2024
0 parents commit 64dee81
Show file tree
Hide file tree
Showing 67 changed files with 5,019 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

.DS_Store
dist-ssr
*.local
stats.html
*.env.*
!default.env
components.d.ts
.idea/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"singleQuote": true,
"semi": true,
"printWidth": 120,
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
"importOrder": ["<THIRD_PARTY_MODULES>","^@/(.*)$", "^[../]", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"tailwindConfig": "./tailwind.config.ts"
}
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
15 changes: 15 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'raw.githubusercontent.com',
port: '',
pathname: '/cosmos/chain-registry/master/**',
},
],
},
};

export default nextConfig;
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "posthuman-source",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 3200",
"lint": "next lint"
},
"dependencies": {
"@geoffcodesthings/tailwind-md-base": "^1.1.0",
"next": "14.1.0",
"node-cache": "^5.1.2",
"react": "^18",
"react-dom": "^18",
"react-markdown": "^9.0.1",
"react-toastify": "^10.0.4",
"rehype-raw": "^7.0.0",
"swr": "^2.2.5"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.0",
"postcss": "^8",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.11",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
}
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Binary file added public/android-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-36x36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-114x114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-57x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-precomposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig><msapplication><tile><square70x70logo src="/ms-icon-70x70.png"/><square150x150logo src="/ms-icon-150x150.png"/><square310x310logo src="/ms-icon-310x310.png"/><TileColor>#ffffff</TileColor></tile></msapplication></browserconfig>
Binary file added public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/fonts/ZonaPro-Black.woff2
Binary file not shown.
Binary file added public/fonts/ZonaPro-Bold.woff2
Binary file not shown.
Binary file added public/fonts/ZonaPro-Regular.woff2
Binary file not shown.
Binary file added public/fonts/ZonaPro-SemiBold.woff2
Binary file not shown.
Binary file added public/fonts/hisqaida2018_bold.ttf
Binary file not shown.
Binary file added public/fonts/hisqaida2018_bold.woff
Binary file not shown.
1 change: 1 addition & 0 deletions public/icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/website.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/img/icons/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/img/icons/external-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/posthuman_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "App",
"icons": [
{
"src": "\/android-icon-36x36.png",
"sizes": "36x36",
"type": "image\/png",
"density": "0.75"
},
{
"src": "\/android-icon-48x48.png",
"sizes": "48x48",
"type": "image\/png",
"density": "1.0"
},
{
"src": "\/android-icon-72x72.png",
"sizes": "72x72",
"type": "image\/png",
"density": "1.5"
},
{
"src": "\/android-icon-96x96.png",
"sizes": "96x96",
"type": "image\/png",
"density": "2.0"
},
{
"src": "\/android-icon-144x144.png",
"sizes": "144x144",
"type": "image\/png",
"density": "3.0"
},
{
"src": "\/android-icon-192x192.png",
"sizes": "192x192",
"type": "image\/png",
"density": "4.0"
}
]
}
Binary file added public/ms-icon-144x144.png
Binary file added public/ms-icon-150x150.png
Binary file added public/ms-icon-310x310.png
Binary file added public/ms-icon-70x70.png
88 changes: 88 additions & 0 deletions src/app/actions/repos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import NodeCache from 'node-cache';

import { CONFIG_REPO, CONTRIBUTIONS_REPO } from '@/app/config';
import deepValue from '@/app/utils/deep-value';
import { IChain, IChainConfig, TChainItem } from '@/types';

const cache = new NodeCache();

export const getRegistryChain = async (chainName: string): Promise<IChain | undefined> => {
if (cache.has(`registry/${chainName}`)) {
return cache.get(`registry/${chainName}`);
}

try {
const res = await fetch(
`https://raw.githubusercontent.com/cosmos/chain-registry/master/${chainName}/chain.json`,
).then((r) => r.json());

cache.set(`registry/${chainName}`, res, 3600);
return res;
} catch (e) {
cache.set(`registry/${chainName}`, undefined, 3600);
return;
}
};

export const getRepoChains = async (): Promise<IChainConfig[]> => {
const cachedData = cache.get('github/chains');
if (cachedData) return cachedData as IChainConfig[];

const res = (await fetch(`${CONFIG_REPO}/networks.json`).then((r) => {
return r.json();
})) as IChainConfig[];
cache.set('github/chains', res, 10);
return res;
};

export const getChain = async (chainName: string): Promise<TChainItem | undefined> => {
const cachedData = cache.get(`chain/${chainName}`);
if (cachedData) return cachedData as TChainItem;

const chains = await getRepoChains();
const registry = await getRegistryChain(chainName);
const chainConfig = chains.find((n) => n.name === chainName);
const chain = Object.assign(registry ?? {}, chainConfig) as TChainItem;
cache.set(`github/${chainName}`, chain, 10);

return chain;
};

export const getRepoChainService = async (chain: string, serviceName: string): Promise<string> => {
const cachedData = cache.get(`github/${chain}/${serviceName}`);
if (cachedData) return cachedData as string;

const service = await fetch(`${CONFIG_REPO}/${chain}/${serviceName.toLowerCase()}.md`).then((r) => r.text());
cache.set(`github/${chain}/${serviceName}`, service, 10);
return service;
};

export const getRepoChainContributions = async (name: string): Promise<string> => {
const cachedData = cache.get(`github/contributions/${name}`);
if (cachedData) return cachedData as string;

const contributions = await fetch(`${CONTRIBUTIONS_REPO}/main/${name}.md`).then((r) => r.text());
cache.set(`github/contributions/${name}`, contributions, 10);
return contributions;
};

export const getRepoChainServiceGlobal = async (chain: TChainItem, serviceName: string): Promise<string> => {
const cachedData = cache.get(`github/global-service/${chain.name}/${serviceName}`);
if (cachedData) return cachedData as string;

let globalService = await fetch(`${CONFIG_REPO}/global/${serviceName.toLowerCase()}.md`).then((r) => r.text());

globalService = globalService.replace(/\{\{(.+?)}}/g, (_, param: string): string => {
if (param[0] === ':') {
const [_, path, template, separator] = param.split(':');
const arr: any = deepValue(chain, path);
return arr.map((item: any) => template.replace(/{(.+?)}/g, (_, subParam) => item[subParam])).join(separator);
}

return deepValue(chain, param) as string;
});

cache.set(`github/global-service/${chain.name}/${serviceName}`, globalService, 10);

return globalService;
};
24 changes: 24 additions & 0 deletions src/app/api/health/[chainName]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextResponse } from 'next/server';

import { getChain } from '@/app/actions/repos';

export async function GET(req: Request, ctx: any) {
const { params } = ctx;
const chain = await getChain(params.chainName);
try {
return NextResponse.json({
status: chain
? ((await fetch(`${chain.endpoints.rpc}/status`, { next: { revalidate: 0 } })
.then((data) => data.json())
.then((result) => {
return (
!result.result.sync_info.catching_up &&
Date.now() - Date.parse(result.result.sync_info.latest_block_time) <= 50000
);
})) as boolean)
: NextResponse.json({ status: false }),
});
} catch {
return NextResponse.json({ status: false });
}
}
23 changes: 23 additions & 0 deletions src/app/chains/[chain]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Link from 'next/link';
import { FC } from 'react';

interface OwnProps {
chain: string;
}
const NotFound: FC<OwnProps> = ({ chain }) => (
<div>
<div className="text-base">
<div>
Mainnet <span className="text-xl font-bold">{chain}</span> was not found!
</div>
<div>
try to fine one{' '}
<Link href={'/'}>
<span className="text-xl underline hover:no-underline">here</span>
</Link>
</div>
</div>
</div>
);

export default NotFound;
Loading

0 comments on commit 64dee81

Please sign in to comment.