Skip to content

Commit

Permalink
Merge pull request #100 from lidofinance/refactor/rpc-url-env
Browse files Browse the repository at this point in the history
Refactor/rpc url env
  • Loading branch information
katamarinaki authored Feb 16, 2024
2 parents b486c05 + 1cb70a7 commit f197868
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 40 deletions.
13 changes: 3 additions & 10 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# https://{NETWORK}.infura.io/v3/{INFURA_API_KEY}
INFURA_API_KEY=

# https://eth-{NETWORK}.alchemyapi.io/v2/{ALCHEMY_API_KEY}
ALCHEMY_API_KEY=

# EL_RPC_URLS_{CHAIN_ID} list or URLs delimeted by commas, first entry is primary, else are fallbacks
EL_RPC_URLS_1=
EL_RPC_URLS_5=
# EL_RPC_URLS list or URLs delimeted by commas, first entry is primary, else are fallbacks
EL_RPC_URLS=

WALLETCONNECT_PROJECT_ID=

# supported networks for connecting wallet
SUPPORTED_CHAINS=1,5

# this chain uses when a wallet is not connected
DEFAULT_CHAIN=1
CHAIN_ID=1

# comma-separated trusted hosts for Content Security Policy
# e.g. http://localhost:PORT for local development
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ FROM node:16-alpine as base

ARG BASE_PATH=""
ARG SUPPORTED_CHAINS="1"
ARG DEFAULT_CHAIN="1"
ARG CHAIN_ID="1"

ENV NEXT_TELEMETRY_DISABLED=1 \
BASE_PATH=$BASE_PATH \
SUPPORTED_CHAINS=$SUPPORTED_CHAINS \
DEFAULT_CHAIN=$DEFAULT_CHAIN
CHAIN_ID=$CHAIN_ID

WORKDIR /app
RUN apk add --no-cache curl=~8.5.0-r0
Expand Down
3 changes: 1 addition & 2 deletions additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ declare module '*.svg' {
}

type RuntimeConfig = {
rpcUrls_1: string[];
rpcUrls_5: string[];
rpcUrls: string[];
};
6 changes: 3 additions & 3 deletions config/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CHAINS } from 'config/chains';
import getConfig from 'next/config';

const { serverRuntimeConfig } = getConfig();
const { rpcUrls_1, rpcUrls_5 } = serverRuntimeConfig;
const { rpcUrls } = serverRuntimeConfig;

export const getBackendRPCPath = (chainId: CHAINS): string => {
const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin;
Expand All @@ -15,6 +15,6 @@ export const backendRPC = {
};

export const externalRPC: Record<number, [string, ...string[]]> = {
[CHAINS.Mainnet]: rpcUrls_1,
[CHAINS.Goerli]: rpcUrls_5,
[CHAINS.Mainnet]: rpcUrls,
[CHAINS.Goerli]: rpcUrls,
};
2 changes: 1 addition & 1 deletion env-dynamics.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type number */
export const defaultChain = parseInt(process.env.DEFAULT_CHAIN, 10) || 1;
export const defaultChain = parseInt(process.env.CHAIN_ID, 10) || 1;
/** @type number[] */
export const supportedChains = process.env?.SUPPORTED_CHAINS?.split(',').map(
(chainId) => parseInt(chainId, 10),
Expand Down
4 changes: 1 addition & 3 deletions next-logger.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const projectDir = process.cwd()
loadEnvConfig(projectDir)

const patterns = [
...commonPatterns,
process.env.INFURA_API_KEY,
process.env.ALCHEMY_API_KEY,
...commonPatterns,
];

const mask = satanizer(patterns);
Expand Down
23 changes: 4 additions & 19 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,9 @@ import buildDynamics from './scripts/build-dynamics.mjs';

buildDynamics();

const infuraApiKey = process.env.INFURA_API_KEY;
const alchemyApiKey = process.env.ALCHEMY_API_KEY;
const rpcUrls_1 =
(process.env.EL_RPC_URLS_1 && process.env.EL_RPC_URLS_1.split(',')) ||
[
alchemyApiKey && `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`,
infuraApiKey && `https://mainnet.infura.io/v3/${infuraApiKey}`,
].filter(Boolean);

const rpcUrls_5 =
(process.env.EL_RPC_URLS_5 && process.env.EL_RPC_URLS_5.split(',')) ||
[
alchemyApiKey && `https://eth-goerli.alchemyapi.io/v2/${alchemyApiKey}`,
infuraApiKey && `https://goerli.infura.io/v3/${infuraApiKey}`,
].filter(Boolean);
const rpcUrls =
(process.env.EL_RPC_URLS && process.env.EL_RPC_URLS.split(',')) ||
[].filter(Boolean);

const cspTrustedHosts = process.env.CSP_TRUSTED_HOSTS?.split(',') ?? [
'https://*.lido.fi',
Expand Down Expand Up @@ -166,10 +154,7 @@ export default {
];
},
serverRuntimeConfig: {
infuraApiKey,
alchemyApiKey,
rpcUrls_1,
rpcUrls_5,
rpcUrls,
rateLimit,
rateLimitTimeFrame,
},
Expand Down

0 comments on commit f197868

Please sign in to comment.