-
Notifications
You must be signed in to change notification settings - Fork 42
/
environment.ts
374 lines (330 loc) · 9.95 KB
/
environment.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import type { ConfigQuery, ConfigQueryVariables } from 'graphql'
import request, { gql } from 'graphql-request'
import { LRUCache } from 'lru-cache'
import { createContext } from 'react'
import invariant from 'ts-invariant'
import {
Chain,
arbitrum,
arbitrumSepolia,
base,
baseSepolia,
bsc,
bscTestnet,
mainnet as ethereumMainnet,
sepolia as ethereumSepolia,
neonDevnet,
neonMainnet,
polygon,
} from 'wagmi/chains'
type RemoteConfig = {
name: string
hasLazyMint: boolean
maxRoyaltiesPerTenThousand: number
offerValiditySeconds: number
metadata: Partial<{
REPORT_EMAIL: string
LOGO: string
FAVICON: string
BRAND_COLOR: string
HOME_BANNERS: {
image: string
title?: string
content?: string
textColor: string
button?: {
text: string
href: string
isExternal?: boolean
}
}[]
FEATURED_TOKEN: string[]
HOME_COLLECTIONS: string[]
HOME_USERS: string[]
HOME_TOKENS: string[]
META_TITLE: string
META_KEYWORDS: string
META_DESCRIPTION: string
META_COMPANY_NAME: string
}>
}
export type Environment = {
/**
* Base configuration
*/
// API Key for the Liteflow API, you can get one at https://dashboard.liteflow.com/developer
LITEFLOW_API_KEY: string
// Email address for end users to send reports to
REPORT_EMAIL: string
// Number of items per page
PAGINATION_LIMIT: number
// Default value for the number of seconds an offer is valid (users can override this) (recommendation: 28 days)
OFFER_VALIDITY_IN_SECONDS: number
// Base URL of the website
BASE_URL: string
// Maximum percentage of royalties
MAX_ROYALTIES: number
// (Optional) Bugsnag API Key, you can get one at https://www.bugsnag.com/
BUGSNAG_API_KEY?: string
/**
* Theme configuration
*/
// URL of the logo to place in the header
LOGO: string
// URL of the favicon
FAVICON: string
// Brand color to use for the theme
BRAND_COLOR: string
/**
* Wallet/chain configuration
*/
// List of supported chains. Liteflow is supporting the following: ethereumMainnet, ethereumSepolia, bscTestnet, bsc, polygon, polygonAmoy, neonMainnet, neonDevnet, arbitrum, arbitrumSepolia, lightlinkPhoenix, lightlinkPegasus, base, baseSepolia
CHAINS: Chain[]
// Wallet connect project ID, you can get one at https://cloud.walletconnect.com/
WALLET_CONNECT_PROJECT_ID: string
// (Optional) Magic API Key, you can get one at https://magic.link/
MAGIC_API_KEY?: string
// (Optional) Alchemy API key to activate fallback if public providers are not responsive
ALCHEMY_API_KEY?: string
/**
* Home page configuration
*/
// List of banners to be displayed on the homepage
HOME_BANNERS: {
// URL of the image to display
image: string
// (Optional) Title of the banner
title?: string
// (Optional) Content of the banner
content?: string
// Text color of the banner. Default is white
textColor: string
// (Optional) Button to display on the banner
button?: {
// Text of the button
text: string
// URL to redirect to when the button is clicked
href: string
// (Optional) Whether the URL is external or not (default: false)
isExternal?: boolean
}
}[]
// Ordered list of tokens to be highlighted on the homepage with the following format: [chainId]-[contractAddress]-[tokenId]
FEATURED_TOKEN: string[]
// Ordered list of collections to be featured on the homepage with the following format: [chainId]-[contractAddress]
HOME_COLLECTIONS: string[]
// Ordered list of users to be featured on the homepage with the following format: [address]
HOME_USERS: string[]
// List of tokens randomized to be featured on the homepage with the following format: [chainId]-[contractAddress]-[tokenId]
// If empty, the tokens will be the last created ones
HOME_TOKENS: string[]
/**
* SEO Configuration
*/
// Name of the company to place in the SEO title and in the footer
META_COMPANY_NAME: string
// Title of the marketplace to place in the SEO title
META_TITLE: string
// Description of the marketplace to place in the SEO description
META_DESCRIPTION: string
// Keywords of the marketplace to place in the SEO keywords
META_KEYWORDS: string
/**
* NFT Mint Behavior
*/
// Enable/disable the lazy minting feature. If enabled, the NFTs will be minted on the first sale
LAZYMINT: boolean
}
const cache = new LRUCache({
max: 100,
ttl:
typeof window === 'undefined'
? 1000 * 10 // 10 sec
: 0, // no ttl, user need to refresh the page
fetchMethod: async (key: string) => {
invariant(key === 'config', 'Invalid key')
const { config } = await request<ConfigQuery, ConfigQueryVariables>(
`${
process.env.NEXT_PUBLIC_LITEFLOW_BASE_URL || 'https://api.liteflow.com'
}/${process.env.NEXT_PUBLIC_LITEFLOW_API_KEY}/graphql`,
gql`
query Config {
config {
name
hasLazyMint
maxRoyaltiesPerTenThousand
offerValiditySeconds
metadata
}
}
`,
undefined,
[['origin', process.env.NEXT_PUBLIC_BASE_URL || '']],
)
return config satisfies RemoteConfig
},
})
export const EnvironmentContext = createContext<Environment>({} as Environment)
const getEnvironment = async (): Promise<Environment> => {
invariant(process.env.NEXT_PUBLIC_BASE_URL, 'Base url is not defined')
invariant(process.env.NEXT_PUBLIC_LITEFLOW_API_KEY, 'API key is not defined')
invariant(
process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID,
'Wallet connect project id is not defined',
)
const config = await cache.fetch('config')
invariant(config, 'Config is not defined')
const {
name,
hasLazyMint,
maxRoyaltiesPerTenThousand,
offerValiditySeconds,
metadata,
} = config
return {
// Base configuration
LITEFLOW_API_KEY: process.env.NEXT_PUBLIC_LITEFLOW_API_KEY,
REPORT_EMAIL: metadata.REPORT_EMAIL || '',
PAGINATION_LIMIT: 12,
OFFER_VALIDITY_IN_SECONDS: offerValiditySeconds,
BASE_URL: process.env.NEXT_PUBLIC_BASE_URL,
MAX_ROYALTIES: maxRoyaltiesPerTenThousand / 100,
BUGSNAG_API_KEY: process.env.NEXT_PUBLIC_BUGSNAG_API_KEY,
// Theme configuration
LOGO: metadata.LOGO || '/logo.svg',
FAVICON: metadata.FAVICON || '/favicon.svg',
BRAND_COLOR: metadata.BRAND_COLOR || '#245BFF',
// Wallet/chain configuration
CHAINS: [
ethereumMainnet,
ethereumSepolia,
bscTestnet,
bsc,
polygon,
{
id: 80_002,
name: 'Polygon Amoy',
network: 'polygon-amoy',
nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
rpcUrls: {
alchemy: {
http: ['https://polygon-amoy.g.alchemy.com/v2'],
webSocket: ['wss://polygon-amoy.g.alchemy.com/v2'],
},
default: {
http: ['https://rpc-amoy.polygon.technology'],
},
public: {
http: ['https://rpc-amoy.polygon.technology'],
},
},
blockExplorers: {
etherscan: {
name: 'Etherscan',
url: 'https://amoy.polygonscan.com',
},
default: {
name: 'Etherscan',
url: 'https://amoy.polygonscan.com',
},
},
contracts: {
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 3127388,
},
},
testnet: true,
},
{
...neonMainnet,
blockExplorers: {
default: {
name: 'Blockscout',
url: 'https://neon.blockscout.com',
},
},
},
{
...neonDevnet,
blockExplorers: {
default: {
name: 'Blockscout',
url: 'https://neon-devnet.blockscout.com',
},
},
},
arbitrum,
arbitrumSepolia,
{
name: 'Lightlink Phoenix Mainnet',
network: 'lightlink-phoenix',
id: 1890,
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['https://replicator.phoenix.lightlink.io/rpc/v1'],
},
public: {
http: ['https://replicator.phoenix.lightlink.io/rpc/v1'],
},
},
blockExplorers: {
default: {
name: 'LightLink Phoenix Explorer',
url: 'https://phoenix.lightlink.io',
},
},
},
{
name: 'Lightlink Pegasus Testnet',
network: 'lightlink-pegasus',
testnet: true,
id: 1891,
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['https://replicator.pegasus.lightlink.io/rpc/v1'],
},
public: {
http: ['https://replicator.pegasus.lightlink.io/rpc/v1'],
},
},
blockExplorers: {
default: {
name: 'LightLink Pegasus Explorer',
url: 'https://pegasus.lightlink.io',
},
},
},
base,
baseSepolia,
],
WALLET_CONNECT_PROJECT_ID:
process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID,
MAGIC_API_KEY: process.env.NEXT_PUBLIC_MAGIC_API_KEY,
ALCHEMY_API_KEY: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
// Home page configuration
HOME_BANNERS: metadata.HOME_BANNERS || [],
FEATURED_TOKEN: metadata.FEATURED_TOKEN || [],
HOME_COLLECTIONS: metadata.HOME_COLLECTIONS || [],
HOME_USERS: metadata.HOME_USERS || [],
HOME_TOKENS: metadata.HOME_TOKENS || [],
// SEO Configuration
META_COMPANY_NAME: name,
META_TITLE: metadata.META_TITLE || name,
META_DESCRIPTION: metadata.META_DESCRIPTION || name,
META_KEYWORDS: metadata.META_KEYWORDS || name,
// NFT Mint Behavior
LAZYMINT: hasLazyMint,
}
}
export default getEnvironment