forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappConfig.ts
More file actions
90 lines (76 loc) · 2.15 KB
/
Copy pathappConfig.ts
File metadata and controls
90 lines (76 loc) · 2.15 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
import { AppSettings, Network } from '../types';
import { NETWORKS } from './constants';
export const DEFAULT_APP_SETTINGS: AppSettings = {
theme: 'dark',
showLineNumbers: true,
autoSave: true,
telemetry: true,
customRpc: {
mainnet: '',
testnet: '',
devnet: ''
},
explorer: 'suiscan'
};
export const normalizeAppSettings = (
settings?: Partial<AppSettings> | null
): AppSettings => ({
...DEFAULT_APP_SETTINGS,
...settings,
customRpc: {
...DEFAULT_APP_SETTINGS.customRpc,
...(settings?.customRpc || {})
}
});
export const resolveRpcUrl = (
network: Network,
settings: Pick<AppSettings, 'customRpc'> = DEFAULT_APP_SETTINGS
) => {
const customUrl =
settings.customRpc[network]?.trim();
return customUrl || NETWORKS[network];
};
const getSuiExplorerHost = (
network: Network,
explorer: AppSettings['explorer']
) => {
if (explorer === 'suivision') {
if (network === 'mainnet') {
return 'https://suivision.xyz';
}
return `https://${network}.suivision.xyz`;
}
if (explorer === 'suiexplorer') {
return 'https://suiexplorer.com';
}
return 'https://suiscan.xyz';
};
const getSuiExplorerQuery = (
network: Network,
explorer: AppSettings['explorer']
) => {
if (explorer === 'suiexplorer') {
return `?network=${network}`;
}
return '';
};
export const getSuiAccountExplorerUrl = (
address: string,
network: Network,
explorer: AppSettings['explorer']
) => {
if (explorer === 'suiscan') {
return `${getSuiExplorerHost(network, explorer)}/${network}/account/${address}`;
}
return `${getSuiExplorerHost(network, explorer)}/address/${address}${getSuiExplorerQuery(network, explorer)}`;
};
export const getSuiTransactionExplorerUrl = (
digest: string,
network: Network,
explorer: AppSettings['explorer']
) => {
if (explorer === 'suiscan') {
return `${getSuiExplorerHost(network, explorer)}/${network}/tx/${digest}`;
}
return `${getSuiExplorerHost(network, explorer)}/txblock/${digest}${getSuiExplorerQuery(network, explorer)}`;
};