From 0c8080803ae278761dc82ef37818fe0206fb1a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Papie=C5=BC?= Date: Thu, 19 Sep 2024 17:29:25 +0200 Subject: [PATCH] chore(debug): show network hashrate --- public/locales/af/settings.json | 4 +++- public/locales/cn/settings.json | 4 +++- public/locales/en/settings.json | 4 +++- public/locales/pl/settings.json | 4 +++- public/locales/tr/settings.json | 4 +++- src-tauri/src/main.rs | 4 ++++ .../components/Settings/DebugSettings.tsx | 23 ++++++++++++------- src/store/useAppStatusStore.ts | 2 ++ src/types/app-status.ts | 2 ++ src/utils/formatHashrate.ts | 15 ++++++++++++ 10 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/utils/formatHashrate.ts diff --git a/public/locales/af/settings.json b/public/locales/af/settings.json index 3b3a9ec4c..d37a7825b 100644 --- a/public/locales/af/settings.json +++ b/public/locales/af/settings.json @@ -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" } diff --git a/public/locales/cn/settings.json b/public/locales/cn/settings.json index cdd28794e..fc0f8575e 100644 --- a/public/locales/cn/settings.json +++ b/public/locales/cn/settings.json @@ -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" } \ No newline at end of file diff --git a/public/locales/en/settings.json b/public/locales/en/settings.json index a7e5d75b2..4d73fad00 100644 --- a/public/locales/en/settings.json +++ b/public/locales/en/settings.json @@ -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" } diff --git a/public/locales/pl/settings.json b/public/locales/pl/settings.json index f49f2a966..5ff880ec3 100644 --- a/public/locales/pl/settings.json +++ b/public/locales/pl/settings.json @@ -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" } \ No newline at end of file diff --git a/public/locales/tr/settings.json b/public/locales/tr/settings.json index 23366da3d..60a7b7cd1 100644 --- a/public/locales/tr/settings.json +++ b/public/locales/tr/settings.json @@ -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" } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c217f4699..09446f85c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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, @@ -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, diff --git a/src/containers/SideBar/components/Settings/DebugSettings.tsx b/src/containers/SideBar/components/Settings/DebugSettings.tsx index 2ee56d985..1d3f9aeb5 100644 --- a/src/containers/SideBar/components/Settings/DebugSettings.tsx +++ b/src/containers/SideBar/components/Settings/DebugSettings.tsx @@ -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 = ( - - {t('last-block-added-time', { ns: 'settings' })} - {displayTime} - - ); - return ( <> {t('debug-info', { ns: 'settings' })} - {debugMarkup} + + {t('last-block-added-time', { ns: 'settings' })} + {displayTime} + + + {t('sha-network-hash-rate', { ns: 'settings' })} + {formatHashrate(sha_network_hash_rate || 0)} + + + {t('randomx-network-hash-rate', { ns: 'settings' })} + {formatHashrate(randomx_network_hash_rate || 0)} + ); } diff --git a/src/store/useAppStatusStore.ts b/src/store/useAppStatusStore.ts index 11841a8ed..569a9ad99 100644 --- a/src/store/useAppStatusStore.ts +++ b/src/store/useAppStatusStore.ts @@ -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, diff --git a/src/types/app-status.ts b/src/types/app-status.ts index d4773f889..58870a2ed 100644 --- a/src/types/app-status.ts +++ b/src/types/app-status.ts @@ -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; diff --git a/src/utils/formatHashrate.ts b/src/utils/formatHashrate.ts new file mode 100644 index 000000000..af8206104 --- /dev/null +++ b/src/utils/formatHashrate.ts @@ -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'; + } +}