From 966b73de5ed62cde3b2103ac04c26b67c55e633c Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Fri, 5 Jan 2024 11:54:43 +0100 Subject: [PATCH] Add version check --- build.sh | 9 +++++++++ src/js/index.js | 23 +++++++++++++++++++++++ src/js/ui/UI.js | 7 +++++++ 3 files changed, 39 insertions(+) diff --git a/build.sh b/build.sh index 91ff5d1..e97b93d 100755 --- a/build.sh +++ b/build.sh @@ -3,3 +3,12 @@ NODE_ENV="development" BUILD_MODE="production" bash prepare.sh npm run build + +if [ "$GITHUB_REF" != "" ]; +then + version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`" + if [ "$version" != "" ]; + then + echo "$version" > ./dist/version.txt + fi +fi diff --git a/src/js/index.js b/src/js/index.js index 81ec0c7..ae4dffe 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -8,11 +8,33 @@ import "../less/style.less"; import LiquidWallet from "./LiquidWallet.js"; import UI from "./ui/UI.js"; import Html from "./ui/Html.js"; +import LinkOpener from "./utils/LinkOpener.js"; /** * The entry point for the Liquid Wallet APP */ +async function versionCheck(ui) { + try { + const currentVersion = await fetch("version.txt").then((r) => r.text()); + const latestGithubReleaseData = await fetch( + "https://api.github.com/repos/riccardobl/anser-liquid/releases/latest", + ).then((r) => r.json()); + if (!latestGithubReleaseData.tag_name) throw new Error("Cannot get latest version from github"); + const latestVersion = latestGithubReleaseData.tag_name; + if (currentVersion != latestVersion) { + const alertEl = ui.info( + "New version available: " + latestVersion + ". Click here to visit the release page.", + ); + alertEl.addEventListener("click", () => { + LinkOpener.navigate(latestGithubReleaseData.html_url); + }); + } + } catch (e) { + console.log(e); + } +} + async function main() { try { // Get the wallet element @@ -45,6 +67,7 @@ async function main() { } catch (e) { console.error(e); } + versionCheck(ui); } catch (e) { console.error(e); if (e.cause == "liquid_not_available") { diff --git a/src/js/ui/UI.js b/src/js/ui/UI.js index f4e8cf0..64e9b81 100644 --- a/src/js/ui/UI.js +++ b/src/js/ui/UI.js @@ -263,6 +263,10 @@ export default class UI { this.showAlert("alert", this.walletEl, ...args); } + perma(...args) { + this.showAlert("perma", this.walletEl, ...args); + } + showAlert(type, containerElement, ...args) { let alertContainerEl = containerElement.querySelector(".alertContainer"); if (!alertContainerEl) { @@ -282,6 +286,7 @@ export default class UI { let time = 5000; if (type === "error") time = 10000; if (type === "fatal") time = 60000; + if (type === "perma") time = 1000 * 60 * 60; const deletionTimeout = setTimeout(() => { alertContainerEl.removeChild(alertBox); }, time); @@ -289,6 +294,8 @@ export default class UI { clearTimeout(deletionTimeout); alertContainerEl.removeChild(alertBox); }); + + return alertBox; } }