-
-
Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathuseExplorer.ts
37 lines (31 loc) · 1.04 KB
/
useExplorer.ts
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
import { type Prefix } from '@kodadot1/static'
import { blockExplorerOf, chainPropListOf } from '@/utils/config/chain.config'
export default function () {
const getSubstrateExplorerUrl = (
urlPrefix: string,
hash: string,
prefix: Prefix,
): string => `${blockExplorerOf(prefix)}${urlPrefix}/${hash}`
const getEvmExplorerUrl = (hash: string, prefix: Prefix): string =>
`${blockExplorerOf(prefix)}/tx/${hash}`
const getAccountUrl = (hash: string, prefix: Prefix): string =>
getSubstrateExplorerUrl('account', hash, prefix)
const getTransactionUrl = (hash: string, prefix: Prefix) => {
return execByVm(
{
EVM: () => getEvmExplorerUrl(hash, prefix),
SUB: () => getSubstrateExplorerUrl('extrinsic', hash, prefix),
},
{ vm: chainPropListOf(prefix).vm },
)
}
const getBlockUrl = (blockId: string, prefix: Prefix) => {
const urlPrefix = 'block'
return getSubstrateExplorerUrl(urlPrefix, blockId, prefix)
}
return {
getAccountUrl,
getTransactionUrl,
getBlockUrl,
}
}