Skip to content

Commit

Permalink
Merge pull request #169 from ubq-testing/speed-improvements
Browse files Browse the repository at this point in the history
Sub 1s loading UI
  • Loading branch information
0x4007 authored Feb 26, 2024
2 parents 7d88536 + 16a534e commit 123f178
Show file tree
Hide file tree
Showing 16 changed files with 820 additions and 765 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ on:
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: "recursive" # Ensures submodules are checked out
# with:
# submodules: "recursive" # Ensures submodules are checked out

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -25,19 +27,16 @@ jobs:
run: |
yarn
yarn build
echo -n $(echo "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" | cut -c1-7) > static/commit.txt
env: # Set environment variables for the build
SUPABASE_URL: "https://wfzpewmlyiozupulbuur.supabase.co"
SUPABASE_ANON_KEY: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6IndmenBld21seWlvenVwdWxidXVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTU2NzQzMzksImV4cCI6MjAxMTI1MDMzOX0.SKIL3Q0NOBaMehH0ekFspwgcu3afp3Dl9EDzPqs1nKs"

- name: Deploy to Cloudflare
if: env.skip != 'true'
uses: ubiquity/cloudflare-deploy-action@main
with:
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 }}
# Add any environment variables you need to pass along here
# SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
# SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
commit_sha: ${{ github.event.pull_request.head.sha }}
2 changes: 1 addition & 1 deletion .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ jobs:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ubiquity/action-conventional-commits@master
56 changes: 51 additions & 5 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-expect-error - Could not find a declaration file for module
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import esbuild from "esbuild";
import * as dotenv from "dotenv";
const typescriptEntries = [
"static/scripts/rewards/index.ts",
"static/scripts/audit-report/audit.ts",
Expand All @@ -12,9 +14,35 @@ 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.

const blacklist = ["https://xdai-archive.blockscout.com", "https://gnosis.api.onfinality.io/public"];

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);
const officialUrls = extraRpcs[networkId].rpcs.filter((rpc) => {
if (typeof rpc === "string") {
if (blacklist.includes(rpc)) {
return null;
} else {
return rpc;
}
}
});
const extraUrls: string[] = extraRpcs[networkId].rpcs
.filter((rpc) => rpc.url !== undefined)
.map((rpc) => {
if (typeof rpc === "string") {
if (blacklist.includes(rpc)) {
return "";
} else {
return rpc;
}
} else {
if (blacklist.includes(rpc.url)) {
return "";
} else {
return rpc.url;
}
}
});
allNetworkUrls[networkId] = [...officialUrls, ...extraUrls];
});

Expand All @@ -32,9 +60,7 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: {
extraRpcs: JSON.stringify(allNetworkUrls),
},
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }),
};

esbuild
Expand All @@ -46,3 +72,23 @@ esbuild
console.error(err);
process.exit(1);
});

function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
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(allNetworkUrls);
return defines;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@octokit/plugin-throttling": "^8.1.3",
"@octokit/rest": "^20.0.2",
"@sinclair/typebox": "^0.32.14",
"@supabase/supabase-js": "2.39.7",
"@types/libsodium-wrappers": "^0.7.13",
"@uniswap/permit2-sdk": "^1.2.0",
"axios": "^1.6.7",
Expand Down
19 changes: 12 additions & 7 deletions scripts/typescript/generate-permit2-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ dotenv.config();

const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // same on all chains

generate().catch((error) => {
generateERC20Permit().catch((error) => {
console.error(error);
verifyEnvironmentVariables();
process.exitCode = 1;
});

async function generate() {
export async function generateERC20Permit(multi = false) {
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL);
const myWallet = new ethers.Wallet(process.env.UBIQUIBOT_PRIVATE_KEY || "", provider);

Expand Down Expand Up @@ -59,9 +59,14 @@ async function generate() {
];

const base64encodedTxData = Buffer.from(JSON.stringify(txData)).toString("base64");
log.ok("Testing URL:");
console.log(`${process.env.FRONTEND_URL}?claim=${base64encodedTxData}`);
log.ok("Public URL:");
console.log(`https://pay.ubq.fi?claim=${base64encodedTxData}`);
console.log();

if (multi) {
return `${process.env.FRONTEND_URL}?claim=${base64encodedTxData}`;
} else {
log.ok("Testing URL:");
console.log(`${process.env.FRONTEND_URL}?claim=${base64encodedTxData}`);
log.ok("Public URL:");
console.log(`https://pay.ubq.fi?claim=${base64encodedTxData}`);
console.log();
}
}
16 changes: 16 additions & 0 deletions scripts/typescript/multi-permits.t.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { generateERC20Permit } from "./generate-permit2-url";
import { log, verifyEnvironmentVariables } from "./utils";

export async function generateMultiERC20Permits() {
for (let i = 0; i < 5; i++) {
const url = await generateERC20Permit();
log.ok("Testing URL:");
console.log(url);
}
}

generateMultiERC20Permits().catch((error) => {
console.error(error);
verifyEnvironmentVariables();
process.exitCode = 1;
});
Loading

0 comments on commit 123f178

Please sign in to comment.