forked from ubiquity/rpc-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ubiquity#28 from Keyrxng/improved-constants
- Loading branch information
Showing
23 changed files
with
31,815 additions
and
1,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", | ||
"version": "0.2", | ||
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "lib", "dist"], | ||
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "lib", "dist", "types/dynamic.ts"], | ||
"useGitignore": true, | ||
"language": "en", | ||
"words": ["dataurl", "devpool", "outdir", "servedir"], | ||
"dictionaries": ["typescript", "node", "software-terms"], | ||
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"], | ||
"ignoreRegExpList": ["[0-9a-fA-F]{6}"], | ||
"ignoreWords": ["Rpcs", "ethersproject", "publicnode", "WXDAI", "XDAI", "chainlist", "Knip", "LOCALSTORAGE"] | ||
"ignoreWords": ["Rpcs", "ethersproject", "publicnode", "WXDAI", "XDAI", "chainlist", "Knip", "LOCALSTORAGE", "sonarjs", "cronos", "Cronos", "gochain"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { appendFile, writeFile } from "fs/promises"; | ||
import { BlockExplorer, NativeToken } from "../types/handler"; | ||
import { generateChainData } from "../lib/chainlist/utils/fetch"; | ||
|
||
/** | ||
* This produces dynamic types and constants for: | ||
* - CHAINS_IDS | ||
* - NETWORKS | ||
* - NETWORK_FAUCETS | ||
* - NETWORK_EXPLORERS | ||
* - NETWORK_CURRENCIES | ||
* - EXTRA_RPCS | ||
*/ | ||
|
||
export async function createDynamicTypes() { | ||
const data = await generateChainData(); | ||
const idToNetwork: Record<string, string> = {}; | ||
const networkToId: Record<string, number> = {}; | ||
const idToRpc: Record<string, string[]> = {}; | ||
const idToFaucet: Record<string, string[]> = {}; | ||
const idToExplorers = {} as Record<string, BlockExplorer[]>; | ||
const idToNativeCurrency: Record<string, NativeToken> = {}; | ||
const extraRpcs: Record<string, string[]> = {}; | ||
|
||
for (const chain of data) { | ||
let { name, chainId, networkId, rpc, faucets, explorers, nativeCurrency } = chain; | ||
name = name.toLowerCase().replace(/\s/g, "-"); | ||
idToNetwork[chainId] = name; | ||
networkToId[name] = networkId; | ||
idToRpc[chainId] = rpc; | ||
idToFaucet[chainId] = faucets; | ||
|
||
if (explorers && explorers.length > 0) { | ||
idToExplorers[chainId] = explorers; | ||
} | ||
|
||
if (rpc && rpc.length > 0) { | ||
const rpcs = rpc.filter((rpc: { url: string }) => rpc.url); | ||
extraRpcs[chainId] = rpcs.map((rpc: { url: string }) => rpc.url); | ||
} | ||
|
||
idToNativeCurrency[chainId] = nativeCurrency; | ||
} | ||
|
||
const filename = "types/dynamic.ts"; | ||
|
||
// Clear the file | ||
await writeFile(filename, "/* eslint-disable sonarjs/no-duplicate-string */\n\n"); | ||
|
||
appendFile(filename, `\nexport const CHAINS_IDS = ${JSON.stringify(idToNetwork, null, 2)} as const;\n`); | ||
appendFile(filename, `\nexport const NETWORKS = ${JSON.stringify(networkToId, null, 2)} as const;\n`); | ||
appendFile(filename, `\nexport const NETWORK_FAUCETS = ${JSON.stringify(idToFaucet, null, 2)};\n`); | ||
appendFile(filename, `\nexport const NETWORK_EXPLORERS = ${JSON.stringify(idToExplorers, null, 2)};\n`); | ||
appendFile(filename, `\nexport const NETWORK_CURRENCIES = ${JSON.stringify(idToNativeCurrency, null, 2)};\n`); | ||
appendFile(filename, `\nexport const EXTRA_RPCS = ${JSON.stringify(extraRpcs, null, 2)};\n`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,21 @@ | |
"node": ">=20.10.0" | ||
}, | ||
"scripts": { | ||
"format": "run-s format:lint format:prettier format:cspell", | ||
"format": "run-p format:*", | ||
"format:lint": "eslint --fix .", | ||
"format:prettier": "prettier --write .", | ||
"format:cspell": "cspell **/*", | ||
"knip": "knip", | ||
"knip-ci": "knip --no-exit-code --reporter json", | ||
"prepare": "husky install", | ||
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist && rm -rf dist/src", | ||
"build:tests": "tsx build/esbuild-build-tests.ts && tsc --emitDeclarationOnly --declaration --project tsconfig.tests.json", | ||
"build": "rm -rf dist && tsx build/esbuild-build.ts", | ||
"postbuild": "yarn build:types", | ||
"postinstall": "git submodule update --init --recursive", | ||
"test": "rm -rf dist && yarn build:tests && jest" | ||
"build": "run-s clean build:types", | ||
"build:types": "tsx build/esbuild-build.ts && tsc --emitDeclarationOnly --declaration --outDir dist", | ||
"build:tests": "tsx build/esbuild-build-tests.ts && tsc --emitDeclarationOnly --declaration --project tsconfig.tests.json", | ||
"postbuild": "rm -rf dist/src", | ||
"pretest": "run-s clean build:tests", | ||
"test": "jest", | ||
"clean": "rm -rf dist" | ||
}, | ||
"keywords": [ | ||
"typescript", | ||
|
@@ -87,4 +89,4 @@ | |
] | ||
}, | ||
"packageManager": "[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
30022f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit
Coverage Report (20%)