forked from Disciplr-Org/Disciplr-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorer.ts
More file actions
49 lines (42 loc) · 1.75 KB
/
Copy pathexplorer.ts
File metadata and controls
49 lines (42 loc) · 1.75 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
import type { WalletNetwork } from '../context/WalletContext';
import { isValidStellarAddress } from './stellarAddress';
const EXPLORER_BASE = 'https://stellar.expert/explorer'
export const EXPLORER_BASE_URLS: Record<WalletNetwork, string> = {
TESTNET: 'https://stellar.expert/explorer/testnet',
PUBLIC: 'https://stellar.expert/explorer/public',
};
export function explorerBaseUrl(network: WalletNetwork): string {
return EXPLORER_BASE_URLS[network] ?? EXPLORER_BASE_URLS.TESTNET;
}
export function getExplorerTxUrl(txHash: string, network: 'TESTNET' | 'PUBLIC' | null): string {
const segment = network === 'PUBLIC' ? 'public' : 'testnet'
return `${EXPLORER_BASE}/${segment}/tx/${txHash}`
}
export function getExplorerAccountUrl(address: string, network: 'TESTNET' | 'PUBLIC' | null): string {
if (!isValidStellarAddress(address)) return '';
const segment = network === 'PUBLIC' ? 'public' : 'testnet'
return `${EXPLORER_BASE}/${segment}/account/${address}`
}
/**
* Builds a Stellar Expert contract/account explorer URL for the given
* address and network.
*
* Returns an empty string when `address` is falsy so callers can guard
* the link render without additional null checks.
*/
export function contractExplorerUrl(address: string, network: string): string {
if (!address) return '';
const base =
EXPLORER_BASE_URLS[(network as WalletNetwork)] ??
EXPLORER_BASE_URLS.TESTNET;
return `${base}/contract/${address}`;
}
/**
* Human-readable label for the given network string.
* Falls back to "Testnet" for unknown values so the UI is never blank.
*/
export function networkLabel(network: string | null | undefined): string {
if (network === 'PUBLIC') return 'Mainnet';
if (network === 'TESTNET') return 'Testnet';
return 'Testnet';
}