Skip to content

Commit

Permalink
fix: use earliest stacks app version check
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jul 13, 2021
1 parent 0686cf8 commit 387a74b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const LATEST_LEDGER_VERSION_MAJOR = 0;

export const LATEST_LEDGER_VERSION_MINOR = 14;

export const SUPPORTED_LEDGER_VERSIONS_MINOR = [11, LATEST_LEDGER_VERSION_MINOR];
export const EARLIEST_SUPPORTED_LEDGER_VERSION = '0.11.0';

export const DEFAULT_POLLING_INTERVAL = 10_000;

Expand Down
21 changes: 16 additions & 5 deletions app/hooks/use-prepare-ledger.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect, useMemo, useState } from 'react';
import { LedgerError } from '@zondax/ledger-blockstack';
import compareVersions from 'compare-versions';
import { Observable } from 'rxjs';
import { filter } from 'rxjs/operators';
import {
EARLIEST_SUPPORTED_LEDGER_VERSION,
LATEST_LEDGER_VERSION_MAJOR,
LATEST_LEDGER_VERSION_MINOR,
SUPPORTED_LEDGER_VERSIONS_MINOR,
} from '@constants/index';

import type { LedgerMessageEvents } from '../main/register-ledger-listeners';
Expand Down Expand Up @@ -45,7 +46,9 @@ export function usePrepareLedger() {
const isSupportedAppVersion = useMemo(() => {
if (appVersion === null) return true;
if (!versionSupportsTestnetLedger && isTestnet()) return false;
return SUPPORTED_LEDGER_VERSIONS_MINOR.includes(appVersion.minor);
const { major, minor, patch } = appVersion;
const currentVersion = `${major}.${minor}.${patch}`;
return compareVersions.compare(currentVersion, EARLIEST_SUPPORTED_LEDGER_VERSION, '>=');
}, [appVersion, versionSupportsTestnetLedger]);

const appVersionErrorText = useMemo(() => {
Expand All @@ -58,10 +61,18 @@ export function usePrepareLedger() {
? 'You should also upgrade your Stacks Wallet to the latest version.'
: ''
}
This version of the Stacks Wallet only works with ${LATEST_LEDGER_VERSION_MAJOR}.${LATEST_LEDGER_VERSION_MINOR}.
Detected version ${String(appVersion?.major)}.${String(appVersion?.minor)}
This version of the Stacks Wallet works with ${EARLIEST_SUPPORTED_LEDGER_VERSION} onwards.
Detected version ${String(appVersion?.major)}.${String(appVersion?.minor)}.${String(
appVersion?.patch
)}
`;
}, [appVersion?.major, appVersion?.minor, isNewerReleaseAvailable, versionSupportsTestnetLedger]);
}, [
appVersion?.major,
appVersion?.minor,
appVersion?.patch,
isNewerReleaseAvailable,
versionSupportsTestnetLedger,
]);

useListenLedgerEffect();

Expand Down

0 comments on commit 387a74b

Please sign in to comment.