Skip to content

Commit

Permalink
Merge pull request #336 from algorandfoundation/dev
Browse files Browse the repository at this point in the history
v0.12.1
  • Loading branch information
drichar authored Jan 12, 2025
2 parents ebea8c6 + 8f1f41a commit eb7dff7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap",
"version": "0.12.0",
"version": "0.12.1",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reti-contracts",
"version": "0.12.0",
"version": "0.12.1",
"license": "MIT",
"scripts": {
"generate-client": "algokit generate client contracts/artifacts/ --language typescript --output contracts/clients/{contract_name}Client.ts && ./update_contract_artifacts.sh",
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reti-ui",
"version": "0.12.0",
"version": "0.12.1",
"private": true,
"type": "module",
"engines": {
Expand Down
46 changes: 42 additions & 4 deletions ui/src/hooks/useCheckForUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import * as React from 'react'
import { toast } from 'sonner'

// Helper function to compare versions
function isNewerVersion(current: string, deployed: string): boolean {
// Remove 'v' prefix if present
const cleanCurrent = current.replace(/^v/, '')
const cleanDeployed = deployed.replace(/^v/, '')

const currentParts = cleanCurrent.split('.').map(Number)
const deployedParts = cleanDeployed.split('.').map(Number)

// Compare major.minor.patch
for (let i = 0; i < 3; i++) {
if (deployedParts[i] > currentParts[i]) return true
if (deployedParts[i] < currentParts[i]) return false
}

return false
}

export function useCheckForUpdates() {
React.useEffect(() => {
if (import.meta.env.MODE !== 'production') {
Expand All @@ -9,11 +27,31 @@ export function useCheckForUpdates() {

const checkForUpdates = async () => {
try {
const response = await fetch('/version.json')
const response = await fetch(`/version.json?_=${Date.now()}`, {
cache: 'no-store',
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
Expires: '0',
},
})

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json()
const deployedVersion = data.version

if (deployedVersion !== __APP_VERSION__) {
// Only show toast if deployed version is newer
if (isNewerVersion(__APP_VERSION__, deployedVersion)) {
// eslint-disable-next-line no-console
console.log('New version detected:', {
current: __APP_VERSION__,
deployed: deployedVersion,
timestamp: new Date().toISOString(),
})

toast(`A new version is available! v${deployedVersion}`, {
description: 'Click the Reload button to update the app.',
action: {
Expand All @@ -29,15 +67,15 @@ export function useCheckForUpdates() {
}
}

const delay = Number(import.meta.env.VITE_UPDATE_CHECK_INTERVAL || 1000 * 60)
checkForUpdates()

const delay = Number(import.meta.env.VITE_UPDATE_CHECK_INTERVAL || 1000 * 60)
if (Number.isNaN(delay)) {
console.error('Invalid update check interval:', import.meta.env.VITE_UPDATE_CHECK_INTERVAL)
return
}

const interval = setInterval(checkForUpdates, delay)

return () => clearInterval(interval)
}, [])
}
17 changes: 12 additions & 5 deletions ui/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ const replaceVersionPlugin = () => {
outDir = config.build.outDir
},
generateBundle() {
const filePath = path.resolve(__dirname, 'public/version.json')
const content = fs.readFileSync(filePath, 'utf-8')
const updatedContent = content.replace('__APP_VERSION__', version)
const newFilePath = path.resolve(outDir, 'version.json')
fs.writeFileSync(newFilePath, updatedContent, 'utf-8')
try {
const filePath = path.resolve(__dirname, 'public/version.json')
if (!fs.existsSync(filePath)) {
throw new Error(`version.json not found at ${filePath}`)
}
const content = fs.readFileSync(filePath, 'utf-8')
const updatedContent = content.replace('__APP_VERSION__', version)
const newFilePath = path.resolve(outDir, 'version.json')
fs.writeFileSync(newFilePath, updatedContent, 'utf-8')
} catch (error) {
console.error('Failed to replace version in version.json file:', error)
}
},
}
}
Expand Down

1 comment on commit eb7dff7

@vercel
Copy link

@vercel vercel bot commented on eb7dff7 Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

reti – ./

reti-git-dev-nodely.vercel.app
reti-nodely.vercel.app
fnet.reti.nodly.io

Please sign in to comment.