-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathvite.config.ts
212 lines (200 loc) · 7.45 KB
/
vite.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import dotenv from 'dotenv'
import path from 'path'
import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr'
import { defineConfig } from 'vite'
import { getNetworks } from '@hop-protocol/sdk'
dotenv.config()
const scriptSrc = new Set([
"'self'",
"'unsafe-inline'",
"'unsafe-eval'", // This is needed when using uniswap sdk, imported by hop sdk.
"https://*.googletagmanager.com",
"https://*.google.com",
"https://*.gstatic.com",
"https://*.google-analytics.com",
"https://*.netlify.app",
"resource:",
"blob:"
])
const connectSrc = new Set([
"'self'",
"http://localhost:*",
"ws://localhost:*",
"https://*.google.com",
"https://*.gstatic.com",
"https://*.google-analytics.com",
"https://*.hop.exchange",
"https://*.rpc.hop.exchange",
"https://*.authereum.com",
"https://*.netlify.app",
"wss://*.authereum.com",
"https://gist.githubusercontent.com",
"https://raw.githubusercontent.com",
"https://*.googleusercontent.com",
"https://*.coinbase.com",
"https://*.walletlink.org",
"https://*.walletconnect.org",
"https://*.walletconnect.com",
"https://*.arbitrum.io",
"https://*.optimism.io",
"https://*.base.org",
"https://sokol.poa.network",
"https://rpc.xdaichain.com",
"https://rpc.gnosischain.com",
"https://rpc.gnosis.gateway.fm",
"https://sokol-archive.blockscout.com",
"https://dai.poa.network",
"https://xdai.poanetwork.dev",
"https://xdai-archive.blockscout.com",
"https://xdai.1hive.org",
"https://rpc.ankr.com",
"https://api.thegraph.com",
"https://gateway.thegraph.com",
"https://thegraph.goerli.zkevm.consensys.net",
"wss://rpc.xdaichain.com/wss",
"wss://rpc.gnosischain.com/wss",
"wss://xdai.poanetwork.dev/wss",
"https://rpc-mumbai.maticvigil.com",
"https://rpc-mainnet.maticvigil.com",
"https://mainnet.arbitrum.io",
"https://arb1.arbitrum.io/rpc",
"https://kovan4.arbitrum.io/rpc",
"https://kovan.optimism.io",
"https://mainnet.optimism.io",
"https://polygon-rpc.com",
"https://rpc.public.zkevm-test.net",
"https://matic-testnet-archive-rpc.bwarelabs.com",
"wss://rpc-mainnet.maticvigil.com/ws",
"wss://*.blocknative.com",
"wss://*.walletlink.org",
"wss://*.walletconnect.org",
"wss://*.walletconnect.com",
"wss://*.zksync.io/jsrpc-ws",
"https://*.infura.io",
"https://*.quiknode.pro",
"https://*.tor.us",
"https://*.alchemyapi.io",
"https://zksync2-testnet.zksync.dev",
"https://consensys-zkevm-goerli-prealpha.infura.io",
"https://rpc.goerli.linea.build",
"https://rpc.linea.build",
"https://*.linea.build",
"https://zksync2-mainnet.zksync.io",
"https://1rpc.io",
"https://*.etherscan.io",
"https://api.rollbar.com",
"https://*.coingecko.com",
"https://*.coinpaprika.com",
"https://*.coincodex.com",
"http://127.0.0.1:21325",
"https://api.opensea.io",
"https://social-auth.hop.exchange",
"https://hopprotocol.cloudflareaccess.com",
"https://optimism-fee-refund-api.hop.exchange",
"https://arbitrum-fee-refund-api.hop.exchange",
"https://hop-merkle-rewards-backend.hop.exchange",
"https://meebits.larvalabs.com",
"https://meebits.app",
"https://gateway.pinata.cloud",
"https://hop.mypinata.cloud",
"https://ipfs.io",
"https://gateway.ipfs.io",
"https://media-exp1.licdn.com",
"https://iris-api.circle.com",
"https://iris-api-sandbox.circle.com",
"https://*.polygon.technology"
])
for (const network of getNetworks()) {
for (const chain of Object.values(network.chains)) {
const { publicRpcUrl, fallbackPublicRpcUrls, subgraphUrl } = chain
if (publicRpcUrl) {
connectSrc.add(publicRpcUrl)
}
if (Array.isArray(fallbackPublicRpcUrls)) {
fallbackPublicRpcUrls.forEach((url) => connectSrc.add(url))
}
if (subgraphUrl) {
connectSrc.add(subgraphUrl)
}
}
}
const frameSrc = new Set([
"'self'",
"http://localhost:*",
"https://*.google.com",
"https://*.gstatic.com",
"https://widget.portis.io",
"https://x2.fortmatic.com",
"https://app.tor.us",
"https://verify.walletconnect.com",
"https://verify.walletconnect.org",
"https://connect.trezor.io",
"chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/u2f-comms.html"
])
const cspConfigPolicy = {
"default-src": ["'none'"],
"child-src": ["'self'", "blob:", "https://*.google.com", "https://*.gstatic.com"],
"script-src": Array.from(scriptSrc),
"connect-src": Array.from(connectSrc),
"img-src": ["*", "data:", "blob:"],
"frame-src": Array.from(frameSrc),
"style-src": ["*", "'unsafe-inline'"],
"font-src": ["https://*.gstatic.com"],
"object-src": ["'none'"],
"form-action": ["'none'"],
"manifest-src": ["'self'"],
"base-uri": ["'none'"],
"block-all-mixed-content": [";"]
}
function cspPlugin() {
return {
name: 'vite-plugin-csp',
transformIndexHtml(html) {
// Use the cspConfigPolicy directly to build the CSP string
const cspString = Object.entries(cspConfigPolicy)
.map(([directive, sources]) => {
// Join sources array into a space-separated string
return `${directive} ${sources.join(' ')}`
})
.join('; ')
// Inject CSP meta tag into the head of the HTML document
return html.replace(
'<head>',
`<head><meta http-equiv="Content-Security-Policy" content="${cspString}">`
)
},
}
}
// https://vitejs.dev/config/
export default defineConfig({
base: process.env.PUBLIC_URL ?? '/',
server: {
port: 3000,
},
plugins: [react(), svgr({
svgrOptions: {
icon: true,
},
}), cspPlugin()],
define: {
"process.env.REACT_APP_NETWORK": process.env.REACT_APP_NETWORK ? `"${process.env.REACT_APP_NETWORK}"` : undefined,
"process.env.REACT_APP_WARNING_ROUTES": process.env.REACT_APP_WARNING_ROUTES ? `"${process.env.REACT_APP_WARNING_ROUTES}"` : undefined,
"process.env.REACT_APP_DISABLED_ROUTES": process.env.REACT_APP_DISABLED_ROUTES ? `"${process.env.REACT_APP_DISABLED_ROUTES}"` : undefined,
"process.env.REACT_APP_DISABLED_ROUTES_NO_LIQUIDITY_WARNING_MESSAGE": process.env.REACT_APP_DISABLED_ROUTES_NO_LIQUIDITY_WARNING_MESSAGE ? `"${process.env.REACT_APP_DISABLED_ROUTES_NO_LIQUIDITY_WARNING_MESSAGE}"` : undefined,
"process.env.REACT_APP_BLOCKLIST_ENABLED": process.env.REACT_APP_BLOCKLIST_ENABLED ? `"${process.env.REACT_APP_BLOCKLIST_ENABLED}"` : undefined,
"process.env.REACT_APP_ENABLED_TOKENS": process.env.REACT_APP_ENABLED_TOKENS ? `"${process.env.REACT_APP_ENABLED_TOKENS}"` : undefined,
"process.env.REACT_APP_DEPRECATED_TOKENS": process.env.REACT_APP_DEPRECATED_TOKENS ? `"${process.env.REACT_APP_DEPRECATED_TOKENS}"` : undefined,
"process.env.REACT_APP_DEPRECATED_POOLS": process.env.REACT_APP_DEPRECATED_POOLS? `"${process.env.REACT_APP_DEPRECATED_POOLS}"` : undefined,
"process.env.REACT_APP_ENABLED_CHAINS": process.env.REACT_APP_ENABLED_CHAINS ? `"${process.env.REACT_APP_ENABLED_CHAINS}"` : undefined,
"process.env.REACT_APP_BNC_DAPP_ID": process.env.REACT_APP_BNC_DAPP_ID ? `"${process.env.REACT_APP_BNC_DAPP_ID}"` : undefined,
"process.env.REACT_APP_SHOW_BANNER_MESSAGE": process.env.REACT_APP_SHOW_BANNER_MESSAGE ? `"${process.env.REACT_APP_SHOW_BANNER_MESSAGE}"` : undefined,
"process.env.REACT_APP_GIT_SHA": process.env.REACT_APP_GIT_SHA ? `"${process.env.REACT_APP_GIT_SHA}"` : undefined,
"process.env.REACT_APP_DISABLE_NATIVE_ASSET_TRANSFERS": process.env.REACT_APP_DISABLE_NATIVE_ASSET_TRANSFERS ? `"${process.env.REACT_APP_DISABLE_NATIVE_ASSET_TRANSFERS}"` : undefined
},
resolve: {
alias: {
'src': path.resolve(__dirname, './src')
},
},
})