Skip to content

Commit

Permalink
type fixes; lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vird committed Nov 3, 2023
1 parent ad73595 commit 6d028f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
9 changes: 5 additions & 4 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { app, ipcMain, shell } from "electron";
import serve from "electron-serve";
import { createWindow } from "./helpers";
import parsePrometheusTextFormat from 'parse-prometheus-text-format';
import { MinorParser } from "./types/Minor";

const isProd = process.env.NODE_ENV === "production";

Expand Down Expand Up @@ -45,7 +46,7 @@ function metric_string_parse(item): number | null {
if (!item) return null;
return +item.metrics[0].value;
}
ipcMain.on("metrics", async (event, arg) => {
ipcMain.on("metrics", async (event) => {
const res = await fetch('http://testnet-3.arweave.net:1984/metrics');
const data = await res.text();

Expand All @@ -69,9 +70,9 @@ ipcMain.on("metrics", async (event, arg) => {
const vdf_step_time_milliseconds_bucket = parsed.find((item: MinorParser) => item.name === 'vdf_step_time_milliseconds');
let vdf_time_lower_bound : number | null = null;
if (vdf_step_time_milliseconds_bucket) {
const buckets = vdf_step_time_milliseconds_bucket.metrics[0].buckets;
for(let k in buckets) {
let value = buckets[k];
const buckets = (vdf_step_time_milliseconds_bucket.metrics[0] as unknown).buckets;
for(const k in buckets) {
const value = buckets[k];
if (value === "0") continue;
if (!vdf_time_lower_bound) {
vdf_time_lower_bound = +k;
Expand Down
4 changes: 2 additions & 2 deletions main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const handler = {
send(channel: string, value: unknown) {
ipcRenderer.send(channel, value);
},
request : async function(channel: string, value: unknown) {
return new Promise((resolve, reject)=>{
request : function(channel: string, value: unknown):Promise<unknown> {
return new Promise((resolve: (...args: unknown[]) => void)=>{
const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => {
ipcRenderer.off(channel, subscription);
resolve(...args)
Expand Down
11 changes: 11 additions & 0 deletions main/types/Minor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type MinorParser = {
name: string;
help: string;
type: string;
metrics: {
value: string;
labels: {
[key: string]: string;
};
}[]
}
3 changes: 1 addition & 2 deletions renderer/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import { MainLayout } from "../layouts";
import { setMinorState, selectMinorState } from "../store/minorSlice";
import { useDispatch, useSelector } from "react-redux";
import { MinorParser } from "../types/Minor";
import ScrollSpy from "react-ui-scrollspy";

interface MenuItems {
Expand Down Expand Up @@ -44,7 +43,7 @@ export default function DashboardPage() {

React.useEffect(() => {
(async () => {
const data = await window.ipc.request("metrics");
const data = await window.ipc.request("metrics",{});

dispatch(setMinorState(data));
})()
Expand Down

0 comments on commit 6d028f4

Please sign in to comment.