Skip to content

Commit 32c0a88

Browse files
committed
Clicking on a certificate hash on tx certifier modal open certificate details
1 parent fcaadd2 commit 32c0a88

File tree

2 files changed

+47
-21
lines changed
  • mithril-explorer/src/components

2 files changed

+47
-21
lines changed

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ import ProtocolParameters from "../ProtocolParameters";
1010
import SignerTable from "../SignerTable";
1111
import VerifyCertificateModal from "../VerifyCertificate/VerifyCertificateModal";
1212

13-
export default function CertificateModal(props) {
13+
export default function CertificateModal({
14+
hash,
15+
hideButtons = false,
16+
onHashChange = (hash) => {},
17+
}) {
1418
const [certificate, setCertificate] = useState({});
1519
const [charts, setCharts] = useState({
1620
stakesBreakdown: {},
1721
});
1822
const [showVerifyCertificateModal, setShowVerifyCertificateModal] = useState(false);
1923
const certificateEndpoint = useSelector(
20-
(state) => `${selectedAggregator(state)}/certificate/${props.hash}`,
24+
(state) => `${selectedAggregator(state)}/certificate/${hash}`,
2125
);
2226

2327
useEffect(() => {
24-
if (!props.hash) {
28+
if (!hash) {
2529
return;
2630
}
2731

@@ -37,19 +41,19 @@ export default function CertificateModal(props) {
3741
setCertificate({});
3842
console.error("Fetch certificate error:", error);
3943
});
40-
}, [certificateEndpoint, props.hash]);
44+
}, [certificateEndpoint, hash]);
4145

4246
function showPrevious() {
43-
props.onHashChange(certificate.previous_hash);
47+
onHashChange(certificate.previous_hash);
4448
}
4549

4650
function close() {
47-
props.onHashChange(undefined);
51+
onHashChange(undefined);
4852
}
4953

5054
return (
5155
<Modal
52-
show={props.hash !== undefined}
56+
show={hash !== undefined}
5357
onHide={close}
5458
size="xl"
5559
aria-labelledby="contained-modal-title-vcenter"
@@ -161,28 +165,32 @@ export default function CertificateModal(props) {
161165
)}
162166
</Modal.Body>
163167
<Modal.Footer>
164-
<Button
165-
size="sm"
166-
onClick={() => setShowVerifyCertificateModal(true)}
167-
className="text-break">
168-
Verify certificate
169-
</Button>
168+
{!hideButtons && (
169+
<Button
170+
size="sm"
171+
onClick={() => setShowVerifyCertificateModal(true)}
172+
className="text-break">
173+
Verify certificate
174+
</Button>
175+
)}
170176
{certificate.genesis_signature !== "" ? (
171177
<Badge bg="warning">Genesis</Badge>
172178
) : (
173-
<>
179+
!hideButtons && (
174180
<Button size="sm" onClick={showPrevious} className="text-break">
175181
Previous hash: {certificate.previous_hash}
176182
</Button>
177-
</>
183+
)
178184
)}
179185
<RawJsonButton href={certificateEndpoint} size="sm" />
180186
</Modal.Footer>
181-
<VerifyCertificateModal
182-
show={showVerifyCertificateModal}
183-
onClose={() => setShowVerifyCertificateModal(false)}
184-
certificateHash={certificate.hash}
185-
/>
187+
{!hideButtons && (
188+
<VerifyCertificateModal
189+
show={showVerifyCertificateModal}
190+
onClose={() => setShowVerifyCertificateModal(false)}
191+
certificateHash={certificate.hash}
192+
/>
193+
)}
186194
</Modal>
187195
);
188196
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import TransactionCertificationBreadcrumb from "./TransactionCertificationBreadc
1010
import TransactionCertificationResult from "./TransactionCertificationResult";
1111
import FetchingProofPane from "./FetchingProofPane";
1212
import ValidatingProofPane from "./ValidatingProofPane";
13+
import CertificateModal from "../CertificateModal";
1314

1415
export const validationSteps = {
1516
ready: 1,
@@ -26,6 +27,7 @@ export default function CertifyCardanoTransactionsModal({
2627
const currentAggregator = useSelector((state) => state.settings.selectedAggregator);
2728
const [client, setClient] = useState(undefined);
2829
const [certificate, setCertificate] = useState(undefined);
30+
const [selectedCertificateHash, setSelectedCertificateHash] = useState(undefined);
2931
const [certificateVerifierStep, setCertificateVerifierStep] = useState(
3032
certificateValidationSteps.ready,
3133
);
@@ -140,6 +142,13 @@ export default function CertifyCardanoTransactionsModal({
140142
}
141143
}
142144

145+
function handleCertificateClick(hash) {
146+
// Only allow to open the submodal when the work is done
147+
if (currentStep === validationSteps.done) {
148+
setSelectedCertificateHash(hash);
149+
}
150+
}
151+
143152
function closeIfNotRunning() {
144153
if (currentStep !== validationSteps.done) {
145154
setShowLoadingWarning(true);
@@ -180,7 +189,9 @@ export default function CertifyCardanoTransactionsModal({
180189
)}
181190
</Col>
182191
</Row>
183-
<Row>
192+
{/*Little hack: hide the modal content if the certificate modal is shown so this modal content*/}
193+
{/*never overflow behind the certificate modal.*/}
194+
<Row className={selectedCertificateHash ? "d-none" : ""}>
184195
<Col>
185196
<Tab.Content>
186197
<Tab.Pane eventKey={getTabForStep(validationSteps.fetchingProof)}>
@@ -196,6 +207,7 @@ export default function CertifyCardanoTransactionsModal({
196207
certificate={certificate}
197208
onStepChange={(step) => setCertificateVerifierStep(step)}
198209
onChainValidationError={() => setIsCertificateChainValid(false)}
210+
onCertificateClick={handleCertificateClick}
199211
showCertificateLinks
200212
hideSpinner
201213
/>
@@ -218,6 +230,12 @@ export default function CertifyCardanoTransactionsModal({
218230
)}
219231
</Modal.Body>
220232
<Modal.Footer></Modal.Footer>
233+
234+
<CertificateModal
235+
hash={selectedCertificateHash}
236+
onHashChange={(hash) => setSelectedCertificateHash(hash)}
237+
hideButtons
238+
/>
221239
</Modal>
222240
);
223241
}

0 commit comments

Comments
 (0)