Skip to content

Commit

Permalink
Add version check
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Jan 5, 2024
1 parent 06566ad commit 966b73d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") {
Expand Down
7 changes: 7 additions & 0 deletions src/js/ui/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -282,13 +286,16 @@ 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);
alertBox.addEventListener("click", () => {
clearTimeout(deletionTimeout);
alertContainerEl.removeChild(alertBox);
});

return alertBox;
}
}

Expand Down

0 comments on commit 966b73d

Please sign in to comment.