Skip to content

Commit

Permalink
show update warning when user is using older versions #1393
Browse files Browse the repository at this point in the history
  • Loading branch information
bassemmagdy committed Nov 24, 2021
1 parent d59ace8 commit 0e80ac9
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/config/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface LanguageConfig {
export interface AppConfig {
languages: LanguageConfig[];
articlesFeedUrl: string;
repositoryDataUrl: string;
constants: {
EVENTS_THROTTLING_TIME: number;
MAX_REMOTE_ACCOUNT_CHECKS: number;
Expand Down Expand Up @@ -59,6 +60,7 @@ const defaultAppConfig: AppConfig = {
],
marketServerUrl: 'http://app.nemcn.io',
articlesFeedUrl: 'https://symbol.github.io/symbol-rss-feeds/',
repositoryDataUrl: 'https://api.github.com/repos/symbol/desktop-wallet/releases/latest',
};
const resolvedAppConfig: AppConfig = window['appConfig'] || defaultAppConfig;
console.log('appConfig resolved!', resolvedAppConfig);
Expand Down
4 changes: 3 additions & 1 deletion src/language/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,5 +1132,7 @@
"transaction_cosignature_warning_proceed": "I understand and wish to proceed.",
"lock_hash_algorithm": "Hash Algorithm",
"not_enough_balance": "Not enough balance",
"use_max_value": "Use maximum value"
"use_max_value": "Use maximum value",
"new_version_available": "A new version of Symbol wallet is available!",
"download_now": " Download now"
}
4 changes: 3 additions & 1 deletion src/language/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,5 +1132,7 @@
"transaction_cosignature_warning_proceed": "確認しましたので署名に同意します",
"lock_hash_algorithm": "ハッシュアルゴリズム",
"not_enough_balance": "バランスが悪い",
"use_max_value": "最大値を使用"
"use_max_value": "最大値を使用",
"new_version_available": "シンボルウォレットの新しいバージョンが利用可能になりました!",
"download_now": " ダウンロード中"
}
4 changes: 3 additions & 1 deletion src/language/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,5 +1132,7 @@
"transaction_cosignature_warning_proceed": "Я понимаю и хочу продолжить.",
"lock_hash_algorithm": "алгоритм хеширования",
"not_enough_balance": "не хватает баланса",
"use_max_value": "Используйте максимальное значение"
"use_max_value": "Используйте максимальное значение",
"new_version_available": "Доступна новая версия кошелька Symbol!",
"download_now": " скачать сейчас"
}
4 changes: 3 additions & 1 deletion src/language/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,5 +1132,7 @@
"transaction_cosignature_warning_proceed": "我理解并请继续。",
"lock_hash_algorithm": "哈希算法",
"not_enough_balance": "余额不足",
"use_maximum_value": "使用最大值"
"use_maximum_value": "使用最大值",
"new_version_available": "新版本的 Symbol 钱包可用!",
"download_now": " 现在就下载"
}
52 changes: 52 additions & 0 deletions src/services/VersionCheckerService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* (C) Symbol Contributors 2021 (https://nem.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*
*/
import { appConfig } from '@/config';
import fetch from 'node-fetch';

/**
* Request github api for latest release
* @internal
* @return {Promise<LatestVersionObject>}
*/
const request = async (): Promise<LatestVersionObject> => {
let versionTag;
let downloadUrl;
await fetch(appConfig.repositoryDataUrl)
.then((response) => response.json()) //Converting the response to a JSON object
.then((data) => {
versionTag = data.tag_name;
downloadUrl = data.html_url;
})
.catch((error) => console.error(error));
return { versionTag, downloadUrl };
};
export type LatestVersionObject = {
versionTag: string;
downloadUrl: string;
};

export class VersionCheckerService {
/**
* Get latest version tag
* @return {Promise<{versionTag:string, downloadUrl:string}>}
*/
public async getLatestVersionTag(): Promise<LatestVersionObject> {
const versionObject = await request();
const versionTag = versionObject.versionTag.substring(1);
const downloadUrl = versionObject.downloadUrl;
return { versionTag, downloadUrl };
}
}
14 changes: 14 additions & 0 deletions src/views/pages/profiles/LoginPage.less
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,20 @@
}
}

.update-box {
background-color: #ffffcc;
margin-top: 0.05rem;
text-align: center;
height: 0.3rem;
width: 100%;
display: inline-block;
font-size: larger;
line-height: 0.3rem;
}

.download-text-color {
color: #44004e;
}
.navbar-icon {
margin-right: 10px;
font-size: 25px;
Expand Down
6 changes: 6 additions & 0 deletions src/views/pages/profiles/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<img class="language_icon" :src="require('@/views/resources/img/login/language.svg')" alt="" />
<LanguageSelector />
</div>

<div v-if="!latestVersionInUse" class="update-box" role="alert">
<b syle="">{{ $t('new_version_available') }}</b>
<a :href="versionCheckerObject.downloadUrl" target="_blank" class="download-text-color">{{ $t('download_now') }}</a>
</div>

<ValidationObserver v-slot="{ handleSubmit }" slim>
<form onsubmit="event.preventDefault()">
<div class="welcome-box">
Expand Down
14 changes: 13 additions & 1 deletion src/views/pages/profiles/LoginPageTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { AccountService } from '@/services/AccountService';
import { NetworkTypeHelper } from '@/core/utils/NetworkTypeHelper';
import { officialIcons } from '@/views/resources/Images';
import _ from 'lodash';
import { VersionCheckerService, LatestVersionObject } from '@/services/VersionCheckerService';
@Component({
computed: {
...mapGetters({
Expand All @@ -59,7 +60,8 @@ export default class LoginPageTs extends Vue {
* Display the application version. This is injected in the app when built.
*/
public packageVersion = process.env.PACKAGE_VERSION || '0';

public versionCheckerObject: LatestVersionObject = null;
public latestVersionInUse: boolean = true;
/**
* All known profiles
*/
Expand Down Expand Up @@ -111,6 +113,16 @@ export default class LoginPageTs extends Vue {
protected get profileNames(): string[] {
return this.profiles.map((p) => p.profileName);
}

public async mounted() {
if (navigator.onLine) {
const versionControlService = new VersionCheckerService();
this.versionCheckerObject = await versionControlService.getLatestVersionTag();
this.versionCheckerObject.versionTag = '1.0.7';
this.latestVersionInUse = this.versionCheckerObject.versionTag === process.env.PACKAGE_VERSION;
}
}

/**
* Hook called when the page is mounted
* @return {void}
Expand Down

0 comments on commit 0e80ac9

Please sign in to comment.