Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix: Use private RPC in production
Browse files Browse the repository at this point in the history
  • Loading branch information
garethfuller committed Sep 6, 2024
1 parent ef3b8a4 commit 11a1ec3
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/modules/web3/ChainConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,21 @@ export const rpcFallbacks: Record<GqlChain, string | undefined> = {
}

const baseUrl = getBaseUrl()
const shouldUsePrivateRpc = !!process.env.PRIVATE_ALCHEMY_KEY
const getPrivateRpcUrl = (chain: GqlChain) => `${baseUrl}/api/rpc/${chain}`
const getRpcOverride = (chain: GqlChain) => {
if (shouldUsePrivateRpc) {
return getPrivateRpcUrl(chain)
}
return undefined
}

export const rpcOverrides: Record<GqlChain, string | undefined> = {
[GqlChain.Mainnet]: getRpcOverride(GqlChain.Mainnet),
[GqlChain.Arbitrum]: getRpcOverride(GqlChain.Arbitrum),
[GqlChain.Base]: getRpcOverride(GqlChain.Base),
[GqlChain.Avalanche]: getRpcOverride(GqlChain.Avalanche),
[GqlChain.Fantom]: getRpcOverride(GqlChain.Fantom),
[GqlChain.Gnosis]: getRpcOverride(GqlChain.Gnosis),
[GqlChain.Optimism]: getRpcOverride(GqlChain.Optimism),
[GqlChain.Polygon]: getRpcOverride(GqlChain.Polygon),
[GqlChain.Zkevm]: getRpcOverride(GqlChain.Zkevm),
[GqlChain.Sepolia]: getRpcOverride(GqlChain.Sepolia),
[GqlChain.Mainnet]: getPrivateRpcUrl(GqlChain.Mainnet),
[GqlChain.Arbitrum]: getPrivateRpcUrl(GqlChain.Arbitrum),
[GqlChain.Base]: getPrivateRpcUrl(GqlChain.Base),
[GqlChain.Avalanche]: getPrivateRpcUrl(GqlChain.Avalanche),
[GqlChain.Fantom]: getPrivateRpcUrl(GqlChain.Fantom),
[GqlChain.Gnosis]: getPrivateRpcUrl(GqlChain.Gnosis),
[GqlChain.Optimism]: getPrivateRpcUrl(GqlChain.Optimism),
[GqlChain.Polygon]: getPrivateRpcUrl(GqlChain.Polygon),
[GqlChain.Zkevm]: getPrivateRpcUrl(GqlChain.Zkevm),
[GqlChain.Sepolia]: getPrivateRpcUrl(GqlChain.Sepolia),
[GqlChain.Mode]: undefined,
[GqlChain.Fraxtal]: getRpcOverride(GqlChain.Fraxtal),
[GqlChain.Fraxtal]: getPrivateRpcUrl(GqlChain.Fraxtal),
}

const customMainnet = { iconUrl: '/images/chains/MAINNET.svg', ...mainnet }
Expand Down

0 comments on commit 11a1ec3

Please sign in to comment.