Skip to content

Commit 815b5a6

Browse files
committed
Add EpochSettings card to explorer
1 parent cc1f630 commit 815b5a6

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { useEffect, useState } from 'react';
2+
import {Card, ListGroup} from "react-bootstrap";
3+
import RawJsonButton from "../RawJsonButton";
4+
5+
export default function EpochSettings(props) {
6+
const [epochSettings, setEpochSettings] = useState({});
7+
8+
useEffect(() => {
9+
if (!props.autoUpdate) {
10+
return;
11+
}
12+
13+
let fetchEpochSettings = () => {
14+
fetch(`${props.aggregator}/epoch-settings`)
15+
.then(response => response.status === 200 ? response.json() : {})
16+
.then(data => setEpochSettings(data))
17+
.catch(error => {
18+
setEpochSettings({});
19+
console.error("Fetch epoch-settings error:", error);
20+
});
21+
};
22+
23+
// Fetch it once without waiting
24+
fetchEpochSettings();
25+
26+
const interval = setInterval(fetchEpochSettings, props.updateInterval);
27+
return () => clearInterval(interval);
28+
}, [props.aggregator, props.updateInterval, props.autoUpdate]);
29+
30+
return (
31+
<div>
32+
<h2>
33+
Epoch Settings
34+
<RawJsonButton href={`${props.aggregator}/epoch-settings`} variant="outline-light" size="sm" />
35+
</h2>
36+
37+
<Card>
38+
<Card.Body>
39+
<Card.Title>Current Epoch</Card.Title>
40+
<ListGroup variant="flush">
41+
<ListGroup.Item>{epochSettings.epoch}</ListGroup.Item>
42+
</ListGroup>
43+
<Card.Title>Protocol Parameters</Card.Title>
44+
<ListGroup horizontal>
45+
<ListGroup.Item>K: {epochSettings.protocol?.k}</ListGroup.Item>
46+
<ListGroup.Item>M: {epochSettings.protocol?.m}</ListGroup.Item>
47+
<ListGroup.Item>Phi: {epochSettings.protocol?.phi_f}</ListGroup.Item>
48+
</ListGroup>
49+
</Card.Body>
50+
</Card>
51+
</div>
52+
);
53+
}

mithril-explorer/pages/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import PendingCertificate from '../components/PendingCertificate';
33
import SnapshotsList from '../components/SnapshotsList';
44
import Head from "next/head";
55
import Image from "next/image";
6-
import { Form, Stack, Button, Row, Col, InputGroup } from "react-bootstrap";
6+
import {Form, Stack, Button, Row, Col, InputGroup, Container} from "react-bootstrap";
77
import styles from "../styles/Home.module.css";
88
import AggregatorSetter from "../components/AggregatorSetter";
99
import available_aggregators from "../aggregators-list";
1010
import {useRouter} from "next/router";
11+
import EpochSettings from "../components/EpochSettings";
1112

1213
function IntervalSetter(props) {
1314
function handleChange(event) {
@@ -89,7 +90,14 @@ export default function Explorer() {
8990
onStartStopPress={handleStartStopButtonPress} />
9091
</Row>
9192
</Form>
92-
<PendingCertificate aggregator={aggregator} updateInterval={interval} autoUpdate={autoUpdate} />
93+
<Row>
94+
<Col>
95+
<EpochSettings aggregator={aggregator} updateInterval={interval} autoUpdate={autoUpdate} />
96+
</Col>
97+
<Col xs={8}>
98+
<PendingCertificate aggregator={aggregator} updateInterval={interval} autoUpdate={autoUpdate} />
99+
</Col>
100+
</Row>
93101
<SnapshotsList aggregator={aggregator} updateInterval={interval} autoUpdate={autoUpdate} />
94102
</Stack>
95103
</main>

0 commit comments

Comments
 (0)