Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/rpc selection #175

Merged
merged 14 commits into from
Mar 3, 2024
Merged
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"binsec",
"chainlist",
"cirip",
"Claimability",
"dataurl",
"devpool",
"ethersproject",
Expand All @@ -27,6 +28,7 @@
"servedir",
"solmate",
"sonarjs",
"SUPABASE",
"typebox",
"TYPEHASH",
"ubiquibot",
Expand Down
42 changes: 21 additions & 21 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
"project": ["./tsconfig.json"],
},
"plugins": ["@typescript-eslint", "sonarjs"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:sonarjs/recommended"],
Expand All @@ -11,15 +11,15 @@
"prefer-arrow-callback": [
"warn",
{
"allowNamedFunctions": true
}
"allowNamedFunctions": true,
},
],
"func-style": [
"warn",
"declaration",
{
"allowArrowFunctions": false
}
"allowArrowFunctions": false,
},
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "error",
Expand All @@ -35,8 +35,8 @@
"ignoreRestSiblings": true,
"vars": "all",
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
"argsIgnorePattern": "^_",
},
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-new": "error",
Expand All @@ -54,55 +54,55 @@
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": false
}
"match": false,
},
},
{
"selector": "memberLike",
"modifiers": ["private"],
"format": ["camelCase"],
"leadingUnderscore": "require"
"leadingUnderscore": "require",
},
{
"selector": "typeLike",
"format": ["PascalCase"]
"format": ["PascalCase"],
},
{
"selector": "typeParameter",
"format": ["PascalCase"],
"prefix": ["T"]
"prefix": ["T"],
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"],
"leadingUnderscore": "allow",
"trailingUnderscore": "allow"
"trailingUnderscore": "allow",
},
{
"selector": "variable",
"format": ["camelCase"],
"leadingUnderscore": "allow",
"trailingUnderscore": "allow"
"trailingUnderscore": "allow",
},
{
"selector": "variable",
"modifiers": ["destructured"],
"format": null
"format": null,
},
{
"selector": "variable",
"types": ["boolean"],
"format": ["PascalCase"],
"prefix": ["is", "should", "has", "can", "did", "will", "does"]
"prefix": ["is", "should", "has", "can", "did", "will", "does"],
},
{
"selector": "variableLike",
"format": ["camelCase"]
"format": ["camelCase"],
},
{
"selector": ["function", "variable"],
"format": ["camelCase"]
}
]
}
"format": ["camelCase"],
},
],
},
}
3 changes: 2 additions & 1 deletion .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ name: Conventional Commits

on:
push:
pull_request:

jobs:
conventional-commits:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ubiquity/action-conventional-commits@master
15 changes: 15 additions & 0 deletions .github/workflows/kebab-case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Enforce kebab-case

on:
push:
pull_request:

