Skip to content

Commit

Permalink
feat: display JM and Jam version in info modal
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Sep 26, 2023
1 parent c297e33 commit 544f172
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
20 changes: 17 additions & 3 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -46,9 +55,14 @@ export default function Footer() {
<rb.Card className="warning-card translate-middle shadow-lg">
<rb.Card.Body>
<rb.Card.Title className="text-center mb-3">{t('footer.warning_alert_title')}</rb.Card.Title>
<p className="text-secondary">{t('footer.warning_alert_text')}</p>
<p>{t('footer.warning_alert_text')}</p>
<p className="text-secondary">
JoinMarket: {serviceInfo?.server?.version?.raw || 'unknown'}
<br />
Jam: {APP_DISPLAY_VERSION}
</p>
<div className="text-center mt-3">
<rb.Button variant="secondary" onClick={() => setShowBetaWarning(false)}>
<rb.Button variant="dark" onClick={() => setShowBetaWarning(false)}>
{t('footer.warning_alert_button_ok')}
</rb.Button>
</div>
Expand Down Expand Up @@ -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}
</a>
</div>
<div className="d-flex gap-2 pe-2">
Expand Down
20 changes: 2 additions & 18 deletions src/context/ServiceInfoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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<ServiceInfo>
Expand Down Expand Up @@ -134,7 +118,7 @@ const ServiceInfoProvider = ({ children }: React.PropsWithChildren<{}>) => {
.then((data: JmGetInfoData) => {
dispatchServiceInfo({
server: {
version: toSemVer(data),
version: toSemVer(data.version),
},
})
})
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit 544f172

Please sign in to comment.