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
119 lines (101 loc) · 3.02 KB
/
Copy pathappConfig.ts
File metadata and controls
119 lines (101 loc) · 3.02 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
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
import { AppSettings, Network, NotificationPreferences } from '../types';
import { NETWORKS } from './constants';
export const DEFAULT_NOTIFICATION_PREFERENCES: NotificationPreferences = {
emailDigests: true,
emailSecurityAlerts: true,
inAppActivityAlerts: true,
inAppProductUpdates: false
};
export const DEFAULT_APP_SETTINGS: AppSettings = {
theme: 'dark',
showLineNumbers: true,
autoSave: true,
telemetry: true,
customRpc: {
mainnet: '',
testnet: '',
devnet: '',
localnet: ''
},
explorer: 'suiscan',
evmExplorer: 'family',
stellarExplorer: 'stellarexpert'
};
export const normalizeNotificationPreferences = (
preferences?: Partial<NotificationPreferences> | null
): NotificationPreferences => ({
...DEFAULT_NOTIFICATION_PREFERENCES,
...(preferences || {})
});
export const normalizeAppSettings = (
settings?: Partial<AppSettings> | null
): AppSettings => {
const merged: AppSettings = {
...DEFAULT_APP_SETTINGS,
...settings,
customRpc: {
...DEFAULT_APP_SETTINGS.customRpc,
...(settings?.customRpc || {})
}
};
// Backward-compat: older persisted state only had Sui `explorer`.
if (!settings?.evmExplorer) {
merged.evmExplorer = DEFAULT_APP_SETTINGS.evmExplorer;
}
if (!settings?.stellarExplorer) {
merged.stellarExplorer = DEFAULT_APP_SETTINGS.stellarExplorer;
}
return merged;
};
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)}`;
};