mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-09 20:21:01 +00:00
Display node details on map
This commit is contained in:
@@ -54,20 +54,6 @@
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.Chain-map-node {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background: #d64ca8;
|
||||
border: 1px solid #000;
|
||||
border-radius: 6px;
|
||||
margin-left: -6px;
|
||||
margin-top: -6px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Chain-node-list {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
|
||||
@@ -4,14 +4,8 @@ import { formatNumber, secondsWithPrecision, viewport } from '../utils';
|
||||
import { Tile, Icon, Node, Ago } from './';
|
||||
import { Types } from '@dotstats/common';
|
||||
|
||||
import nodeIcon from '../icons/server.svg';
|
||||
import nodeTypeIcon from '../icons/terminal.svg';
|
||||
import peersIcon from '../icons/broadcast.svg';
|
||||
import transactionsIcon from '../icons/inbox.svg';
|
||||
import blockIcon from '../icons/package.svg';
|
||||
import blockHashIcon from '../icons/file-binary.svg';
|
||||
import blockTimeIcon from '../icons/history.svg';
|
||||
import propagationTimeIcon from '../icons/dashboard.svg';
|
||||
import lastTimeIcon from '../icons/watch.svg';
|
||||
import worldIcon from '../icons/globe.svg';
|
||||
|
||||
@@ -130,14 +124,10 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
|
||||
// const location = [48.8589507, 2.2770201] as Types.NodeLocation; // Paris
|
||||
// const location = [36.7183391, -4.5193071]as Types.NodeLocation; // Malaga
|
||||
|
||||
const { left, top } = this.pixelPosition(location[0], location[1]);
|
||||
|
||||
return (
|
||||
<span
|
||||
key={node.id}
|
||||
className="Chain-map-node"
|
||||
style={this.pixelPosition(location[0], location[1])}
|
||||
title={node.nodeDetails[0]}
|
||||
data-location={JSON.stringify(node.location)}
|
||||
/>
|
||||
<Node.Location key={node.id} left={left} top={top} {...node} />
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -148,19 +138,7 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
|
||||
private renderTable() {
|
||||
return (
|
||||
<table className="Chain-node-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><Icon src={nodeIcon} alt="Node" /></th>
|
||||
<th><Icon src={nodeTypeIcon} alt="Implementation" /></th>
|
||||
<th><Icon src={peersIcon} alt="Peer Count" /></th>
|
||||
<th><Icon src={transactionsIcon} alt="Transactions in Queue" /></th>
|
||||
<th><Icon src={blockIcon} alt="Block" /></th>
|
||||
<th><Icon src={blockHashIcon} alt="Block Hash" /></th>
|
||||
<th><Icon src={blockTimeIcon} alt="Block Time" /></th>
|
||||
<th><Icon src={propagationTimeIcon} alt="Block Propagation Time" /></th>
|
||||
<th><Icon src={lastTimeIcon} alt="Last Block Time" /></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<Node.Header />
|
||||
<tbody>
|
||||
{
|
||||
this.nodes().sort(sortNodes).map((node) => <Node.Row key={node.id} {...node} />)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
.Node-Location {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background: #d64ca8;
|
||||
border: 1px solid #000;
|
||||
border-radius: 6px;
|
||||
margin-left: -6px;
|
||||
margin-top: -6px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Node-details {
|
||||
display: none;
|
||||
min-width: 335px;
|
||||
position: absolute;
|
||||
left: 16px;
|
||||
top: -4px;
|
||||
font-family: monospace, sans-serif;
|
||||
background: #222;
|
||||
color: #fff;
|
||||
box-shadow: 0 3px 20px rgba(0,0,0,0.5);
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.Node-details td {
|
||||
text-align: left;
|
||||
padding: 0.5em 1em;
|
||||
}
|
||||
|
||||
.Node-details td:nth-child(odd) {
|
||||
padding-right: 0.2em;
|
||||
}
|
||||
|
||||
.Node-details td:nth-child(even) {
|
||||
padding-left: 0.2em;
|
||||
}
|
||||
|
||||
.Node-Location:hover .Node-details {
|
||||
display: initial;
|
||||
}
|
||||
@@ -1,8 +1,20 @@
|
||||
import * as React from 'react';
|
||||
import { formatNumber, trimHash, milliOrSecond, secondsWithPrecision } from '../utils';
|
||||
import { Ago } from './Ago';
|
||||
import { Ago, Icon } from './';
|
||||
import { Types, Maybe } from '@dotstats/common';
|
||||
|
||||
import nodeIcon from '../icons/server.svg';
|
||||
import nodeTypeIcon from '../icons/terminal.svg';
|
||||
import peersIcon from '../icons/broadcast.svg';
|
||||
import transactionsIcon from '../icons/inbox.svg';
|
||||
import blockIcon from '../icons/package.svg';
|
||||
import blockHashIcon from '../icons/file-binary.svg';
|
||||
import blockTimeIcon from '../icons/history.svg';
|
||||
import propagationTimeIcon from '../icons/dashboard.svg';
|
||||
import lastTimeIcon from '../icons/watch.svg';
|
||||
|
||||
import './Node.css';
|
||||
|
||||
export namespace Node {
|
||||
export interface Props {
|
||||
id: Types.NodeId;
|
||||
@@ -17,6 +29,24 @@ export namespace Node {
|
||||
top: number;
|
||||
}
|
||||
|
||||
export function Header() {
|
||||
return (
|
||||
<thead>
|
||||
<tr>
|
||||
<th><Icon src={nodeIcon} alt="Node" /></th>
|
||||
<th><Icon src={nodeTypeIcon} alt="Implementation" /></th>
|
||||
<th><Icon src={peersIcon} alt="Peer Count" /></th>
|
||||
<th><Icon src={transactionsIcon} alt="Transactions in Queue" /></th>
|
||||
<th><Icon src={blockIcon} alt="Block" /></th>
|
||||
<th><Icon src={blockHashIcon} alt="Block Hash" /></th>
|
||||
<th><Icon src={blockTimeIcon} alt="Block Time" /></th>
|
||||
<th><Icon src={propagationTimeIcon} alt="Block Propagation Time" /></th>
|
||||
<th><Icon src={lastTimeIcon} alt="Last Block Time" /></th>
|
||||
</tr>
|
||||
</thead>
|
||||
)
|
||||
}
|
||||
|
||||
export function Row(props: Props) {
|
||||
const [name, implementation, version] = props.nodeDetails;
|
||||
const [height, hash, blockTime, blockTimestamp, propagationTime] = props.blockDetails;
|
||||
@@ -39,14 +69,36 @@ export namespace Node {
|
||||
|
||||
export function Location(props: Props & PixelPosition) {
|
||||
const { left, top } = props;
|
||||
const [name, implementation, version] = props.nodeDetails;
|
||||
const [height, hash, blockTime, blockTimestamp, propagationTime] = props.blockDetails;
|
||||
|
||||
return (
|
||||
<span
|
||||
className="Chain-map-node"
|
||||
style={{ left, top }}
|
||||
title={props.nodeDetails[0]}
|
||||
data-location={JSON.stringify(props.location)}
|
||||
/>
|
||||
<div className="Node-Location" style={{ left, top }}>
|
||||
<table className="Node-details">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><Icon src={nodeIcon} alt="Node" /></td><td colSpan={5}>{name}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Icon src={nodeTypeIcon} alt="Implementation" /></td><td colSpan={5}>{implementation} v{version}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Icon src={blockIcon} alt="Block" /></td><td colSpan={5}>#{formatNumber(height)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Icon src={blockHashIcon} alt="Block Hash" /></td><td colSpan={5}>{trimHash(hash, 20)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Icon src={blockTimeIcon} alt="Block Time" /></td>
|
||||
<td style={{ width: 80 }}>{secondsWithPrecision(blockTime/1000)}</td>
|
||||
<td><Icon src={propagationTimeIcon} alt="Block Propagation Time" /></td>
|
||||
<td style={{ width: 58 }}>{propagationTime === null ? '∞' : milliOrSecond(propagationTime as number)}</td>
|
||||
<td><Icon src={lastTimeIcon} alt="Last Block Time" /></td>
|
||||
<td style={{ minWidth: 82 }}><Ago when={blockTimestamp} /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
import './index.css';
|
||||
import registerServiceWorker from './registerServiceWorker';
|
||||
import { unregister } from './registerServiceWorker';
|
||||
|
||||
ReactDOM.render(
|
||||
<App />,
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
registerServiceWorker();
|
||||
|
||||
unregister();
|
||||
|
||||
@@ -9,111 +9,6 @@
|
||||
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
|
||||
// This link also includes instructions on opting out of this behavior.
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export default function register() {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL!,
|
||||
window.location.toString()
|
||||
);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Lets check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://goo.gl/SC7cgQ'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not local host. Just register service worker
|
||||
registerValidSW(swUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl: string) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker) {
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the old content will have been purged and
|
||||
// the fresh content will have been added to the cache.
|
||||
// It's the perfect time to display a 'New content is
|
||||
// available; please refresh.' message in your web app.
|
||||
console.log('New content is available; please refresh.');
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// 'Content is cached for offline use.' message.
|
||||
console.log('Content is cached for offline use.');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl)
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
if (
|
||||
response.status === 404 ||
|
||||
response.headers.get('content-type')!.indexOf('javascript') === -1
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
|
||||
Reference in New Issue
Block a user