From 978a49f85296eb2b1533b20568b273eebabbfe15 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Sun, 10 Jan 2021 11:20:35 +0100 Subject: [PATCH] fix: check update logic --- .github/workflows/debug-build.yml | 1 - .github/workflows/publish-version.yml | 1 - app/constants/index.ts | 4 +++- app/hooks/use-check-for-updates.ts | 11 +++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/debug-build.yml b/.github/workflows/debug-build.yml index b78cda46c..bffbf85c8 100644 --- a/.github/workflows/debug-build.yml +++ b/.github/workflows/debug-build.yml @@ -103,7 +103,6 @@ jobs: SHA: ${{ github.event.pull_request.head.sha }} NODE_ENV: production GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WALLET_VERSION: ${{ steps.extract_version.outputs.version }} PULL_REQUEST: ${{ steps.vars.outputs.pull_request_id }} BRANCH_NAME: ${{ steps.vars.outputs.branch_name }} CSC_LINK: ${{ secrets[matrix.CSC_LINK_SECRET_NAME] }} diff --git a/.github/workflows/publish-version.yml b/.github/workflows/publish-version.yml index 6f30b69f7..4983b9420 100644 --- a/.github/workflows/publish-version.yml +++ b/.github/workflows/publish-version.yml @@ -98,7 +98,6 @@ jobs: SHA: ${{ github.event.pull_request.head.sha }} PULL_REQUEST: ${{ steps.vars.outputs.pull_request_id }} BRANCH_NAME: ${{ steps.vars.outputs.branch_name }} - WALLET_VERSION: ${{ steps.extract_version.outputs.version }} CSC_LINK: ${{ secrets[matrix.CSC_LINK_SECRET_NAME] }} CSC_KEY_PASSWORD: ${{ secrets[matrix.CSC_KEY_PASSWORD_SECRET_NAME] }} APPLE_ID: ${{ secrets.APPLE_ID }} diff --git a/app/constants/index.ts b/app/constants/index.ts index 97f76eb3d..65ea9ba87 100644 --- a/app/constants/index.ts +++ b/app/constants/index.ts @@ -1,3 +1,5 @@ +import packageJson from '../../package.json'; + type Environments = 'development' | 'testing' | 'production'; export const NETWORK = process.env.STX_NETWORK as 'mainnet' | 'testnet'; @@ -14,7 +16,7 @@ export const ENTITY_NAME = 'Blockstack'; export const FULL_ENTITY_NAME = 'Blockstack PBC'; -export const WALLET_VERSION = process.env.WALLET_VERSION || 'v0.0.0'; +export const WALLET_VERSION = packageJson.version; export const BUY_STX_URL = 'https://coinmarketcap.com/currencies/blockstack/markets'; diff --git a/app/hooks/use-check-for-updates.ts b/app/hooks/use-check-for-updates.ts index 1a7baead6..0606d2895 100644 --- a/app/hooks/use-check-for-updates.ts +++ b/app/hooks/use-check-for-updates.ts @@ -2,12 +2,12 @@ import { useCallback, useEffect, useState } from 'react'; import compareVersions from 'compare-versions'; import { checkForNewRelease, GithubReleases } from '@api/check-for-new-release'; -import { safeAwait } from '@utils/safe-await'; import { WALLET_VERSION, NETWORK } from '@constants/index'; +import { safeAwait } from '@utils/safe-await'; import { useInterval } from './use-interval'; const UPDATE_CHECK_INTERVAL = 120_000; -const NEW_WALLET_STARTING_MAJOR_VERSION = 4; +const NEW_WALLET_STARTING_MAJOR_VERSION = NETWORK === 'mainnet' ? '4.0.0' : '4.0.0-beta.0'; export function useCheckForUpdates() { const [newerReleaseAvailable, setNewerReleaseAvailable] = useState(false); @@ -22,10 +22,8 @@ export function useCheckForUpdates() { .filter(release => compareVersions.validate(release.tag_name)) .filter(release => (NETWORK === 'mainnet' ? !release.prerelease : release.prerelease)) .filter(release => release.tag_name.startsWith('v')) - .filter( - release => - typeof release.tag_name[1] === 'number' && - release.tag_name[1] >= NEW_WALLET_STARTING_MAJOR_VERSION + .filter(release => + compareVersions.compare(release.tag_name, NEW_WALLET_STARTING_MAJOR_VERSION, '>') ); if (latestReleases[0]) setLatestRelease(latestReleases[0]); @@ -33,6 +31,7 @@ export function useCheckForUpdates() { const isThereNewerRelease = latestReleases.some(release => compareVersions.compare(release.tag_name, WALLET_VERSION, '>') ); + setNewerReleaseAvailable(isThereNewerRelease); }, []);