jobs:
check-filenames:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Check For Non Kebab-Cased TypeScript Files
run: .github/workflows/scripts/kebab-case.sh
29 changes: 29 additions & 0 deletions .github/workflows/scripts/kebab-case.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
non_compliant_files=()
ignoreList=("^\.\/.git" "^\.\/\..*" "^\.\/[^\/]*$")
while IFS= read -r line; do
ignoreList+=(".*$line")
done < .gitignore
while read -r file; do
basefile=$(basename "$file")
ignoreFile=false
for pattern in "${ignoreList[@]}"; do
if [[ "$file" =~ $pattern ]]; then
ignoreFile=true
break
fi
done
if $ignoreFile; then
continue
elif ! echo "$basefile" | grep -q -E "^([a-z0-9]+-)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$|^([a-z0-9]+_)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$"; then
non_compliant_files+=("$file")
echo "::warning file=$file::This file is not in kebab-case or snake_case"
fi
done < <(find . -type f -name '*.ts' -print | grep -E '/[a-z]+[a-zA-Z]*\.ts$')
if [ ${#non_compliant_files[@]} -ne 0 ]; then
echo "The following files are not in kebab-case or snake_case:"
for file in "${non_compliant_files[@]}"; do
echo " - $file"
done
exit 1
fi
31 changes: 31 additions & 0 deletions .github/workflows/scripts/kebabalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
non_compliant_files=()
ignoreList=("^\.\/.git" "^\.\/\..*" "^\.\/[^\/]*$")
while IFS= read -r line; do
ignoreList+=(".*$line")
done < .gitignore
while read -r file; do
basefile=$(basename "$file")
ignoreFile=false
for pattern in "${ignoreList[@]}"; do
if [[ "$file" =~ $pattern ]]; then
ignoreFile=true
break
fi
done
if $ignoreFile; then
continue
elif ! echo "$basefile" | grep -q -E "^([a-z0-9]+-)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$|^([a-z0-9]+_)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$"; then
non_compliant_files+=("$file")
echo "::warning file=$file::This file is not in kebab-case or snake_case"
newfile=$(dirname "$file")/$(echo "$basefile" | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g')
mv "$file" "$newfile"
fi
done < <(find . -type f -name '*.ts' -print | grep -E '/[a-z]+[a-zA-Z]*\.ts$')
if [ ${#non_compliant_files[@]} -ne 0 ]; then
echo "The following files are not in kebab-case or snake_case:"
for file in "${non_compliant_files[@]}"; do
echo " - $file"
done
exit 1
fi
24 changes: 14 additions & 10 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import esbuild from "esbuild";
import { execSync } from "child_process";
import * as dotenv from "dotenv";
import esbuild from "esbuild";
import extraRpcs from "../lib/chainlist/constants/extraRpcs";

const typescriptEntries = [
"static/scripts/rewards/index.ts",
"static/scripts/rewards/init.ts",
"static/scripts/audit-report/audit.ts",
"static/scripts/onboarding/onboarding.ts",
"static/scripts/key-generator/keygen.ts",
Expand Down Expand Up @@ -33,7 +35,10 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }),
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
extraRpcs: allNetworkUrls,
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
};

esbuild
Expand All @@ -46,22 +51,21 @@ esbuild
process.exit(1);
});

function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
function createEnvDefines(environmentVariables: string[], generatedAtBuild: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
for (const name of envVarNames) {
for (const name of environmentVariables) {
const envVar = process.env[name];
if (envVar !== undefined) {
defines[name] = JSON.stringify(envVar);
} else {
throw new Error(`Missing environment variable: ${name}`);
}
}
for (const key in extras) {
if (Object.prototype.hasOwnProperty.call(extras, key)) {
defines[key] = JSON.stringify(extras[key]);
for (const key in generatedAtBuild) {
if (Object.prototype.hasOwnProperty.call(generatedAtBuild, key)) {
defines[key] = JSON.stringify(generatedAtBuild[key]);
}
}
defines["extraRpcs"] = JSON.stringify(extraRpcs);
return defines;
}
14 changes: 2 additions & 12 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
export interface EthereumIsh {
autoRefreshOnNetworkChange: boolean;
chainId: string;
isMetaMask?: boolean;
isStatus?: boolean;
networkVersion: string;
selectedAddress: string;

on(event: "close" | "accountsChanged" | "chainChanged" | "networkChanged", callback: (payload: unknown) => void): void;
once(event: "close" | "accountsChanged" | "chainChanged" | "networkChanged", callback: (payload: unknown) => void): void;
}
import { Ethereum } from "ethereum-protocol";

declare global {
interface Window {
ethereum: EthereumIsh;
ethereum: Ethereum;
}
}
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"node": ">=20.10.0"
},
"scripts": {
"start": "run-s utils:hash start:sign start:ui",
"start": "run-s start:sign start:ui",
"watch": "nodemon -e ts,tsx --exec yarn start",
"watch:ui": "nodemon -e ts,tsx --exec yarn start:ui",
"format": "run-s format:lint format:prettier format:cspell",
"build": "run-s utils:hash utils:build",
"build": "run-s utils:build",
"start:ui": "tsx build/esbuild-server.ts",
"start:sign": "tsx scripts/typescript/generate-permit2-url.ts",
"utils:build": "tsx build/esbuild-build.ts",
"utils:hash": "git rev-parse --short HEAD > static/commit.txt",
"utils:get-invalidate-params": "forge script --via-ir scripts/solidity/GetInvalidateNonceParams.s.sol",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
Expand Down Expand Up @@ -55,6 +56,7 @@
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@types/ethereum-protocol": "^1.0.5",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
Expand All @@ -68,6 +70,7 @@
"husky": "^9.0.11",
"knip": "^5.0.1",
"lint-staged": "^15.2.2",
"nodemon": "^3.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"tsx": "^4.7.1",
Expand All @@ -77,7 +80,8 @@
"lint-staged": {
"*.ts": [
"yarn prettier --write",
"eslint --fix"
"eslint --fix",
"bash .github/workflows/scripts/kebab-case.sh"
],
"src/**.{ts,json}": [
"cspell"
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@
</main>

<ul class="notifications"></ul>
<script src="out/scripts/rewards/index.js" type="application/javascript"></script>
<script src="out/scripts/rewards/init.js" type="application/javascript"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions static/scripts/audit-report/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import GoDB from "godb";
import { permit2Abi } from "../rewards/abis";
import { Chain, ChainScan, DATABASE_NAME, NULL_HASH, NULL_ID } from "./constants";
import {
RateLimitOptions,
getCurrency,
getGitHubUrlPartsArray,
getOptimalRPC,
getRandomAPIKey,
populateTable,
primaryRateLimitHandler,
RateLimitOptions,
secondaryRateLimitHandler,
} from "./helpers";
import {
Expand All @@ -29,7 +29,7 @@ import {
StandardInterface,
TxData,
} from "./types";
import { getTxInfo } from "./utils/getTransaction";
import { getTxInfo } from "./utils/get-transaction";

declare const SUPABASE_URL: string;
declare const SUPABASE_ANON_KEY: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { Chain } from "../constants";
import { Transaction } from "../types/transaction";
import { getBlockInfo, updateBlockInfo } from "./blockInfo";
import { getBlockInfo, updateBlockInfo } from "./block-info";

export async function getTxInfo(hash: string, url: string, chain: Chain): Promise<Transaction> {
try {
Expand Down
Loading
Loading