Skip to content

Commit

Permalink
adjust rebased code
Browse files Browse the repository at this point in the history
  • Loading branch information
mmrrnn committed Aug 8, 2024
1 parent af2e3e0 commit 75935cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/containers/SideBar/Miner/Miner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,30 @@ import AutoMiner from './components/AutoMiner.tsx';
import Scheduler from './components/Scheduler.tsx';
import ModeSelect from './components/ModeSelect.tsx';
import { useAppStatusStore } from '../../../store/useAppStatusStore.ts';
import { formatNumber } from '../../../utils';
import { useEffect } from 'react';
import { formatNumber, truncateString } from '../../../utils';
import { useEffect, useState } from 'react';

function Miner() {
const cpu = useAppStatusStore((s) => s.cpu);
const [currResource, setCurrResource] = useState<"CPU" | "GPU">("CPU");
const {cpu, gpu_brand} = useAppStatusStore((s) => s);
const {
cpu_usage,
cpu_brand = '',
hash_rate,
estimated_earnings = 0,
} = cpu || {};

const truncateString = (str: string, num: number): string => {
if (str.length <= num) {
return str;
}
return str.slice(0, num) + '...';
};
useEffect(() => {
const resourceSwitcher = setInterval(() => {
setCurrResource((prev) => (prev === "CPU" ? "GPU" : "CPU"));
}, 5_000);

useEffect(() => {
const resourceSwitcher = setInterval(() => {
setCurrResource((prev) => (prev === "CPU" ? "GPU" : "CPU"));
}, 5_000);
return () => {
clearInterval(resourceSwitcher);
};
}, []);

return () => {
clearInterval(resourceSwitcher);
};
}, []);

const resourceBrand = currResource === "CPU" ? cpuBrand : gpuBrand;
const resourceBrand = (currResource === "CPU" ? cpu_brand : gpu_brand) || "";

return (
<MinerWrapper>
Expand All @@ -42,10 +36,9 @@ function Miner() {
<TileWrapper>
<Tile title="Resources" stats="CPU" />
<ModeSelect />
{/*<Tile title="GPU Utilization" stats="23%" />*/}
<Tile title="Hashrate (to remove)" stats={hash_rate + ' H/s'} />
<Tile title="CPU Utilization" stats={cpu_usage + '%'} />
<Tile title="CHIP/GPU" stats={truncateString(cpu_brand, 10)} />
<Tile title={currResource} stats={truncateString(resourceBrand, 10)} />
<Tile
title="Est Earnings"
stats={
Expand Down
1 change: 1 addition & 0 deletions src/store/useAppStatusStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const initialState: State = {
base_node: undefined,
wallet_balance: undefined,
mode: 'eco',
gpu_brand: undefined,
};
export const useAppStatusStore = create<AppStatusStoreState>()(
persist(
Expand Down
1 change: 1 addition & 0 deletions src/types/app-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface AppStatus {
cpu?: CpuMinerStatus;
base_node?: BaseNodeStatus;
wallet_balance?: WalletBalance;
gpu_brand?: string;
}

export interface CpuMinerStatus {
Expand Down

0 comments on commit 75935cd

Please sign in to comment.