Skip to content

Commit

Permalink
Address network information export
Browse files Browse the repository at this point in the history
  • Loading branch information
wirednkod committed Feb 19, 2024
1 parent 63f3dbf commit def7df0
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ postcss.config.js
LICENSE
README.md
CHANGELOG.md
.licenserc.json
.licenserc.json

*json_export_index*
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
67 changes: 67 additions & 0 deletions packages/assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
47 changes: 47 additions & 0 deletions packages/assets/lib/external/config.js
Original file line number Diff line number Diff line change
@@ -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",
];
75 changes: 75 additions & 0 deletions packages/assets/lib/external/polkadot_directory_repo.js
Original file line number Diff line number Diff line change
@@ -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();
77 changes: 77 additions & 0 deletions packages/assets/lib/external/types.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions packages/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/assets/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"resolveJsonModule": true,
"esModuleInterop": true,
},
"include": ["./**/*", "./lib/ecosystem/json/*.json"],
"include": ["./**/*", "lib/ecosystem/json"]
}
2 changes: 1 addition & 1 deletion packages/ui-core/lib/accent/kusama-relay.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%);
}
2 changes: 1 addition & 1 deletion packages/ui-core/lib/accent/polkadot-relay.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%);
}
2 changes: 1 addition & 1 deletion packages/ui-core/lib/accent/westend-relay.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%);
}
2 changes: 1 addition & 1 deletion sandbox/src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -11284,6 +11289,7 @@ [email protected]:
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==
Expand Down

0 comments on commit def7df0

Please sign in to comment.