Skip to content

Commit

Permalink
Merge pull request #5 from ArweaveTeam/fix/types2
Browse files Browse the repository at this point in the history
Fix/types2
  • Loading branch information
vird authored Nov 7, 2023
2 parents 74445d2 + 2957fd3 commit 5dda4d3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run check:lint && npm run check:types
npm run format:renderer && npm run format:main
npm run check:lint && npm run check:types
npm run format:renderer && npm run format:main
8 changes: 5 additions & 3 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import serve from "electron-serve";
import { createWindow } from "./helpers";
import parsePrometheusTextFormat from "parse-prometheus-text-format";
import { MinorParser } from "./types/Minor";
import { Metrics } from "../types/metrics";

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

Expand Down Expand Up @@ -86,14 +87,15 @@ ipcMain.on("metrics", async (event) => {
}
}
}

event.reply("metrics", {
const metrics: Metrics = {
data_unpackaged,
data_packaged,
hash_rate,
earnings,
vdf_time_lower_bound,
});
};

event.reply("metrics", metrics);
});

ipcMain.on("open-url", async (event, arg) => {
Expand Down
15 changes: 8 additions & 7 deletions main/preload.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron";
import { Metrics } from "../types/metrics";

const handler = {
send(channel: string, value: unknown) {
ipcRenderer.send(channel, value);
},
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);
requestMetrics: function (): Promise<Metrics> {
return new Promise((resolve: (res: Metrics) => void) => {
const subscription = (_event: IpcRendererEvent, res: Metrics) => {
ipcRenderer.off("metrics", subscription);
resolve(res);
};
ipcRenderer.on(channel, subscription);
ipcRenderer.send(channel, value);
ipcRenderer.on("metrics", subscription);
ipcRenderer.send("metrics", {});
});
},
on(channel: string, callback: (...args: unknown[]) => void) {
Expand Down
8 changes: 2 additions & 6 deletions main/types/Minor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ export type MinorParser = {
type: string;
metrics: {
value: string;
labels: {
[key: string]: string;
};
buckets: {
[key: string]: string;
};
labels: Record<string, string>;
buckets: Record<string, string>;
}[];
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev": "nextron",
"build": "nextron build",
"postinstall": "electron-builder install-app-deps",
"check": "npm run check:lint && npm run check:types",
"check:lint": "npx eslint .",
"check:types": "npx tsc --noEmit",
"format:renderer": "prettier --write \"renderer/**/*.{js,jsx,ts,tsx,css}\"",
Expand Down
2 changes: 1 addition & 1 deletion renderer/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function DashboardPage() {

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

dispatch(setMinorState(data));
})();
Expand Down
7 changes: 7 additions & 0 deletions types/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type Metrics = {
data_unpackaged: number;
data_packaged: number;
hash_rate: number;
earnings: number;
vdf_time_lower_bound: number;
}

0 comments on commit 5dda4d3

Please sign in to comment.