1
1
import { Modal , Spinner } from "react-bootstrap" ;
2
- import init , { MithrilClient } from "@mithril-dev/mithril-client-wasm" ;
2
+ import initMithrilClient , { MithrilClient } from "@mithril-dev/mithril-client-wasm" ;
3
3
import { useEffect , useState } from "react" ;
4
4
import { useSelector } from "react-redux" ;
5
5
import LocalDateTime from "../LocalDateTime" ;
6
+ import { formatProcessDuration , computeAggregatorNetworkFromUrl } from "../../utils" ;
6
7
7
8
export default function VerifyCertificate ( { show, onClose, certificateHash } ) {
8
9
const currentAggregator = useSelector ( ( state ) => state . settings . selectedAggregator ) ;
@@ -11,23 +12,15 @@ export default function VerifyCertificate({ show, onClose, certificateHash }) {
11
12
const [ verificationDuration , setVerificationDuration ] = useState ( null ) ;
12
13
13
14
useEffect ( ( ) => {
14
- let startTime ;
15
15
async function buildClientAndVerifyChain ( ) {
16
16
try {
17
17
const client = await initializeClient ( ) ;
18
18
if ( certificateHash !== null && certificateHash !== undefined ) {
19
- startTime = performance . now ( ) ;
19
+ let startTime = performance . now ( ) ;
20
20
const certificate = await client . get_mithril_certificate ( certificateHash ) ;
21
21
setCertificateData ( certificate ) ;
22
22
await client . verify_certificate_chain ( certificateHash ) ;
23
-
24
- // Process duration
25
- const duration = performance . now ( ) - startTime ;
26
- const minutes = Math . floor ( duration / 60000 ) ;
27
- const seconds = Math . floor ( ( duration % 60000 ) / 1000 ) ;
28
- setVerificationDuration (
29
- minutes > 0 ? `${ minutes } minutes and ${ seconds } seconds` : `${ seconds } seconds` ,
30
- ) ;
23
+ setVerificationDuration ( formatProcessDuration ( startTime ) ) ;
31
24
}
32
25
} catch ( error ) {
33
26
console . error ( "Error:" , error ) ;
@@ -55,16 +48,14 @@ export default function VerifyCertificate({ show, onClose, certificateHash }) {
55
48
} , [ show ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
56
49
57
50
async function initializeClient ( ) {
58
- await init ( ) ;
51
+ await initMithrilClient ( ) ;
59
52
const genesisVerificationKey = await fetchGenesisVerificationKey ( ) ;
60
53
return new MithrilClient ( currentAggregator , genesisVerificationKey ) ;
61
54
}
62
55
63
56
async function fetchGenesisVerificationKey ( ) {
64
57
try {
65
- let network = currentAggregator . match ( / a g g r e g a t o r \. ( .* ?) \. a p i / ) ;
66
- network = network && network [ 1 ] ? network [ 1 ] : null ;
67
-
58
+ const network = computeAggregatorNetworkFromUrl ( currentAggregator ) ;
68
59
const response = await fetch (
69
60
"https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/" +
70
61
network +
@@ -89,10 +80,10 @@ export default function VerifyCertificate({ show, onClose, certificateHash }) {
89
80
displayEventInDOM ( "The certificate chain validation has started..." ) ;
90
81
} else if ( event . type === "CertificateValidated" ) {
91
82
displayEventInDOM (
92
- "A certificate has been validated, hash: " + event . payload . certificate_hash ,
83
+ "A certificate has been validated, hash: <strong> " + event . payload . certificate_hash + "<strong>" ,
93
84
) ;
94
85
} else if ( event . type === "CertificateChainValidated" ) {
95
- displayEventInDOM ( "The certificate chain is valid ✅" ) ;
86
+ displayEventInDOM ( "<strong> The certificate chain is valid ✅<strong> " ) ;
96
87
} else {
97
88
displayEventInDOM ( event ) ;
98
89
}
@@ -115,7 +106,7 @@ export default function VerifyCertificate({ show, onClose, certificateHash }) {
115
106
aria-labelledby = "contained-modal-title-vcenter"
116
107
centered >
117
108
< Modal . Header closeButton >
118
- < Modal . Title > Verify certificate and certificate chain </ Modal . Title >
109
+ < Modal . Title > Verify certificate</ Modal . Title >
119
110
</ Modal . Header >
120
111
< Modal . Body >
121
112
{ certificateData && (
0 commit comments