From def7df07ea005c001b9afab302d28651e55468a9 Mon Sep 17 00:00:00 2001 From: Nikos Kontakis Date: Mon, 19 Feb 2024 15:14:21 +0200 Subject: [PATCH] Address network information export --- .eslintignore | 4 +- package.json | 1 + packages/assets/README.md | 67 ++++++++++++++++ packages/assets/lib/external/config.js | 47 +++++++++++ .../lib/external/polkadot_directory_repo.js | 75 ++++++++++++++++++ packages/assets/lib/external/types.ts | 77 +++++++++++++++++++ packages/assets/package.json | 2 + packages/assets/tsconfig.json | 2 +- packages/ui-core/lib/accent/kusama-relay.css | 2 +- .../ui-core/lib/accent/polkadot-relay.css | 2 +- packages/ui-core/lib/accent/westend-relay.css | 2 +- sandbox/src/styles/index.scss | 2 +- yarn.lock | 6 ++ 13 files changed, 283 insertions(+), 6 deletions(-) create mode 100644 packages/assets/lib/external/config.js create mode 100644 packages/assets/lib/external/polkadot_directory_repo.js create mode 100644 packages/assets/lib/external/types.ts diff --git a/.eslintignore b/.eslintignore index 3553892d..e3e5424d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -23,4 +23,6 @@ postcss.config.js LICENSE README.md CHANGELOG.md -.licenserc.json \ No newline at end of file +.licenserc.json + +*json_export_index* diff --git a/package.json b/package.json index e2a89cd7..8956007f 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "framer-motion": "^11.0.5", "gulp": "^4.0.2", "gulp-livereload": "^4.0.2", + "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", "gulp-sass": "^5.0.0", "gulp-sourcemaps": "^3.0.0", diff --git a/packages/assets/README.md b/packages/assets/README.md index d2e38430..b9b0eb80 100644 --- a/packages/assets/README.md +++ b/packages/assets/README.md @@ -73,3 +73,70 @@ export const ValidatorCommunity = [ | Ordering | Please place your operator in alphabetical order within `ValidatorCommunity`. | Please submit an issue for any queries around adding your operator details. + +## Adding Network Information + +Network members can add the network's information by following the JSON interface as seen below: + +```ts +export interface NetworkInformation { + name: string; + network_type: string; + chain: Chain; + chainspec: Chainspec; + goals: string[]; + repository: string; + validators: string[]; + release_cycle: string; + specs: Specs; + contacts: Contact[]; + faucet?: any; + rpc_endpoints: RpcEndpoint[]; + api_endpoints: ApiEndpoint[]; + bootnodes: Bootnode[]; + documentation: string[]; + expectations: any[]; + features: string[]; + notes: any[]; +} + +export interface Chain { + type: string; + parent?: string; + consensus: string; + sudo: boolean; + para_id?: number; +} + +export interface Chainspec { + http_url: string; +} + +export interface Specs { + block_time: number; + decimals: number; + token: string; + ss58_format: number; + ed?: number; + lease_period?: number; + era?: any; +} + +export interface Contact { + type: string; + contact: string; +} + +export interface Endpoint { + name: string; + url: string; +} + +export type RpcEndpoint = Endpoint; +export type ApiEndpoint = Endpoint; +export type Bootnode = Endpoint; +``` + +## Editing Network Information + +In case some information need to be updated, you can open a PR with the needed changes to the [asset's repository](https://github.com/polkadot-ui/library); \ No newline at end of file diff --git a/packages/assets/lib/external/config.js b/packages/assets/lib/external/config.js new file mode 100644 index 00000000..8ea489d7 --- /dev/null +++ b/packages/assets/lib/external/config.js @@ -0,0 +1,47 @@ +/* @license Copyright 2024 @polkadot-ui/library authors & contributors +SPDX-License-Identifier: MIT */ + +export const POLKADOT_NETWORK_URL = + "https://raw.githubusercontent.com/polkadot-cloud/polkadot_network_directory/master/chain_info/"; + +export const NETWORKS = [ + "Acala", + "Ajuna", + "Aleph_Zero", + "Aleph_Zero_Testnet", + "Astar", + "Bajun", + "Basilisk", + "Bifrost", + "Bifrost_Kusama", + "Contracts", + "HydraDX", + "Idiyanale_Testnet", + "Karura", + "Khala", + "Kusama", + "Kusama_Asset_Hub", + "Kusama_BridgeHub", + "Moonbase_Alpha", + "Moonbase_Relay", + "Moonbeam", + "Moonriver", + "Phala", + "Polkadot", + "Polkadot_Asset_Hub", + "Polkadot_BridgeHub", + "Polkadot_Collectives", + "Rococo", + "Rococo_Asset_Hub", + "Rococo_BridgeHub", + "Shibuya", + "Shiden", + "Tangle", + "Tinkernet", + "Tokyo", + "Watr", + "Westend", + "Westend_Asset_Hub", + "Westend_BridgeHub", + "Westend_Collectives", +]; diff --git a/packages/assets/lib/external/polkadot_directory_repo.js b/packages/assets/lib/external/polkadot_directory_repo.js new file mode 100644 index 00000000..4a308c20 --- /dev/null +++ b/packages/assets/lib/external/polkadot_directory_repo.js @@ -0,0 +1,75 @@ +/* @license Copyright 2024 @polkadot-ui/library authors & contributors +SPDX-License-Identifier: MIT */ + +import fs from "fs"; +import http from "https"; +import { parse } from "yaml"; + +import { POLKADOT_NETWORK_URL, NETWORKS } from "./config.js"; + +const EXTERNAL_DIR = "./lib/external/"; +const YAML_DIR = EXTERNAL_DIR + "yaml/"; +const JSON_DIR = EXTERNAL_DIR + "json/"; +const dirs = [YAML_DIR, JSON_DIR]; + +fs.rmSync(JSON_DIR, { recursive: true, force: true }); +fs.rmSync(YAML_DIR, { recursive: true, force: true }); + +dirs.forEach((dir) => { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } +}); + +const writeStream = fs.createWriteStream(EXTERNAL_DIR + "index.ts"); +writeStream.write(`export * from "./json/index";`); +writeStream.write(`export * from "./types";`); +writeStream.end(); + +const generateFiles = (f) => { + const yamlFile = f + ".yaml"; + const jsonFile = f + ".json"; + const downloadFile = fs.createWriteStream(YAML_DIR + yamlFile); + http.get(POLKADOT_NETWORK_URL + yamlFile, (response) => { + response.pipe(downloadFile); + // after download completed, convert to JSON and close filestream + downloadFile.on("finish", () => { + const ymlFile = fs.readFileSync(YAML_DIR + yamlFile, "utf8"); + fs.writeFileSync( + `./lib/external/json/${jsonFile}`, + JSON.stringify(parse(ymlFile)) + ); + downloadFile.close(); + }); + }); +}; + +for (const f of NETWORKS) { + generateFiles(f); +} + +const createIndexFile = () => { + const exportArray = []; + const indexFile = fs.createWriteStream(JSON_DIR + "index.tsx", { + flags: "a", + }); + indexFile.write( + `/* @license Copyright 2024 @polkadot-ui/library authors & contributors\n` + ); + indexFile.write(`SPDX-License-Identifier: MIT */\n`); + indexFile.write(`import { NetworkInformation } from "../types";\n`); + + for (const f of NETWORKS) { + const f_lower = f.toLowerCase(); + indexFile.write(`import ${f_lower + "Json"} from "./${f}.json";\n`); + indexFile.write( + `const ${f_lower}: NetworkInformation = ${f_lower + "Json"};\n` + ); + exportArray.push(f_lower); + } + + indexFile.write(`export { ${exportArray.join(", ")} };\n`); + indexFile.end(); +}; + +createIndexFile(); diff --git a/packages/assets/lib/external/types.ts b/packages/assets/lib/external/types.ts new file mode 100644 index 00000000..79926f5c --- /dev/null +++ b/packages/assets/lib/external/types.ts @@ -0,0 +1,77 @@ +export interface NetworkInformation { + name: string; + network_type: string; + // TODO, add type guard for string + // | "mainnet" + // | "testnet" + // | "canarynet" + // | "solo_mainnet" + // | "solo_testnet"; + chain: Chain; + chainspec: Chainspec; + goals: string[]; + repository: string; + validators: string[]; + release_cycle: string; + specs: Specs; + contacts: Contact[]; + faucet?: null | string; + rpc_endpoints: RpcEndpoint[]; + api_endpoints: ApiEndpoint[]; + bootnodes: Bootnode[]; + documentation: string[]; + expectations: string[]; + features: string[]; + notes?: string[]; +} + +export interface Chain { + type: string; + // TODO, add type guard for string + // | "relaychain" + // | "parachain" + // | "testnet" + // | "solo_mainnet" + // | "solo_testnet"; + parent?: string; + // TODO, add type guard for string + // | "Polkadot" + // | "Kusama" + // | "Westend" + // | "Rococo" + // | "Moonbase Relay" + // | "Tokyo"; + consensus: string; + // TODO, add type guard for string + // "PoS" | "PoA" | "Aura"; + sudo: boolean; + para_id?: number; +} + +export interface Chainspec { + http_url: string; +} + +export interface Specs { + block_time: number; + decimals: number; + token: string; + ss58_format: number; + ed?: number; + lease_period?: number; + era?: number | null; +} + +export interface Contact { + type: string; + contact: string; +} + +export interface Endpoint { + name: string; + url: string; +} + +export type RpcEndpoint = Endpoint; +export type ApiEndpoint = Endpoint; +export type Bootnode = Endpoint; diff --git a/packages/assets/package.json b/packages/assets/package.json index 07a81163..a9722e3e 100644 --- a/packages/assets/package.json +++ b/packages/assets/package.json @@ -21,8 +21,10 @@ }, "homepage": "https://github.com/polkadot-ui/library#readme", "scripts": { + "prebuild": "node ./lib/external/polkadot_directory_repo.js", "build:mock": "node ../../builder/run.mjs -t package:build -p assets", "build": "rm -fr dist && gulp --silent && cp LICENSE dist && yarn build:mock", + "postbuild": "rm -rf ./lib/external/yaml ./lib/external/json ./lib/external/index.ts", "clear": "rm -rf node_modules dist tsconfig.tsbuildinfo" } } diff --git a/packages/assets/tsconfig.json b/packages/assets/tsconfig.json index 6c2b32f6..0ef1a5a0 100644 --- a/packages/assets/tsconfig.json +++ b/packages/assets/tsconfig.json @@ -16,5 +16,5 @@ "resolveJsonModule": true, "esModuleInterop": true, }, - "include": ["./**/*", "./lib/ecosystem/json/*.json"], + "include": ["./**/*", "lib/ecosystem/json"] } diff --git a/packages/ui-core/lib/accent/kusama-relay.css b/packages/ui-core/lib/accent/kusama-relay.css index e409629c..067e8244 100644 --- a/packages/ui-core/lib/accent/kusama-relay.css +++ b/packages/ui-core/lib/accent/kusama-relay.css @@ -16,7 +16,7 @@ SPDX-License-Identifier: MIT */ --accent-color-transparent-light: rgb(51 51 51 / 5%); --accent-color-transparent-dark: rgb(102 102 102 / 5%); - + --accent-color-pending-light: rgb(51 51 51 / 50%); --accent-color-pending-dark: rgb(102 102 102 / 50%); } diff --git a/packages/ui-core/lib/accent/polkadot-relay.css b/packages/ui-core/lib/accent/polkadot-relay.css index 38d3c4ef..dd547341 100644 --- a/packages/ui-core/lib/accent/polkadot-relay.css +++ b/packages/ui-core/lib/accent/polkadot-relay.css @@ -16,7 +16,7 @@ SPDX-License-Identifier: MIT */ --accent-color-transparent-light: rgb(211 48 121 / 5%); --accent-color-transparent-dark: rgb(211 48 121 / 5%); - + --accent-color-pending-light: rgb(211 48 121 / 50%); --accent-color-pending-dark: rgb(211 48 121 / 50%); } diff --git a/packages/ui-core/lib/accent/westend-relay.css b/packages/ui-core/lib/accent/westend-relay.css index f1fd3a4f..c175b1f0 100644 --- a/packages/ui-core/lib/accent/westend-relay.css +++ b/packages/ui-core/lib/accent/westend-relay.css @@ -16,7 +16,7 @@ SPDX-License-Identifier: MIT */ --accent-color-transparent-light: rgb(218 78 113 / 5%); --accent-color-transparent-dark: rgb(218 78 113 / 5%); - + --accent-color-pending-light: rgb(218 78 113 / 50%); --accent-color-pending-dark: rgb(218 78 113 / 50%); } diff --git a/sandbox/src/styles/index.scss b/sandbox/src/styles/index.scss index d358c2d3..2ffacce7 100644 --- a/sandbox/src/styles/index.scss +++ b/sandbox/src/styles/index.scss @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT */ /* Developer Notes: * This file should be imported in the main library entry file. */ - html { +html { font-size: 10px; @media (width >= 600px) { diff --git a/yarn.lock b/yarn.lock index 8f7c2ac5..dbc64b16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5768,6 +5768,11 @@ gulp-livereload@^4.0.2: tiny-lr "^1.1.1" vinyl "^2.2.0" +gulp-rename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-2.0.0.tgz#9bbc3962b0c0f52fc67cd5eaff6c223ec5b9cf6c" + integrity sha512-97Vba4KBzbYmR5VBs9mWmK+HwIf5mj+/zioxfZhOKeXtx5ZjBk57KFlePf5nxq9QsTtFl0ejnHE3zTC9MHXqyQ== + gulp-replace@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/gulp-replace/-/gulp-replace-1.1.4.tgz#06a0e9ee36f30e343c1e0a2dd760ec32c8a3d3b2" @@ -11284,6 +11289,7 @@ workerpool@6.2.1: integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==