-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
136 lines (124 loc) · 4.43 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
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { ViteToml } from 'vite-plugin-toml'
import { readFileSync } from 'fs';
import wasm from 'vite-plugin-wasm';
import { EthereumNetworkID } from 'dlc-btc-lib/models';
import { supportedEthereumNetworks } from 'dlc-btc-lib/constants';
const SOLIDITY_CONTRACT_URL = 'https://raw.githubusercontent.com/DLC-link/dlc-solidity';
async function fetchEthereumDeploymentPlans(
appEnvironment: string,
branchName: string,
ethereumNetworkIDs: EthereumNetworkID[],
localDeploymentFilesURL?: string
): Promise<any[]> {
const deploymentPlans = await Promise.all(ethereumNetworkIDs.map(async (ethereumNetworkID) => {
const ethereumNetwork = supportedEthereumNetworks.find(
network => network.id === ethereumNetworkID
);
const networkDeploymentPlans = await Promise.all(['DLCManager', 'IBTC'].map(async (contractName) => {
let deploymentPlanURL: string;
switch (appEnvironment) {
case 'mainnet':
case 'testnet':
case 'devnet':
deploymentPlanURL = `${SOLIDITY_CONTRACT_URL}/${branchName}/deploymentFiles/${ethereumNetwork.name.toLowerCase()}/${contractName}.json`;
break;
case 'localhost':
deploymentPlanURL = `${localDeploymentFilesURL}/contracts/localhost/${contractName}.json`;
break;
default:
throw new Error('Invalid App Environment');
}
try {
const response = await fetch(deploymentPlanURL);
const contractData = await response.json();
return contractData;
} catch (error) {
throw new Error(
`Could not fetch deployment info for ${contractName} on ${ethereumNetwork.name}`
);
}
}));
return { name: ethereumNetwork.name, deploymentPlans: networkDeploymentPlans};
}));
return deploymentPlans;
}
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const environmentName = env.VITE_APP_ENVIRONMENT;
const branchName = env.VITE_ETHEREUM_DEPLOYMENT_BRANCH
const appConfigurationJSON = readFileSync(resolve(__dirname, `./config.${environmentName}.json`), 'utf-8');
const appConfiguration = JSON.parse(appConfigurationJSON);
appConfiguration.ethereumContractInformations = await fetchEthereumDeploymentPlans(environmentName, branchName, appConfiguration.enabledEthereumNetworkIDs);
const arbitrumURLs: string[] = env.VITE_ARBITRUM_OBSERVER_NODE.split(',');
const l1URLs: string[] = env.VITE_L1_OBSERVER_NODE.split(',');
const baseURLs: string[] = env.VITE_BASE_OBSERVER_NODE.split(',');
const avalancheURLs: string[] = env.VITE_AVALANCHE_OBSERVER_NODE.split(',');
const bscURLs: string[] = env.VITE_BSC_OBSERVER_NODE.split(',');
appConfiguration.arbitrumWebsocket = arbitrumURLs[0];
appConfiguration.arbitrumHTTP = arbitrumURLs[1];
appConfiguration.l1Websocket = l1URLs[0];
appConfiguration.l1HTTP = l1URLs[1];
appConfiguration.baseWebsocket = baseURLs[0];
appConfiguration.baseHTTP = baseURLs[1];
appConfiguration.avalancheWebsocket = avalancheURLs[0];
appConfiguration.avalancheHTTP = avalancheURLs[1];
appConfiguration.bscWebsocket = bscURLs[0];
appConfiguration.bscHTTP = bscURLs[1];
appConfiguration.walletConnectProjectID = env.VITE_WALLET_CONNECT_PROJECT_ID;
return {
plugins: [react(), wasm(), ViteToml()],
build: {
target: 'esnext',
},
define: {
appConfiguration,
},
resolve: {
alias: [
{
find: "@store",
replacement: resolve(__dirname, './src/app/store')
},
{
find: "@components",
replacement: resolve(__dirname, './src/app/components')
},
{
find: "@models",
replacement: resolve(__dirname, './src/shared/models')
},
{
find: "@functions",
replacement: resolve(__dirname, './src/app/functions')
},
{
find: "@common",
replacement: resolve(__dirname, './src/app/common')
},
{
find: "@pages",
replacement: resolve(__dirname, './src/app/pages')
},
{
find: "@shared",
replacement: resolve(__dirname, './src/shared')
},
{
find: "@hooks",
replacement: resolve(__dirname, './src/app/hooks')
},
{
find: "@providers",
replacement: resolve(__dirname, './src/app/providers')
},
{
find: "@styles",
replacement: resolve(__dirname, './src/styles')
}]
}
}
})