diff --git a/.cspell.json b/.cspell.json index a24a60a..d220b84 100644 --- a/.cspell.json +++ b/.cspell.json @@ -35,8 +35,7 @@ "WXDAI", "XDAI", "xmark", - - + "SUPABASE" ], "dictionaries": ["typescript", "node", "software-terms", "html"], "import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"], diff --git a/.env.example b/.env.example index e49d79a..6ee8810 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -MY_SECRET="MY_SECRET" +SUPABASE_URL="" +SUPBASE_ANON_KEY="" diff --git a/.gitmodules b/.gitmodules index 58889d8..c93a2e2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,7 @@ path = lib/ubiquibot url = https://github.com/ubiquity/ubiquibot branch = development +[submodule "lib/chainlist"] + path = lib/chainlist + url = https://github.com/DefiLlama/chainlist.git + branch = main diff --git a/build/esbuild-build.ts b/build/esbuild-build.ts index 0224a6f..d82f4de 100644 --- a/build/esbuild-build.ts +++ b/build/esbuild-build.ts @@ -1,9 +1,20 @@ // @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/onboarding/onboarding.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 = {}; +// 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, @@ -18,6 +29,7 @@ export const esBuildContext: esbuild.BuildOptions = { ".svg": "dataurl", }, outdir: "static/out", + define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { allNetworkUrls }), }; esbuild @@ -29,3 +41,23 @@ esbuild console.error(err); process.exit(1); }); + +function createEnvDefines(envVarNames: string[], extras: Record): Record { + const defines: Record = {}; + 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; +} diff --git a/lib/chainlist b/lib/chainlist new file mode 160000 index 0000000..8059283 --- /dev/null +++ b/lib/chainlist @@ -0,0 +1 @@ +Subproject commit 805928372c7a97eec513e8c74c344dd759f07e1c