Skip to content

Commit 30a959a

Browse files
committed
refactor(explorer): always fetch data once even if paused
Now data will be updated even if the auto refresh is paused if: - at first loading - when the selected aggregator is changed
1 parent b7b53b7 commit 30a959a

File tree

6 files changed

+34
-39
lines changed

6 files changed

+34
-39
lines changed

mithril-explorer/src/components/Artifacts/CardanoDbSnapshotsList/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export default function CardanoDbSnapshotsList(props) {
1818
const updateInterval = useSelector((state) => state.settings.updateInterval);
1919

2020
useEffect(() => {
21-
if (!autoUpdate) {
22-
return;
23-
}
24-
2521
let fetchSnapshots = () => {
2622
fetch(artifactsEndpoint)
2723
.then((response) => response.json())
@@ -35,8 +31,10 @@ export default function CardanoDbSnapshotsList(props) {
3531
// Fetch them once without waiting
3632
fetchSnapshots();
3733

38-
const interval = setInterval(fetchSnapshots, updateInterval);
39-
return () => clearInterval(interval);
34+
if (autoUpdate) {
35+
const interval = setInterval(fetchSnapshots, updateInterval);
36+
return () => clearInterval(interval);
37+
}
4038
}, [artifactsEndpoint, updateInterval, autoUpdate]);
4139

4240
function handleCertificateHashChange(hash) {

mithril-explorer/src/components/Artifacts/CardanoStakeDistributionsList/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export default function CardanoStakeDistributionsList(props) {
1717
const updateInterval = useSelector((state) => state.settings.updateInterval);
1818

1919
useEffect(() => {
20-
if (!autoUpdate) {
21-
return;
22-
}
23-
2420
let fetchCardanoStakeDistribution = () => {
2521
fetch(artifactsEndpoint)
2622
.then((response) => response.json())
@@ -34,8 +30,10 @@ export default function CardanoStakeDistributionsList(props) {
3430
// Fetch them once without waiting
3531
fetchCardanoStakeDistribution();
3632

37-
const interval = setInterval(fetchCardanoStakeDistribution, updateInterval);
38-
return () => clearInterval(interval);
33+
if (autoUpdate) {
34+
const interval = setInterval(fetchCardanoStakeDistribution, updateInterval);
35+
return () => clearInterval(interval);
36+
}
3937
}, [artifactsEndpoint, updateInterval, autoUpdate]);
4038

4139
function handleCertificateHashChange(hash) {

mithril-explorer/src/components/Artifacts/CardanoTransactionsSnapshotsList/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export default function CardanoTransactionsSnapshotsList(props) {
2525
);
2626

2727
useEffect(() => {
28-
if (!autoUpdate) {
29-
return;
30-
}
31-
3228
let fetchSnapshots = () => {
3329
fetch(artifactsEndpoint)
3430
.then((response) => response.json())
@@ -42,8 +38,10 @@ export default function CardanoTransactionsSnapshotsList(props) {
4238
// Fetch them once without waiting
4339
fetchSnapshots();
4440

45-
const interval = setInterval(fetchSnapshots, updateInterval);
46-
return () => clearInterval(interval);
41+
if (autoUpdate) {
42+
const interval = setInterval(fetchSnapshots, updateInterval);
43+
return () => clearInterval(interval);
44+
}
4745
}, [artifactsEndpoint, updateInterval, autoUpdate]);
4846

4947
function handleCertificateHashChange(hash) {

mithril-explorer/src/components/Artifacts/CertificatesList/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ export default function CertificatesList(props) {
1616
const updateInterval = useSelector((state) => state.settings.updateInterval);
1717

1818
useEffect(() => {
19-
if (!autoUpdate) {
20-
return;
21-
}
22-
2319
let fetchCertificates = () => {
2420
fetch(certificatesEndpoint)
2521
.then((response) => response.json())
@@ -33,8 +29,10 @@ export default function CertificatesList(props) {
3329
// Fetch them once without waiting
3430
fetchCertificates();
3531

36-
const interval = setInterval(fetchCertificates, updateInterval);
37-
return () => clearInterval(interval);
32+
if (autoUpdate) {
33+
const interval = setInterval(fetchCertificates, updateInterval);
34+
return () => clearInterval(interval);
35+
}
3836
}, [certificatesEndpoint, updateInterval, autoUpdate]);
3937

4038
function handleCertificateHashChange(hash) {

mithril-explorer/src/components/Artifacts/MithrilStakeDistributionsList/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export default function MithrilStakeDistributionsList(props) {
1717
const updateInterval = useSelector((state) => state.settings.updateInterval);
1818

1919
useEffect(() => {
20-
if (!autoUpdate) {
21-
return;
22-
}
23-
2420
let fetchMithrilStakeDistribution = () => {
2521
fetch(artifactsEndpoint)
2622
.then((response) => response.json())
@@ -34,8 +30,10 @@ export default function MithrilStakeDistributionsList(props) {
3430
// Fetch them once without waiting
3531
fetchMithrilStakeDistribution();
3632

37-
const interval = setInterval(fetchMithrilStakeDistribution, updateInterval);
38-
return () => clearInterval(interval);
33+
if (autoUpdate) {
34+
const interval = setInterval(fetchMithrilStakeDistribution, updateInterval);
35+
return () => clearInterval(interval);
36+
}
3937
}, [artifactsEndpoint, updateInterval, autoUpdate]);
4038

4139
function handleCertificateHashChange(hash) {

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from "react";
2-
import {Card, Row, Col, Stack, Container} from "react-bootstrap";
2+
import { Card, Row, Col, Stack, Container } from "react-bootstrap";
33
import { useSelector } from "react-redux";
44
import LinkButton from "#/LinkButton";
55
import RawJsonButton from "#/RawJsonButton";
@@ -19,10 +19,6 @@ export default function EpochSettings() {
1919
const [inOutRegistrationsPageUrl, setInOutRegistrationsPageUrl] = useState(undefined);
2020

2121
useEffect(() => {
22-
if (!autoUpdate) {
23-
return;
24-
}
25-
2622
let fetchEpochSettings = () => {
2723
fetch(epochSettingsEndpoint)
2824
.then((response) => (response.status === 200 ? response.json() : {}))
@@ -36,8 +32,10 @@ export default function EpochSettings() {
3632
// Fetch it once without waiting
3733
fetchEpochSettings();
3834

39-
const interval = setInterval(fetchEpochSettings, updateInterval);
40-
return () => clearInterval(interval);
35+
if (autoUpdate) {
36+
const interval = setInterval(fetchEpochSettings, updateInterval);
37+
return () => clearInterval(interval);
38+
}
4139
}, [epochSettingsEndpoint, updateInterval, autoUpdate]);
4240

4341
useEffect(() => {
@@ -74,14 +72,21 @@ export default function EpochSettings() {
7472
</Col>
7573
<Col xs={12} md="auto">
7674
<h5>Registration Protocol Parameters</h5>
77-
<ProtocolParameters protocolParameters={epochSettings.signer_registration_protocol ?? epochSettings.next_protocol}/>
75+
<ProtocolParameters
76+
protocolParameters={
77+
epochSettings.signer_registration_protocol ?? epochSettings.next_protocol
78+
}
79+
/>
7880
</Col>
7981
</Row>
8082
</Container>
8183
</Card.Body>
8284
{registrationPageUrl && inOutRegistrationsPageUrl && (
8385
<Card.Footer>
84-
<Stack direction="horizontal" gap={1} className="justify-content-md-end align-items-stretch justify-content-sm-center">
86+
<Stack
87+
direction="horizontal"
88+
gap={1}
89+
className="justify-content-md-end align-items-stretch justify-content-sm-center">
8590
<LinkButton href={registrationPageUrl}>
8691
<i className="bi bi-pen"></i> Registered Signers
8792
</LinkButton>

0 commit comments

Comments
 (0)