Skip to content

Commit

Permalink
Merge branch 'fix/perf' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Feb 21, 2024
2 parents 53ab0ec + 7855fbd commit b592128
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"useGitignore": true,
"language": "en",
"words": [
"solmate",
"binkey",
"binsec",
"chainlist",
"cirip",
"dataurl",
"devpool",
Expand All @@ -25,6 +25,7 @@
"Rpcs",
"scalarmult",
"servedir",
"solmate",
"sonarjs",
"typebox",
"TYPEHASH",
Expand Down
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/esbuild-build.ts
static/scripts/rewards/constants.ts
static/scripts/rewards/render-transaction/render-transaction.ts
**/lib/**
19 changes: 4 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build & Deploy

on:
push:
pull_request:
workflow_dispatch:

env:
Expand All @@ -16,6 +17,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: "recursive" # Ensures submodules are checked out

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -28,31 +31,17 @@ jobs:
yarn build
echo -n $(echo "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" | cut -c1-7) > static/commit.txt
- name: Check Cloudflare API Token
id: check_token
run: |
if [[ -z "${{ secrets.CLOUDFLARE_API_TOKEN }}" ]]; then
echo "Cloudflare API token is not set. Skipping deployment."
echo "skip=true" >> $GITHUB_ENV
else
echo "skip=false" >> $GITHUB_ENV
fi
shell: bash

- name: Deploy to Cloudflare
if: env.skip != 'true'
uses: ubiquity/cloudflare-deploy-action@main
with:
cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare_api_token: JWo5dPsoyohH5PRu89-RktjCvRN0-ODC6CC9ZBqF # Specifically scoped for public contributors to automatically deploy to our team Cloudflare account
repository: ${{ github.repository }}
production_branch: ${{ github.event.repository.default_branch }}
output_directory: "static"
current_branch: ${{ github.ref_name }}
pull_request_number: ${{ github.event.pull_request.number }}
commit_sha: ${{ github.sha }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
app_id: ${{ secrets.APP_ID }}
app_installation_id: ${{ secrets.APP_INSTALLATION_ID }}
# Add any environment variables you need to pass along here
# SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
# SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
path = lib/ubiquibot
url = https://github.com/ubiquity/ubiquibot
shallow = true
[submodule "lib/chainlist"]
path = lib/chainlist
url = https://github.com/DefiLlama/chainlist.git
22 changes: 19 additions & 3 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import esbuild from "esbuild";
import * as dotenv from "dotenv";
const typescriptEntries = [
Expand All @@ -9,6 +10,15 @@ const typescriptEntries = [
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[]> = {};
// 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];
});

export const esBuildContext: esbuild.BuildOptions = {
sourcemap: true,
entryPoints: entries,
Expand All @@ -23,7 +33,7 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"]),
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }),
};

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

function createEnvDefines(variableNames: string[]): Record<string, string> {
function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
for (const name of variableNames) {
for (const name of envVarNames) {
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]);
}
}
defines["extraRpcs"] = JSON.stringify(extraRpcs);
return defines;
}
1 change: 1 addition & 0 deletions lib/chainlist
Submodule chainlist added at 805928
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
"format:cspell": "cspell **/*",
"prepare": "husky install"
"prepare": "husky install",
"postinstall": "git submodule update --init --recursive"
},
"keywords": [
"typescript",
Expand Down
13 changes: 10 additions & 3 deletions static/scripts/rewards/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// type RPC = { url: string; tracking?: string; trackingDetails?: string };
// type Network = { name?: string; rpcs: RPC[]; websiteDead?: boolean; rpcWorking?: boolean };
// type Networks = { [key: string]: Network };

declare const extraRpcs: Record<string, string[]>; // @DEV: passed in at build time check build/esbuild-build.ts

export enum NetworkIds {
Mainnet = 1,
Goerli = 5,
Gnosis = 100,
}
console.trace({ extraRpcs });

export enum Tokens {
DAI = "0x6b175474e89094c44da98b954eedeac495271d0f",
Expand Down Expand Up @@ -36,9 +43,9 @@ export const networkExplorers: Record<number, string> = {
};

export const networkRpcs: Record<number, string[]> = {
[NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet"],
[NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli"],
[NetworkIds.Gnosis]: ["https://rpc.gnosischain.com"],
[NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet", ...(extraRpcs[NetworkIds.Mainnet] || [])],
[NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli", ...(extraRpcs[NetworkIds.Goerli] || [])],
[NetworkIds.Gnosis]: [...(extraRpcs[NetworkIds.Gnosis] || [])],
};

export const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
Expand Down
4 changes: 2 additions & 2 deletions static/scripts/rewards/web3/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export async function handleNetwork(desiredNetworkId: number) {
invalidateButton.disabled = true;
}

const chainIdHex = String(web3provider.network.chainId);
const currentNetworkId = parseInt(chainIdHex, 16);
const network = await web3provider.getNetwork();
const currentNetworkId = network.chainId;

// watch for network changes
window.ethereum.on("chainChanged", <T>(newNetworkId: T | string) => handleIfOnCorrectNetwork(parseInt(newNetworkId as string, 16), desiredNetworkId));
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"include": ["src", "lib/chainlist/constants/extraRpcs.js", "static", "build", "scripts/typescript", "globals.d.ts"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
Expand Down

0 comments on commit b592128

Please sign in to comment.