Skip to content

Commit

Permalink
feat: add more detailed Node Event rows
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Oct 25, 2024
1 parent 5040d2b commit ea5b5fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/screens/node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const Node = ({ history, location }: Props) => {
const renderTable = (data: RowData[]) =>
data.map(([label, value], idx) => {
return (
<LineWrap key={`smeshing-status-${idx}`}>
<LineWrap key={`smeshing-status-${idx}-${label}`}>
<TextWrapper>
<Text>{label}</Text>
<Text>{value}</Text>
Expand Down
14 changes: 13 additions & 1 deletion app/screens/node/NodeEventActivityRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { NodeEvent } from '../../../shared/types';
import ErrorMessage from '../../basicComponents/ErrorMessage';
import { getEventType } from '../../../shared/utils';
import { getEventType, longToNumber } from '../../../shared/utils';
import { CustomTimeAgo } from '../../basicComponents';
import { getNodeEventStage } from './nodeEventUtils';

Expand Down Expand Up @@ -88,6 +88,18 @@ export default (event: NodeEvent) => {
return `Published proposal on layer ${event.proposal?.layer}`;
case 'beacon':
return `Node computed randomness beacon for epoch ${event.beacon?.epoch}`;
case 'bestProofSelected': {
const ticks = longToNumber(
typeof event.bestProofSelected?.ticks === 'string'
? parseInt(event.bestProofSelected?.ticks, 10)
: event.bestProofSelected?.ticks ?? 0
);
return `The best PoET proof is selected for round ${
event.bestProofSelected?.roundId ?? ''
}: ${ticks} ticks`;
}
case 'registeredInPoet':
return `Registered in PoET. Round ID: ${event.registeredInPoet?.roundId}`;
default:
return event.help ?? 'Node is preparing...';
}
Expand Down
11 changes: 10 additions & 1 deletion shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os from 'os';
import Long from 'long';
import { hash } from '@spacemesh/sm-codec';
import { Timestamp } from '@grpc/grpc-js/build/src/generated/google/protobuf/Timestamp';
import { Event } from '../api/generated/spacemesh/v1/Event';
Expand Down Expand Up @@ -91,8 +92,16 @@ export const toHexString = (

export const deriveHRP = (addr: string) => addr.match(/^(\w+)1/)?.[1] || null;

/* eslint-disable no-nested-ternary */
export const longToNumber = (val: Long | number) =>
typeof val === 'number' ? val : val.toNumber();
typeof val === 'number'
? val
: val instanceof Long
? val.toNumber()
: Object.hasOwn(val, 'low') && Object.hasOwn(val, 'high')
? Long.fromValue(val).toNumber()
: NaN;
/* eslint-enable no-nested-ternary */

export const convertBytesToMiB = (maxFileSize: number) =>
maxFileSize / 1024 / 1024;
Expand Down

0 comments on commit ea5b5fd

Please sign in to comment.