Skip to content

Commit fcaadd2

Browse files
committed
Make certificate hashes of the explorer chain verifier clickable
The raised event is then transmit to the parent via a callback.
1 parent a22e4ca commit fcaadd2

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

mithril-explorer/src/components/CertifyCardanoTransactionsModal/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ export default function CertifyCardanoTransactionsModal({
194194
<CertificateVerifier
195195
client={client}
196196
certificate={certificate}
197-
showSpinner={false}
198197
onStepChange={(step) => setCertificateVerifierStep(step)}
199198
onChainValidationError={() => setIsCertificateChainValid(false)}
199+
showCertificateLinks
200+
hideSpinner
200201
/>
201202
)}
202203
</Tab.Pane>

mithril-explorer/src/components/VerifyCertificate/CertificateVerifier.js

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
22
import { Spinner, Table } from "react-bootstrap";
33
import { formatProcessDuration } from "../../utils";
44
import CopyableHash from "../CopyableHash";
5+
import CopyButton from "../CopyButton";
56
import IconBadge from "../IconBadge";
67
import LocalDateTime from "../LocalDateTime";
78

@@ -28,12 +29,32 @@ const eventPosition = {
2829
afterTable: 3,
2930
};
3031

32+
function CertificateHash({ hash, onClick, showLink, linkVariant = "dark" }) {
33+
function clicked(event) {
34+
event.preventDefault();
35+
onClick(hash);
36+
}
37+
38+
return showLink ? (
39+
<>
40+
<a href="#" target="_blank" className={`link-${linkVariant}`} onClick={clicked}>
41+
{hash}
42+
</a>{" "}
43+
<CopyButton textToCopy={hash} />
44+
</>
45+
) : (
46+
<CopyableHash hash={hash} />
47+
);
48+
}
49+
3150
export default function CertificateVerifier({
3251
client,
3352
certificate,
34-
showSpinner = true,
53+
hideSpinner = false,
54+
showCertificateLinks = false,
3555
onStepChange = (step) => {},
3656
onChainValidationError = (error) => {},
57+
onCertificateClick = (hash) => {},
3758
}) {
3859
const [currentStep, setCurrentStep] = useState(certificateValidationSteps.ready);
3960
const [validationError, setValidationError] = useState(undefined);
@@ -99,16 +120,7 @@ export default function CertificateVerifier({
99120
break;
100121
case certificateChainValidationEvents.certificateValidated:
101122
position = eventPosition.inTable;
102-
message = (
103-
<>
104-
<td>
105-
<CopyableHash hash={event.payload.certificate_hash} />
106-
</td>
107-
<td>
108-
<IconBadge tooltip="Valid Certificate" variant="success" icon="mithril" />
109-
</td>
110-
</>
111-
);
123+
message = { certificateHash: event.payload.certificate_hash };
112124
break;
113125
case certificateChainValidationEvents.done:
114126
message = (
@@ -133,7 +145,15 @@ export default function CertificateVerifier({
133145
{Object.entries(certificate).length > 0 && (
134146
<div>
135147
<h4>Certificate Details</h4>
136-
<div>Certificate hash: {certificate.hash}</div>
148+
<div>
149+
Certificate hash:{" "}
150+
<CertificateHash
151+
hash={certificate.hash}
152+
onClick={() => onCertificateClick(certificate.hash)}
153+
showLink={showCertificateLinks}
154+
linkVariant="primary"
155+
/>
156+
</div>
137157
<div>Epoch: {certificate.beacon.epoch}</div>
138158
<div className="d-flex justify-content-between">
139159
<div>
@@ -142,7 +162,7 @@ export default function CertificateVerifier({
142162
{currentStep === certificateValidationSteps.validationInProgress && (
143163
<div className="d-flex align-items-center">
144164
<div className="ms-1 pe-1">Verifying the certificate chain...</div>
145-
{showSpinner && <Spinner animation="border" variant="primary" />}
165+
{!hideSpinner && <Spinner animation="border" variant="primary" />}
146166
</div>
147167
)}
148168
{currentStep === certificateValidationSteps.done && (
@@ -170,7 +190,18 @@ export default function CertificateVerifier({
170190
{verificationEvents
171191
.filter((evt) => evt.position === eventPosition.inTable)
172192
.map((evt) => (
173-
<tr key={evt.id}>{evt.message}</tr>
193+
<tr key={evt.id}>
194+
<td>
195+
<CertificateHash
196+
hash={evt.message.certificateHash}
197+
onClick={() => onCertificateClick(evt.message.certificateHash)}
198+
showLink={showCertificateLinks}
199+
/>
200+
</td>
201+
<td>
202+
<IconBadge tooltip="Valid Certificate" variant="success" icon="mithril" />
203+
</td>
204+
</tr>
174205
))}
175206
</tbody>
176207
</Table>

0 commit comments

Comments
 (0)