-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ts
53 lines (43 loc) · 1.72 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { ChainId } from '@usedapp/core';
interface AppConfig {
jsonRpcUri: string;
wsRpcUri: string;
subgraphApiUri: string;
enableHistory: boolean;
}
type SupportedChains = ChainId.Rinkeby | ChainId.Mainnet | ChainId.Hardhat;
export const CHAIN_ID: SupportedChains = parseInt(process.env.NEXT_PUBLIC_CHAIN_ID ?? '4');
export const ETHERSCAN_API_KEY = process.env.NEXT_PUBLIC_ETHERSCAN_API_KEY ?? '';
const INFURA_PROJECT_ID = process.env.NEXT_PUBLIC_INFURA_PROJECT_ID;
export const createNetworkHttpUrl = (network: string): string => {
const custom = process.env[`REACT_APP_${network.toUpperCase()}_JSONRPC`];
return custom || `https://${network}.infura.io/v3/${INFURA_PROJECT_ID}`;
};
export const createNetworkWsUrl = (network: string): string => {
const custom = process.env[`REACT_APP_${network.toUpperCase()}_WSRPC`];
return custom || `wss://${network}.infura.io/ws/v3/${INFURA_PROJECT_ID}`;
};
const app: Record<SupportedChains, AppConfig> = {
[ChainId.Rinkeby]: {
jsonRpcUri: createNetworkHttpUrl('rinkeby'),
wsRpcUri: createNetworkWsUrl('rinkeby'),
subgraphApiUri: 'https://api.thegraph.com/subgraphs/name/nounsdao/nouns-subgraph-rinkeby-v4',
enableHistory: process.env.REACT_APP_ENABLE_HISTORY === 'true',
},
[ChainId.Mainnet]: {
jsonRpcUri: createNetworkHttpUrl('mainnet'),
wsRpcUri: createNetworkWsUrl('mainnet'),
subgraphApiUri: 'https://api.thegraph.com/subgraphs/name/nounsdao/nouns-subgraph',
enableHistory: process.env.REACT_APP_ENABLE_HISTORY === 'true',
},
[ChainId.Hardhat]: {
jsonRpcUri: 'http://localhost:8545',
wsRpcUri: 'ws://localhost:8545',
subgraphApiUri: '',
enableHistory: false,
},
};
const config = {
app: app[CHAIN_ID],
};
export default config;