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

feat: Dynamic rpc handler #183

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b087bf7
Merge pull request #132 from ubiquity/development
0x4007 Sep 12, 2023
c031b60
feat: upgrade deployments
0x4007 Feb 16, 2024
ff69f3b
Merge branch 'main' of https://github.com/ubiquity/pay.ubq.fi
0x4007 Feb 16, 2024
f929e15
Merge branch 'development' of https://github.com/ubiquity/pay.ubq.fi
0x4007 Feb 16, 2024
785d151
Merge branch 'development'
0x4007 Feb 19, 2024
70811a7
fix: remove deprecated ci
0x4007 Feb 19, 2024
86f7a8f
chore: update supabase key name
0x4007 Feb 20, 2024
047368b
chore: update supabase key name
0x4007 Feb 20, 2024
7d88536
Merge pull request #167 from pavlovcik/fix/perf
0x4007 Feb 20, 2024
f5e3a80
feat: sub 1s load time
Keyrxng Feb 20, 2024
ebd54e1
fix: conflicts
Keyrxng Feb 20, 2024
7fab1b4
chore: fetch inside try
Keyrxng Feb 20, 2024
f1ca988
feat: sub 1s load time
Keyrxng Feb 20, 2024
97fb13c
chore: fetch inside try
Keyrxng Feb 20, 2024
2adf64b
fix: revert and pull from head
Keyrxng Feb 20, 2024
c0249df
Merge branch 'ubiquity:development' into speed-improvements
Keyrxng Feb 21, 2024
8a09cec
fix: merge bugs and working on stability
0x4007 Feb 21, 2024
faf7219
chore: commit hash now in esbuild process
0x4007 Feb 21, 2024
517dd48
fix: use allnetworkurls
Keyrxng Feb 21, 2024
80ea9ea
refactor: rpc only checks and selects once at session start
0x4007 Feb 21, 2024
0fc24a2
fix: use fastest rpc endpoint for requests
0x4007 Feb 21, 2024
cef5280
chore: kebabalize
0x4007 Feb 21, 2024
dae1037
feat: update imports in kebablize
0x4007 Feb 21, 2024
0ff7042
feat: mac support
0x4007 Feb 21, 2024
f4c71ec
revert: kebabalize only files names
0x4007 Feb 21, 2024
ae73eee
chore: kebabed
0x4007 Feb 21, 2024
c065b8c
feat: fast claims
0x4007 Feb 21, 2024
f9c2b87
fix: post claim render bug
0x4007 Feb 21, 2024
2c8f5ca
fix: toaster errors on claims for erc20
0x4007 Feb 21, 2024
b9f9c77
fix: loader animation on claim button
0x4007 Feb 21, 2024
f307223
refactor: move app into all functions
0x4007 Feb 22, 2024
4787509
Merge branch 'main' of https://github.com/pavlovcik/pay.ubq.fi
0x4007 Feb 22, 2024
2d96f10
chore: erc permits first pass
Keyrxng Feb 23, 2024
8693e52
feat: permit second pass working
Keyrxng Feb 23, 2024
1fe025d
fix: rpc blacklist
Keyrxng Feb 23, 2024
6a57f38
fix: 721 permit from signTyped vs static
Keyrxng Feb 25, 2024
a4d0750
fix: exclude node_modules from kebab workflow
Keyrxng Feb 25, 2024
b5d1793
fix: pass permit into permit2 and align 721 permit with anvil depl
Keyrxng Feb 25, 2024
ee787e5
Merge branch 'ubiquity:development' into sync-erc-permits
Keyrxng Feb 25, 2024
8392fb7
Merge branch 'sync-erc-permits' of https://github.com/ubq-testing/pay…
Keyrxng Feb 25, 2024
b7483f7
chore: pagination and permit to reward
Keyrxng Feb 25, 2024
6f3bfdf
Merge branch 'ubiquity:development' into speed-improvements
Keyrxng Feb 26, 2024
16a534e
fix: no network resolved
Keyrxng Feb 26, 2024
123f178
Merge pull request #169 from ubq-testing/speed-improvements
0x4007 Feb 26, 2024
ea0baff
chore: remove blacklist
molecula451 Feb 27, 2024
6713c16
Merge pull request #179 from molecula451/blacklist-bye
0x4007 Feb 27, 2024
40b8c3e
chore: no rpc mapping for localhost
Keyrxng Feb 27, 2024
3a34de6
Merge branch 'main' of https://github.com/ubiquity/pay.ubq.fi
0x4007 Feb 28, 2024
065b1eb
Merge branch 'development'
0x4007 Feb 28, 2024
1d5bb65
fix: request account
Keyrxng Feb 28, 2024
a5855f7
feat: rpc handler
Keyrxng Feb 29, 2024
75cb97a
chore: merge from main and test
Keyrxng Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
},
],
},
}
1 change: 1 addition & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Conventional Commits

on:
push:
pull_request:

jobs:
conventional-commits:
Expand Down
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
30 changes: 30 additions & 0 deletions .github/workflows/scripts/kebab-case.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
non_compliant_files=()
ignoreList=("^\.\/.git" "^\.\/\..*" "^\.\/[^\/]*$")
ignoreList+=("^\.\/node_modules")
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
34 changes: 21 additions & 13 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import { execSync } from "child_process";
import * as dotenv from "dotenv";
import esbuild from "esbuild";
import extraRpcs from "../lib/chainlist/constants/extraRpcs";

import * as dotenv from "dotenv";
import esbuild from "esbuild";
import chainlist 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",
];
const cssEntries = ["static/styles/rewards/rewards.css", "static/styles/audit-report/audit.css", "static/styles/onboarding/onboarding.css"];
export const entries = [...typescriptEntries, ...cssEntries];

const allNetworkUrls: Record<string, string[]> = {};
const extraRpcs: Record<string, string[]> = {};
// this flattens all the rpcs into a single object, with key names that match the networkIds. The arrays are just of URLs per network ID.

Object.keys(extraRpcs).forEach((networkId) => {
const officialUrls = extraRpcs[networkId].rpcs.filter((rpc) => typeof rpc === "string");
const extraUrls: string[] = extraRpcs[networkId].rpcs.filter((rpc) => rpc.url !== undefined).map((rpc) => rpc.url);
allNetworkUrls[networkId] = [...officialUrls, ...extraUrls];
Object.keys(chainlist).forEach((networkId) => {
const officialUrls = chainlist[networkId].rpcs.filter((rpc) => typeof rpc === "string");
const extraUrls: string[] = chainlist[networkId].rpcs.filter((rpc) => rpc.url !== undefined && rpc.tracking === "none").map((rpc) => rpc.url);
extraRpcs[networkId] = [...officialUrls, ...extraUrls];
});

export const esBuildContext: esbuild.BuildOptions = {
Expand All @@ -33,7 +38,10 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { extraRpcs: allNetworkUrls }),
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
extraRpcs,
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
};

esbuild
Expand All @@ -46,20 +54,20 @@ 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]);
}
}
return defines;
Expand Down
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
Loading
Loading