Skip to content

Commit

Permalink
chore: add function to get rpc-urls dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jul 15, 2024
1 parent 3743151 commit e33ec4e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/features/applications/components/ImpactTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils/semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});

Expand Down

0 comments on commit e33ec4e

Please sign in to comment.