-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathhome.quicklinks.ts
More file actions
388 lines (350 loc) · 10.5 KB
/
Copy pathhome.quicklinks.ts
File metadata and controls
388 lines (350 loc) · 10.5 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
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/**
* @docs Home Quicklinks Helper
*
* Central place for pool-related mapping used by the Home page.
*
* Responsibilities:
* - Normalize stratum URLs and extract hostnames
* - Generate pool-specific dashboard/statistics URLs (quick links)
* - Detect pool capabilities (e.g. ICMP ping support)
* - Resolve pool icons with the following priority:
*
* 1) Manual icon override (PoolMeta.iconUrl)
* 2) Custom favicon path (PoolMeta.faviconPath + faviconHost)
* 3) Default favicon fallback: https://<host>/favicon.ico
*
* Additionally:
* - Local pools (private IP/localhost/.local) are handled via registry rule
* and return DEFAULT_POOL_ICON_URL to avoid broken favicons.
*
* Notes:
* - No external favicon services are used
* - No network existence checks are performed
* - Order matters: first matching pool wins
*/
export type PoolCapabilities = {
/** ICMP ping is supported/sensible */
ping?: boolean;
};
export const DEFAULT_POOL_ICON_URL = 'assets/pools/default.svg';
export const DEFAULT_EXTERNAL_POOL_ICON_URL = 'assets/pools/public.svg';
export type PoolMeta = {
id: string;
name: string;
/** Match against normalized hostname (lowercased, no port) */
match: (host: string, raw: string) => boolean;
/** Optional pool dashboard / stats URL builder */
quickLink?: (address: string) => string;
/** Optional pool capabilities */
caps?: PoolCapabilities;
/**
* Optional hostname override used for favicon resolution.
* Example: pool UI on parasite.space, favicon on parasite.wtf
*/
faviconHost?: string;
/**
* Optional custom favicon path.
* Allows svg/png or nested paths.
*
* Examples:
* - '/favicon.svg'
* - '/assets/favicon.png'
* - '/img/logo.svg'
*/
faviconPath?: string;
/**
* Optional manual icon override.
* Can be a local asset path or absolute URL.
* Takes highest priority.
*/
iconUrl?: string;
};
/* ------------------------------------------------------------------
* URL / host helpers
* ------------------------------------------------------------------ */
/**
* Ensures the input can be parsed by the `URL` constructor.
* If no scheme is present, `http://` is prepended.
*/
function toUrlLike(raw: string): string {
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(raw)) {
return raw;
}
return `http://${raw}`;
}
/**
* Extracts a normalized hostname from a stratum URL.
*
* Supports:
* - stratum+tcp://host:port
* - host:port
* - host
*/
function extractHost(stratumURL: string): string {
try {
return new URL(toUrlLike(stratumURL)).hostname.toLowerCase();
} catch {
return (stratumURL ?? '').toLowerCase();
}
}
/**
* Local host heuristics for pools running on the local network.
* For these endpoints, a favicon usually does not exist (no web server),
* and HTTPS is often not available. We use a local default icon instead.
*/
function isIp(host: string): boolean {
return /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
}
function isPrivateIp(host: string): boolean {
if (!isIp(host)) return false;
const [a, b] = host.split('.').map((n) => parseInt(n, 10));
if (a === 10) return true;
if (a === 192 && b === 168) return true;
if (a === 172 && b >= 16 && b <= 31) return true;
return false;
}
/**
* Detects localhost / private network endpoints.
*
* Includes:
* - localhost
* - 127.0.0.1
* - ::1 (IPv6 localhost)
* - *.local
* - private IPv4 ranges
*/
export function isLocalHost(host: string): boolean {
const h = (host ?? '').toLowerCase();
// IPv6 localhost
if (h === '::1') return true;
// classic localhost
if (h === 'localhost') return true;
// mDNS / local domains
if (h.endsWith('.local')) return true;
// IPv4 localhost
if (h === '127.0.0.1') return true;
// private IPv4 ranges
if (isPrivateIp(h)) return true;
return false;
}
/* ------------------------------------------------------------------
* Pool registry (first match wins)
* ------------------------------------------------------------------ */
const POOLS: PoolMeta[] = [
/**
* Local pool rule (must be FIRST).
* Ensures local endpoints do not try to load https://<ip>/favicon.ico
* and instead use the default icon.
*
* Example -> Parasite pool:
* - UI: parasite.space
* - Icon may be hosted elsewhere or have custom path
*
* If you ever need a custom path or different domain:
* - set faviconHost + faviconPath
*
* Example:
* faviconHost: 'parasite.wtf',
* faviconPath: '/favicon.svg',
*/
{
// Prefer Umbrel over other local pools.
id: 'umbrel-local',
name: 'Umbrel',
match: (h) => h === 'umbrel.local',
iconUrl: 'assets/pools/umbrel.svg',
},
{
id: 'local-pool',
name: 'Local pool',
match: (h) => isLocalHost(h),
iconUrl: DEFAULT_POOL_ICON_URL,
},
{
id: 'public-pool',
name: 'public-pool.io',
match: (h) => h.includes('public-pool.io'),
quickLink: (a) => `https://web.public-pool.io/#/app/${a}`,
iconUrl: 'assets/pools/public-pool.png',
caps: { ping: false },
},
{
id: 'ocean',
name: 'ocean.xyz',
match: (h) => h.includes('ocean.xyz'),
quickLink: (a) => `https://ocean.xyz/stats/${a}`,
},
// CKPool variants
{
id: 'ckpool-eusolo',
name: 'eusolo*.ckpool.org',
match: (h) => /^eusolo[46]?\.(ckpool\.org)$/.test(h),
quickLink: (a) => `https://eusolostats.ckpool.org/users/${a}`,
iconUrl: '/assets/pools/ck-eupool.svg',
},
{
id: 'ckpool-solo',
name: 'solo*.ckpool.org',
match: (h) => /^solo[46]?\.(ckpool\.org)$/.test(h),
quickLink: (a) => `https://solostats.ckpool.org/users/${a}`,
iconUrl: '/assets/pools/ck-pool.svg',
},
{
id: 'ckpool-ausolo',
name: 'ausolo*.ckpool.org',
match: (h) => /^ausolo[46]?\.(ckpool\.org)$/.test(h),
quickLink: (a) => `https://ausolostats.ckpool.org/users/${a}`,
iconUrl: '/assets/pools/ck-aupool.svg',
},
{
id: 'noderunners',
name: 'pool.noderunners.network',
match: (h) => h.includes('pool.noderunners.network'),
quickLink: (a) => `https://noderunners.network/en/pool/user/${a}`,
faviconHost: 'noderunners.network',
},
{
id: 'satoshiradio',
name: 'satoshiradio.nl',
match: (h) => h.includes('satoshiradio.nl'),
quickLink: (a) => `https://pool.satoshiradio.nl/user/${a}`,
faviconHost: 'satoshiradio.nl',
faviconPath: '/assets/SR_Logo_Orange.webp',
},
{
id: 'solohash',
name: 'solohash.co.uk',
match: (h) => h.includes('solohash.co.uk'),
quickLink: (a) => `https://solohash.co.uk/user/${a}`,
faviconHost: 'solohash.co.uk',
faviconPath: '/icons/favicon.ico',
},
{
id: 'parasite',
name: 'parasite',
match: (h) => h.includes('parasite.space') || h.includes('parasite.wtf'),
quickLink: (a) => `https://parasite.space/user/${a}`,
faviconHost: 'parasite.space',
faviconPath: '/favicon.ico',
},
{
id: 'solomining-de',
name: 'solomining.de',
match: (h) => h.includes('solomining.de'),
quickLink: (a) => `https://pool.solomining.de/#/app/${a}`,
},
{
id: 'atlaspool',
name: 'atlaspool.io',
match: (h) => h.includes('atlaspool.io'),
quickLink: (a) => `https://atlaspool.io/dashboard.html?wallet=${a}`,
faviconHost: 'atlaspool.io',
faviconPath: '/favicon.ico',
},
{
id: 'powermining',
name: 'powermining.io',
match: (h) => h.includes('powermining.io'),
quickLink: (a) => `https://pool.powermining.io/#/app/${a}`,
},
{
id: 'blitzpool',
name: 'blitzpool.yourdevice.ch',
match: (h) => h.includes('blitzpool.yourdevice.ch'),
quickLink: (a) => `https://blitzpool.yourdevice.ch/#/app/${a}`,
},
{
id: 'braiins-solo',
name: 'Braiins Solo',
match: (h) => h.includes('solo.stratum.braiins.com'),
quickLink: (a) => `https://solo.braiins.com/stats/${a}`,
faviconHost: 'solo.braiins.com',
faviconPath: '/icon.png'
},
{
id: 'mining-dutch',
name: 'mining-dutch.nl',
// stratum host is a regional subdomain (e.g. europe.mining-dutch.nl);
// account-based pool, so link to the main site instead of the wallet
match: (h) => h.includes('mining-dutch.nl'),
quickLink: () => `https://www.mining-dutch.nl`,
faviconHost: 'www.mining-dutch.nl',
}
];
/* ------------------------------------------------------------------
* Public API
* ------------------------------------------------------------------ */
/**
* Detects pool metadata for a given stratum endpoint.
*
* @param stratumURL Stratum pool URL or host
*/
export function detectPoolMeta(stratumURL: string): PoolMeta | undefined {
const raw = stratumURL ?? '';
const host = extractHost(raw);
return POOLS.find((p) => p.match(host, raw));
}
/**
* Builds a pool-specific dashboard / statistics URL.
*
* @param stratumURL Stratum pool URL or host
* @param stratumUser Stratum user string (wallet[.worker])
*/
export function getQuickLink(
stratumURL: string,
stratumUser: string
): string | undefined {
const safeUrl = stratumURL ?? '';
const safeUser = stratumUser ?? '';
if (!safeUrl.trim() && !safeUser.trim()) {
return undefined;
}
const address = safeUser.split('.', 1)[0] || '';
const pool = detectPoolMeta(safeUrl);
if (pool?.quickLink) {
return pool.quickLink(address);
}
return safeUrl.startsWith('http') ? safeUrl : toUrlLike(safeUrl);
}
/**
* Indicates whether the given pool supports ICMP ping.
*
* @param stratumURL Stratum pool URL or host
*/
export function supportsPing(stratumURL: string): boolean {
const pool = detectPoolMeta(stratumURL ?? '');
return pool?.caps?.ping ?? true;
}
/**
* Resolves a pool icon URL.
*
* Priority:
* 1) Manual icon override (PoolMeta.iconUrl)
* 2) Custom favicon path (PoolMeta.faviconPath + faviconHost)
* 3) Default favicon.ico at https://<host>/favicon.ico
*
* Local pools are handled by a registry rule which sets iconUrl to DEFAULT_POOL_ICON_URL.
*
* @param stratumURL Stratum pool URL or host
* @returns Icon URL (may be DEFAULT_POOL_ICON_URL)
*/
export function getPoolIconUrl(stratumURL: string): string {
const safeUrl = stratumURL ?? '';
const pool = detectPoolMeta(safeUrl);
// 1) Manual icon override (including local-pool rule)
if (pool?.iconUrl?.trim()) {
return pool.iconUrl.trim();
}
const host = extractHost(safeUrl);
const faviconHost = (pool?.faviconHost ?? host).trim();
// If we cannot derive a host, fall back to a local default icon
if (!faviconHost) {
return DEFAULT_POOL_ICON_URL;
}
// 2) Custom favicon path (svg/png/etc.)
if (pool?.faviconPath?.trim()) {
return `https://${faviconHost}${pool.faviconPath.trim()}`;
}
// 3) Default favicon.ico
return `https://${faviconHost}/favicon.ico`;
}