Skip to content

Commit 177ffde

Browse files
committed
feat: watch for update
1 parent 9178cfe commit 177ffde

7 files changed

Lines changed: 83 additions & 17 deletions

File tree

app.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Sentry from "@sentry/vue"
55
/** Services */
66
import Socket from "@/services/api/socket"
77
import amp from "@/services/amp"
8+
import { watchForUpdate } from "@/services/version"
89
910
/** Components */
1011
import ModalsManager from "@/components/modals/ModalsManager.vue"
@@ -46,7 +47,46 @@ rollupsRankingStore.$subscribe((mutation, state) => {
4647
localStorage.setItem("rollups_ranking", JSON.stringify(state.rollups_ranking))
4748
})
4849
50+
let watchInterval = null
51+
4952
onMounted(async () => {
53+
/**
54+
* Watch for package.json->version and notify users about the new version
55+
*/
56+
appStore.version = (await $fetch("/api/version")).version
57+
if (!import.meta.dev)
58+
watchInterval = watchForUpdate(appStore.version, (newVersion) => {
59+
clearInterval(watchInterval)
60+
notificationsStore.create({
61+
notification: {
62+
type: "success",
63+
icon: "info",
64+
title: "New update is available",
65+
description: "Refresh the page to get the latest update with new features & bug fixes.",
66+
autoDestroy: false,
67+
irremovable: true,
68+
actions: [
69+
{
70+
name: "Refresh",
71+
icon: "refresh",
72+
callback: () => {
73+
location.reload()
74+
},
75+
},
76+
{
77+
name: "Changelog",
78+
icon: "menu",
79+
callback: () => {
80+
window
81+
.open(`https://github.com/celenium-io/celenium-interface/releases/tag/v${newVersion}`, "_blank")
82+
.focus()
83+
},
84+
},
85+
],
86+
},
87+
})
88+
})
89+
5090
if (localStorage.bookmarks) {
5191
bookmarksStore.bookmarks = JSON.parse(localStorage.bookmarks)
5292
}
@@ -117,6 +157,10 @@ onMounted(async () => {
117157
Socket.close()
118158
}
119159
})
160+
161+
onBeforeUnmount(() => {
162+
clearInterval(watchInterval)
163+
})
120164
</script>
121165
122166
<template>

assets/icons.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"burn": "m19.676 10.993c-0.3035-0.39661-0.67297-0.74034-1.0161-1.0841-0.8841-0.79323-1.887-1.3617-2.7315-2.1946-1.9661-1.9302-2.4016-5.1163-1.148-7.5621-1.2536 0.30407-2.3488 0.99153-3.2857 1.7451-3.4176 2.7498-4.7636 7.6017-3.1537 11.766 0.052783 0.1322 0.10556 0.26441 0.10556 0.43627 0 0.29085-0.19793 0.55526-0.46184 0.66102-0.3035 0.1322-0.62019 0.052888-0.87091-0.15864-0.079173-0.066108-0.13196-0.1322-0.18474-0.22475-1.4911-1.8905-1.7286-4.6007-0.72575-6.7689-2.2037 1.798-3.4044 4.8387-3.2329 7.7075 0.079174 0.66102 0.15835 1.322 0.38267 1.9831 0.18474 0.79323 0.54102 1.5865 0.93688 2.2871 1.4251 2.2871 3.8927 3.9265 6.545 4.257 2.8238 0.35695 5.8456-0.15864 8.0097-2.1153 2.4148-2.1946 3.2593-5.7112 2.0189-8.7255l-0.17154-0.34373c-0.27711-0.60814-1.0161-1.6658-1.0161-1.6658m-4.1698 8.3289c-0.36948 0.31729-0.97647 0.66102-1.4515 0.79323-1.4779 0.52882-2.9558-0.21153-3.8267-1.0841 1.5703-0.37017 2.5072-1.5336 2.7843-2.7102 0.22432-1.0576-0.19793-1.9302-0.36948-2.9482-0.15835-0.97831-0.13196-1.8112 0.22432-2.7234 0.25072 0.50238 0.51463 1.0048 0.83132 1.4014 1.0161 1.322 2.6127 1.9037 2.9558 3.7017 0.05278 0.18509 0.07917 0.37017 0.07917 0.56848 0.03958 1.0841-0.43545 2.2739-1.2272 3.001z",
3636
"unlock": "m3.998 6.07c3.608-2.084 8.211-1.05 10.582 2.377 2.37 3.427 1.713 8.099-1.511 10.739-3.224 2.641-7.934 2.364-10.827-0.635s-2.999-7.716-0.244-10.843v-1.708c0-2.582 1.652-4.875 4.102-5.692 2.45-0.816 5.148 0.026 6.698 2.092 0.331 0.442 0.242 1.069-0.2 1.4-0.442 0.332-1.069 0.242-1.4-0.2-1.033-1.377-2.832-1.939-4.465-1.394-1.634 0.544-2.735 2.073-2.735 3.794zm5 5.93c0-0.552-0.448-1-1-1-0.553 0-1 0.448-1 1v2c0 0.553 0.447 1 1 1 0.552 0 1-0.447 1-1z",
3737
"self-delegation": "m12 1c-6.0751 0-11 4.9249-11 11 0 6.0751 4.9249 11 11 11 6.0751 0 11-4.9249 11-11 0-6.0751-4.9249-11-11-11zm-9 11c0-4.9706 4.0294-9 9-9 4.9706 0 9 4.0294 9 9 0 2.2211-0.8046 4.2543-2.1382 5.824-0.9161-1.1126-2.3054-1.824-3.8618-1.824h-6c-1.5564 0-2.9457 0.7114-3.8618 1.8241-1.3336-1.5698-2.1382-3.603-2.1382-5.8241zm4-2.5c0-2.7614 2.2386-5 5-5 2.7614 0 5 2.2386 5 5 0 2.7614-2.2386 5-5 5-2.7614 0-5-2.2386-5-5z",
38+
"refresh": "M10.1702 3.18887C13.523 2.49067 16.918 3.74107 19.0003 6.30704V4.0004C19.0003 3.44811 19.448 3.0004 20.0003 3.0004C20.5525 3.00055 21.0003 3.44821 21.0003 4.0004V9.0004C21.0001 9.55241 20.5523 10.0002 20.0003 10.0004H15.0003C14.4481 10.0004 14.0005 9.5525 14.0003 9.0004C14.0003 8.44811 14.448 8.0004 15.0003 8.0004H17.7708C16.1416 5.63557 13.1619 4.47732 10.2571 5.22208V5.2211C9.0266 5.53767 7.90556 6.18399 7.01397 7.08927C6.12234 7.99464 5.49333 9.1254 5.19561 10.3607C4.89791 11.5961 4.94218 12.8898 5.32354 14.102C5.70491 15.3139 6.40943 16.3993 7.36065 17.2416C8.31201 18.0839 9.47559 18.6514 10.7249 18.8832C11.9741 19.1148 13.2634 19.002 14.4534 18.557C15.6434 18.1119 16.6902 17.3514 17.4808 16.3568C18.2714 15.3623 18.7764 14.1712 18.9417 12.9115C19.0135 12.3639 19.5162 11.9774 20.0638 12.0492C20.611 12.1214 20.9969 12.6239 20.9251 13.1713C20.7126 14.7911 20.0628 16.3231 19.0462 17.602C18.0296 18.8806 16.6837 19.8588 15.1536 20.4311C13.6235 21.0032 11.9659 21.1479 10.3597 20.85C8.7534 20.552 7.25863 19.8216 6.03546 18.7387C4.81228 17.6556 3.90665 16.26 3.41632 14.7016C2.92605 13.1431 2.86853 11.4803 3.25128 9.892C3.63407 8.30375 4.44282 6.84996 5.58917 5.68595C6.73552 4.522 8.17693 3.69158 9.75909 3.28458H9.76007L10.1702 3.18887Z",
3839
"redelegate": "m8 9c-3.866 0-7 3.134-7 7s3.134 7 7 7c3.866 0 7-3.134 7-7s-3.134-7-7-7zm1.0625-1.938c0.45832-3.4225 3.3898-6.062 6.9377-6.062 3.866 0 7 3.134 7 7 0 3.5479-2.6395 6.4794-6.062 6.9377-0.4847-4.1215-3.7542-7.391-7.8757-7.8757zm9.6446 10.231c0.3905 0.3905 0.3905 1.0237 0 1.4142l-0.2598 0.2598c1.4447-0.216 2.5527-1.4621 2.5527-2.9669 0-0.5523 0.4477-1 1-1s1 0.4477 1 1c0 2.6273-2.0264 4.7813-4.6014 4.9843l0.3085 0.3086c0.3905 0.3905 0.3905 1.0237 0 1.4142s-1.0237 0.3905-1.4142 0l-2-2c-0.1875-0.1875-0.2929-0.4419-0.2929-0.7071s0.1054-0.5196 0.2929-0.7071l2-2c0.3905-0.3905 1.0237-0.3905 1.4142 0zm-13.414-16c0.39053-0.39052 1.0237-0.39052 1.4142 0l2 2c0.39052 0.39053 0.39052 1.0237 0 1.4142l-2 2c-0.39053 0.39052-1.0237 0.39052-1.4142 0-0.39052-0.39053-0.39052-1.0237 0-1.4142l0.25977-0.25976c-1.4447 0.21598-2.5527 1.462-2.5527 2.9669 0 0.55228-0.44772 1-1 1s-1-0.44772-1-1c0-2.6273 2.0264-4.7813 4.6014-4.9844l-0.30855-0.30854c-0.39052-0.39053-0.39052-1.0237 0-1.4142z",
3940
"granters": "M 11.181 12.164 C 11.463 12.308 11.693 12.537 11.836 12.819 C 11.99 13.119 12 13.448 12 13.777 L 12 18.223 C 12 18.343 12 18.485 11.99 18.61 C 11.977 18.809 11.925 19.003 11.836 19.181 C 11.693 19.463 11.463 19.692 11.181 19.836 C 11.003 19.925 10.809 19.977 10.61 19.99 C 10.485 20 10.342 20 10.223 20 L 1.777 20 C 1.657 20 1.515 20 1.389 19.99 C 1.19 19.977 0.996 19.925 0.817 19.836 C 0.534 19.691 0.305 19.46 0.161 19.176 C 0.074 18.997 0.023 18.803 0.01 18.605 C 0.002 18.476 -0.001 18.347 0 18.218 C 0.005 17.179 -0.026 16.065 0.38 15.087 C 0.888 13.862 1.861 12.888 3.086 12.381 C 3.596 12.169 4.134 12.081 4.742 12.041 C 5.335 12 6.063 12 6.964 12 L 10.224 12 C 10.552 12 10.881 12.01 11.181 12.164 Z M 21.707 13.293 C 22.098 13.683 22.098 14.316 21.707 14.707 L 17.707 18.707 C 17.317 19.097 16.684 19.097 16.293 18.707 L 14.293 16.707 C 13.914 16.315 13.92 15.691 14.306 15.305 C 14.691 14.919 15.315 14.914 15.707 15.293 L 17 16.586 L 20.293 13.293 C 20.684 12.903 21.317 12.903 21.707 13.293 Z M 13.573 0.916 C 13.781 0.404 14.364 0.157 14.875 0.364 C 16.765 1.128 18.001 2.962 18.001 5 C 18.001 7.038 16.765 8.872 14.875 9.636 C 14.365 9.839 13.786 9.591 13.58 9.081 C 13.374 8.572 13.617 7.992 14.125 7.782 C 15.259 7.323 16.001 6.223 16.001 5 C 16.001 3.777 15.259 2.677 14.125 2.218 C 13.614 2.011 13.366 1.428 13.573 0.916 Z M 3.5 5 C 3.5 2.239 5.739 0 8.5 0 C 11.262 0 13.5 2.239 13.5 5 C 13.5 7.761 11.262 10 8.5 10 C 5.739 10 3.5 7.761 3.5 5 Z",
4041
"grid": "m8 2c0.55228 0 1 0.44772 1 1v4h6v-4c0-0.55228 0.4477-1 1-1s1 0.44772 1 1v4h3c0.5523 0 1 0.44772 1 1s-0.4477 1-1 1h-3v6h3c0.5523 0 1 0.4477 1 1s-0.4477 1-1 1h-3v4c0 0.5523-0.4477 1-1 1s-1-0.4477-1-1v-4h-6v4c0 0.5523-0.44772 1-1 1s-1-0.4477-1-1v-4h-3c-0.55228 0-1-0.4477-1-1s0.44772-1 1-1h3v-6h-3c-0.55228 0-1-0.44772-1-1s0.44772-1 1-1h3v-4c0-0.55228 0.44772-1 1-1zm7 13v-6h-6v6h6z",

components/Notifications.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<script setup>
2+
/** UI */
3+
import Button from "@/components/ui/Button.vue"
4+
25
/**
36
* Store
47
*/
@@ -37,13 +40,9 @@ const handleActionCallback = (callback, notification) => {
3740
<div v-if="notification.description" :class="$style.description">
3841
<Text v-if="notification.description === 'privacy'">
3942
Here's our
40-
<NuxtLink to="/privacy-policy" :class="$style.link">
41-
Privacy Policy
42-
</NuxtLink>
43-
and
44-
<NuxtLink to="/terms-of-use" :class="$style.link">
45-
Terms of Use
46-
</NuxtLink>
43+
<NuxtLink to="/privacy-policy" :class="$style.link"> Privacy Policy </NuxtLink>
44+
and
45+
<NuxtLink to="/terms-of-use" :class="$style.link"> Terms of Use </NuxtLink>
4746
</Text>
4847
<Text v-else>
4948
{{ notification.description }}
@@ -65,17 +64,16 @@ const handleActionCallback = (callback, notification) => {
6564
</div>
6665

6766
<Flex v-if="notification.actions" align="center" gap="6" :class="$style.actions">
68-
<Flex
69-
v-for="(action, aIndex) in notification.actions"
70-
:key="aIndex"
67+
<Button
68+
v-for="(action, actionIdx) in notification.actions"
69+
:key="actionIdx"
7170
@click="handleActionCallback(action.callback, notification)"
72-
align="center"
73-
gap="6"
74-
:class="$style.action"
71+
type="secondary"
72+
size="mini"
7573
>
76-
<Icon v-if="action.icon" :name="action.icon" color="tertiary" size="12" />
77-
<Text size="12" weight="600" color="secondary">{{ action.name }}</Text>
78-
</Flex>
74+
<Icon v-if="action.icon" :name="action.icon" color="tertiary" size="14" />
75+
<Text size="12" weight="600" color="primary">{{ action.name }}</Text>
76+
</Button>
7977
</Flex>
8078
</Flex>
8179

@@ -137,7 +135,7 @@ const handleActionCallback = (callback, notification) => {
137135
}
138136
139137
.general_icon.success {
140-
fill: var(--green);
138+
fill: var(--brand);
141139
}
142140
143141
.general_icon.warning {

server/api/version.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { readFileSync } from "fs"
2+
import { join } from "path"
3+
4+
export default defineEventHandler(() => {
5+
const { version } = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf-8"))
6+
return {
7+
version,
8+
}
9+
})

services/amp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as amp from "@amplitude/analytics-browser"
22

33
const init = (t) => {
4+
if (!t) return
45
amp.init(t, { defaultTracking: true })
56
}
67

services/version.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const watchForUpdate = (currentVersion, callback) => {
2+
return setInterval(async () => {
3+
try {
4+
const { version } = await $fetch("/api/version")
5+
if (currentVersion !== version) callback(version)
6+
} catch (error) {
7+
console.error(`Error watchForUpdate: `, error)
8+
}
9+
}, 60_000)
10+
}

store/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useModalsStore } from "./modals"
22

33
export const useAppStore = defineStore("app", () => {
4+
const version = ref()
5+
46
const modalsStore = useModalsStore()
57

68
const network = ref()
@@ -45,6 +47,7 @@ export const useAppStore = defineStore("app", () => {
4547
}
4648

4749
return {
50+
version,
4851
network,
4952
head,
5053
gas,

0 commit comments

Comments
 (0)