-
Notifications
You must be signed in to change notification settings - Fork 667
Expand file tree
/
Copy pathcluster.ts
More file actions
90 lines (81 loc) · 2.74 KB
/
Copy pathcluster.ts
File metadata and controls
90 lines (81 loc) · 2.74 KB
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
export enum ClusterStatus {
Connected,
Connecting,
Failure,
}
export enum Cluster {
MainnetBeta,
Testnet,
Devnet,
Simd296,
Custom,
}
export const CLUSTERS = [Cluster.MainnetBeta, Cluster.Testnet, Cluster.Devnet, Cluster.Simd296, Cluster.Custom];
export function clusterSlug(cluster: Cluster): string {
switch (cluster) {
case Cluster.MainnetBeta:
return 'mainnet-beta';
case Cluster.Testnet:
return 'testnet';
case Cluster.Devnet:
return 'devnet';
case Cluster.Simd296:
return 'simd296';
case Cluster.Custom:
return 'custom';
}
}
export function clusterName(cluster: Cluster): string {
switch (cluster) {
case Cluster.MainnetBeta:
return 'Mainnet Beta';
case Cluster.Testnet:
return 'Testnet';
case Cluster.Devnet:
return 'Devnet';
case Cluster.Simd296:
return 'SIMD-296';
case Cluster.Custom:
return 'Custom';
}
}
export const MAINNET_BETA_URL = 'https://api.mainnet.solana.com';
export const TESTNET_URL = 'https://api.testnet.solana.com';
export const DEVNET_URL = 'https://api.devnet.solana.com';
export const SIMD296_URL = 'https://simd-0296.surfnet.dev:8899';
export const modifyUrl = (url: string): string => {
if (typeof window !== 'undefined' && window.location.hostname === 'localhost') {
return url;
} else {
return url.replace('api', 'explorer-api');
}
};
export function clusterUrl(cluster: Cluster, customUrl: string): string {
switch (cluster) {
case Cluster.Devnet:
return process.env.NEXT_PUBLIC_DEVNET_RPC_URL ?? modifyUrl(DEVNET_URL);
case Cluster.MainnetBeta:
return process.env.NEXT_PUBLIC_MAINNET_RPC_URL ?? modifyUrl(MAINNET_BETA_URL);
case Cluster.Testnet:
return process.env.NEXT_PUBLIC_TESTNET_RPC_URL ?? modifyUrl(TESTNET_URL);
case Cluster.Simd296:
return process.env.NEXT_PUBLIC_SIMD296_RPC_URL ?? SIMD296_URL;
case Cluster.Custom:
return customUrl;
}
}
export function serverClusterUrl(cluster: Cluster, customUrl: string): string {
switch (cluster) {
case Cluster.Devnet:
return process.env.DEVNET_RPC_URL ?? modifyUrl(DEVNET_URL);
case Cluster.MainnetBeta:
return process.env.MAINNET_RPC_URL ?? modifyUrl(MAINNET_BETA_URL);
case Cluster.Testnet:
return process.env.TESTNET_RPC_URL ?? modifyUrl(TESTNET_URL);
case Cluster.Simd296:
return process.env.SIMD296_RPC_URL ?? SIMD296_URL;
case Cluster.Custom:
return customUrl;
}
}
export const DEFAULT_CLUSTER = Cluster.MainnetBeta;