Skip to content

Commit

Permalink
fix: check update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 14, 2021
1 parent 4fc7f28 commit 978a49f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/debug-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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] }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion app/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import packageJson from '../../package.json';

type Environments = 'development' | 'testing' | 'production';

export const NETWORK = process.env.STX_NETWORK as 'mainnet' | 'testnet';
Expand All @@ -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';

Expand Down
11 changes: 5 additions & 6 deletions app/hooks/use-check-for-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -22,17 +22,16 @@ 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]);

const isThereNewerRelease = latestReleases.some(release =>
compareVersions.compare(release.tag_name, WALLET_VERSION, '>')
);

setNewerReleaseAvailable(isThereNewerRelease);
}, []);

Expand Down

0 comments on commit 978a49f

Please sign in to comment.