Skip to content

Commit

Permalink
chore(debug): show network hashrate
Browse files Browse the repository at this point in the history
  • Loading branch information
mmrrnn committed Sep 20, 2024
1 parent 8a5978f commit 0c80808
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 13 deletions.
4 changes: 3 additions & 1 deletion public/locales/af/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
"gpu-unavailable": "⚠️ GPU gedeaktiveer omdat jou hardeware dit nie ondersteun nie",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet"
"reset-wallet": "Reset wallet",
"sha-network-hash-rate": "Hashrate sieci Sha3",
"randomx-network-hash-rate": "Hashrate sieci Randomx"
}
4 changes: 3 additions & 1 deletion public/locales/cn/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
"reset-permanently": "您确定要永久重置所有设置吗?",
"reset-wallet": "Reset wallet",
"experimental-title": "实验性功能",
"experimental-warning": "⚠️ 警告:这些功能正在积极开发中,可能会表现得不可预测。请谨慎操作。"
"experimental-warning": "⚠️ 警告:这些功能正在积极开发中,可能会表现得不可预测。请谨慎操作。",
"sha-network-hash-rate": "Hashrate sieci Sha3",
"randomx-network-hash-rate": "Hashrate sieci Randomx"
}
4 changes: 3 additions & 1 deletion public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet",
"experimental-title": "Experimental Features",
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully."
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully.",
"sha-network-hash-rate": "Sha3 network hashrate",
"randomx-network-hash-rate": "Randomx network hashrate"
}
4 changes: 3 additions & 1 deletion public/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"reset-settings": "Resetuj ustawienia",
"reset-permanently": "Czy na pewno chcesz trwale zresetować ustawienia?",
"gpu-unavailable": "⚠️ Kopanie GPU niedostępne ponieważ Twój sprzęt go nie obsługuje",
"reset-wallet": "Resetuj porfel"
"reset-wallet": "Resetuj porfel",
"sha-network-hash-rate": "Hashrate sieci Sha3",
"randomx-network-hash-rate": "Hashrate sieci Randomx"
}
4 changes: 3 additions & 1 deletion public/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
"reset-settings": "Ayarları sıfırla",
"reset-permanently": "Tüm ayarları kalıcı olarak sıfırlamak istediğinizden emin misiniz?",
"gpu-unavailable": "⚠️ GPU devre dışı bırakıldı çünkü donanımınız bunu desteklemiyor",
"reset-wallet": "Reset wallet"
"reset-wallet": "Reset wallet",
"sha-network-hash-rate": "Sha3 network hashrate",
"randomx-network-hash-rate": "Randomx network hashrate"
}
4 changes: 4 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ async fn status(
Ok(Some(AppStatus {
cpu,
gpu,
sha_network_hash_rate: sha_hash_rate,
randomx_network_hash_rate: randomx_hash_rate,
hardware_status: hardware_status.clone(),
base_node: BaseNodeStatus {
block_height,
Expand Down Expand Up @@ -1010,6 +1012,8 @@ async fn reset_settings<'r>(
pub struct AppStatus {
cpu: CpuMinerStatus,
gpu: GpuMinerStatus,
sha_network_hash_rate: u64,
randomx_network_hash_rate: u64,
hardware_status: HardwareStatus,
base_node: BaseNodeStatus,
wallet_balance: WalletBalance,
Expand Down
23 changes: 15 additions & 8 deletions src/containers/SideBar/components/Settings/DebugSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ import calculateTimeSince from '@app/utils/calculateTimeSince.ts';
import { useAppStatusStore } from '@app/store/useAppStatusStore.ts';
import { Stack } from '@app/components/elements/Stack.tsx';
import { useShallow } from 'zustand/react/shallow';
import { formatHashrate } from '@app/utils/formatHashrate';

export default function DebugSettings() {
const { t } = useTranslation(['common', 'settings'], { useSuspense: false });

const blockTime = useAppStatusStore(useShallow((state) => state.base_node?.block_time));
const sha_network_hash_rate = useAppStatusStore((state) => state?.sha_network_hash_rate);
const randomx_network_hash_rate = useAppStatusStore((state) => state?.randomx_network_hash_rate);

const now = new Date();
const lastBlockTime = calculateTimeSince(blockTime || 0, now.getTime());
const { daysString, hoursString, minutes, seconds } = lastBlockTime || {};
const displayTime = `${daysString} ${hoursString} : ${minutes} : ${seconds}`;

const debugMarkup = (
<Stack direction="row" justifyContent="space-between">
<Typography variant="p">{t('last-block-added-time', { ns: 'settings' })}</Typography>
<Typography>{displayTime}</Typography>
</Stack>
);

return (
<>
<Typography variant="h6">{t('debug-info', { ns: 'settings' })}</Typography>
{debugMarkup}
<Stack direction="row" justifyContent="space-between">
<Typography variant="p">{t('last-block-added-time', { ns: 'settings' })}</Typography>
<Typography>{displayTime}</Typography>
</Stack>
<Stack direction="row" justifyContent="space-between">
<Typography variant="p">{t('sha-network-hash-rate', { ns: 'settings' })}</Typography>
<Typography>{formatHashrate(sha_network_hash_rate || 0)}</Typography>
</Stack>
<Stack direction="row" justifyContent="space-between">
<Typography variant="p">{t('randomx-network-hash-rate', { ns: 'settings' })}</Typography>
<Typography>{formatHashrate(randomx_network_hash_rate || 0)}</Typography>
</Stack>
</>
);
}
2 changes: 2 additions & 0 deletions src/store/useAppStatusStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type AppStatusStoreState = State & Actions;

const initialState: State = {
cpu: undefined,
sha_network_hash_rate: 0,
randomx_network_hash_rate: 0,
hardware_status: undefined,
base_node: undefined,
p2pool_enabled: false,
Expand Down
2 changes: 2 additions & 0 deletions src/types/app-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { modeType } from '../store/types';
export interface AppStatus {
cpu?: CpuMinerStatus;
gpu?: GpuMinerStatus;
sha_network_hash_rate: number;
randomx_network_hash_rate: number;
gpu_earnings?: EstimatedEarnings;
base_node?: BaseNodeStatus;
hardware_status?: HardwareStatus;
Expand Down
15 changes: 15 additions & 0 deletions src/utils/formatHashrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function formatHashrate(hashrate: number) {
if (hashrate < 1000) {
return hashrate + ' H/s';
} else if (hashrate < 1000000) {
return (hashrate / 1000).toFixed(2) + ' kH/s';
} else if (hashrate < 1000000000) {
return (hashrate / 1000000).toFixed(2) + ' MH/s';
} else if (hashrate < 1000000000000) {
return (hashrate / 1000000000).toFixed(2) + ' GH/s';
} else if (hashrate < 1000000000000000) {
return (hashrate / 1000000000000).toFixed(2) + ' TH/s';
} else {
return (hashrate / 1000000000000000).toFixed(2) + ' PH/s';
}
}

0 comments on commit 0c80808

Please sign in to comment.