From 544f1726f7c9e9002dc88413f6fca687503d2e46 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Tue, 26 Sep 2023 12:08:40 +0200 Subject: [PATCH] feat: display JM and Jam version in info modal --- src/components/Footer.tsx | 20 +++++++++++++++++--- src/context/ServiceInfoContext.tsx | 20 ++------------------ src/utils.ts | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index e3ac0bb69..c185170ba 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -2,15 +2,24 @@ import { useState, useEffect, useMemo } from 'react' import * as rb from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import { useSettings, useSettingsDispatch } from '../context/SettingsContext' +import { useServiceInfo } from '../context/ServiceInfoContext' import { useWebsocketState } from '../context/WebsocketContext' import { useCurrentWallet } from '../context/WalletContext' import Sprite from './Sprite' import Cheatsheet from './Cheatsheet' import packageInfo from '../../package.json' +import { isDevMode } from '../constants/debugFeatures' +import { toSemVer } from '../utils' + +const APP_DISPLAY_VERSION = (() => { + const version = toSemVer(packageInfo.version) + return !isDevMode() ? `v${version.raw}` : `v${version.major}.${version.minor}.${version.patch + 1}dev` +})() export default function Footer() { const { t } = useTranslation() const settings = useSettings() + const serviceInfo = useServiceInfo() const settingsDispatch = useSettingsDispatch() const websocketState = useWebsocketState() const currentWallet = useCurrentWallet() @@ -46,9 +55,14 @@ export default function Footer() { {t('footer.warning_alert_title')} -

{t('footer.warning_alert_text')}

+

{t('footer.warning_alert_text')}

+

+ JoinMarket: {serviceInfo?.server?.version?.raw || 'unknown'} +
+ Jam: {APP_DISPLAY_VERSION} +

- setShowBetaWarning(false)}> + setShowBetaWarning(false)}> {t('footer.warning_alert_button_ok')}
@@ -100,7 +114,7 @@ export default function Footer() { rel="noopener noreferrer" className="d-flex align-items-center text-secondary" > - v{packageInfo.version} + {APP_DISPLAY_VERSION}
diff --git a/src/context/ServiceInfoContext.tsx b/src/context/ServiceInfoContext.tsx index c68b36637..6c6355ebd 100644 --- a/src/context/ServiceInfoContext.tsx +++ b/src/context/ServiceInfoContext.tsx @@ -5,6 +5,7 @@ import { useCurrentWallet, useSetCurrentWallet } from './WalletContext' import { useWebsocket } from './WebsocketContext' import { clearSession } from '../session' import { CJ_STATE_TAKER_RUNNING, CJ_STATE_MAKER_RUNNING } from '../constants/config' +import { toSemVer, UNKNOWN_VERSION } from '../utils' import * as Api from '../libs/JmWalletApi' @@ -57,8 +58,6 @@ interface JmGetInfoData { version: string } -const UNKNOWN_VERSION: SemVer = { major: 0, minor: 0, patch: 0, raw: 'unknown' } - type SessionFlag = { sessionActive: boolean } type MakerRunningFlag = { makerRunning: boolean } type CoinjoinInProgressFlag = { coinjoinInProgress: boolean } @@ -89,21 +88,6 @@ type ServiceInfoUpdate = | RescanBlockchainInProgressFlag | ServerInfo -const versionRegex = new RegExp(/^(\d+)\.(\d+)\.(\d+).*$/) -const toSemVer = (data: JmGetInfoData): SemVer => { - const arr = versionRegex.exec(data.version) - if (!arr || arr.length < 4) { - return UNKNOWN_VERSION - } - - return { - major: parseInt(arr[1], 10), - minor: parseInt(arr[2], 10), - patch: parseInt(arr[3], 10), - raw: data.version, - } -} - interface ServiceInfoContextEntry { serviceInfo: ServiceInfo | null reloadServiceInfo: ({ signal }: { signal: AbortSignal }) => Promise @@ -134,7 +118,7 @@ const ServiceInfoProvider = ({ children }: React.PropsWithChildren<{}>) => { .then((data: JmGetInfoData) => { dispatchServiceInfo({ server: { - version: toSemVer(data), + version: toSemVer(data.version), }, }) }) diff --git a/src/utils.ts b/src/utils.ts index d02c7eb68..11f9c062c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -71,3 +71,20 @@ export const factorToPercentage = (val: number, precision = 6) => { } export const isValidNumber = (val: number | undefined) => typeof val === 'number' && !isNaN(val) + +export const UNKNOWN_VERSION: SemVer = { major: 0, minor: 0, patch: 0, raw: 'unknown' } + +const versionRegex = new RegExp(/^(\d+)\.(\d+)\.(\d+).*$/) +export const toSemVer = (raw: string): SemVer => { + const arr = versionRegex.exec(raw) + if (!arr || arr.length < 4) { + return UNKNOWN_VERSION + } + + return { + major: parseInt(arr[1], 10), + minor: parseInt(arr[2], 10), + patch: parseInt(arr[3], 10), + raw, + } +}