From e33ec4e638b6db763c9a8eab167aca4476a0f367 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:33:54 +0100 Subject: [PATCH] chore: add function to get rpc-urls dynamically --- src/config.ts | 13 +++++++++++++ src/features/applications/components/ImpactTags.tsx | 1 - src/providers/index.tsx | 4 +--- src/utils/semaphore.ts | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/config.ts b/src/config.ts index f5100770..1dfabe7e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -55,6 +55,19 @@ export const semaphoreEthersChain = (): string => { } }; +/** + * Get the RPC URL based on the network we are connected to + * @returns the alchemy RPC URL + */ +export const getRPCURL = (): string | undefined => { + switch (process.env.NEXT_PUBLIC_CHAIN_NAME) { + case "optimismSepolia": + return `https://opt-sepolia.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ID!}`; + default: + return undefined; + } +}; + export const config = { logoUrl: "/Logo.svg", pageSize: 3 * 4, diff --git a/src/features/applications/components/ImpactTags.tsx b/src/features/applications/components/ImpactTags.tsx index a40c0cba..aa08efab 100644 --- a/src/features/applications/components/ImpactTags.tsx +++ b/src/features/applications/components/ImpactTags.tsx @@ -14,7 +14,6 @@ export const ImpactTags = (): JSX.Element => { control, }); - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition const selected = watch("impactCategory") ?? []; const error = formState.errors.impactCategory; diff --git a/src/providers/index.tsx b/src/providers/index.tsx index b412660c..aa45e622 100644 --- a/src/providers/index.tsx +++ b/src/providers/index.tsx @@ -63,9 +63,7 @@ function createWagmiConfig() { ssr: false, chains: activeChains as unknown as readonly [Chain, ...Chain[]], transports: { - [appConfig.config.network.id]: http( - `https://opt-sepolia.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ID!}`, - ), + [appConfig.config.network.id]: http(appConfig.getRPCURL()), }, }); diff --git a/src/utils/semaphore.ts b/src/utils/semaphore.ts index b660e489..49ad980b 100644 --- a/src/utils/semaphore.ts +++ b/src/utils/semaphore.ts @@ -3,7 +3,7 @@ import { SemaphoreEthers } from "@semaphore-protocol/data"; import { AbiCoder, JsonRpcSigner } from "ethers"; import { getSemaphoreGatekeeperData } from "maci-cli/sdk"; -import { config, semaphoreEthersChain } from "~/config"; +import { config, getRPCURL, semaphoreEthersChain } from "~/config"; /** * Encodes the Semaphore Proof to be sent on chain @@ -33,7 +33,7 @@ export const getSemaphoreProof = async (signer: JsonRpcSigner, identity: Identit maciAddress: config.maciAddress!, }); - const semaphore = new SemaphoreEthers(semaphoreEthersChain(), { + const semaphore = new SemaphoreEthers(getRPCURL() ?? semaphoreEthersChain(), { address: semaphoreContractAddress, });