Skip to content

Commit

Permalink
chore(suite): tweak suite fw hash selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemonexe committed Oct 14, 2024
1 parent 0f49b0f commit a741e65
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/suite/src/reducers/suite/suiteReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import { isDeviceAcquired } from '@suite-common/suite-utils';
import { discoveryActions, DeviceRootState, selectDevice } from '@suite-common/wallet-core';
import { versionUtils } from '@trezor/utils';
import { isWeb } from '@trezor/env-utils';
import { TRANSPORT, TransportInfo, ConnectSettings } from '@trezor/connect';
import {
TRANSPORT,
TransportInfo,
ConnectSettings,
FirmwareHashCheckError,
FirmwareRevisionCheckError,
} from '@trezor/connect';

import { getIsTorEnabled, getIsTorLoading } from 'src/utils/suite/tor';
import type { OAuthServerEnvironment } from 'src/types/suite/metadata';
Expand Down Expand Up @@ -460,16 +466,20 @@ export const selectFirmwareRevisionCheckError = (state: StateForFirmwareChecks)
*/
const selectIsFirmwareRevisionCheckEnabledAndFailed = (state: StateForFirmwareChecks): boolean => {
const error = selectFirmwareRevisionCheckError(state);
const softErrors: FirmwareRevisionCheckError[] = [
'cannot-perform-check-offline',
'other-error',
];

return error ? !['cannot-perform-check-offline', 'other-error'].includes(error) : false;
return error !== null ? !softErrors.includes(error) : false;
};

/**
* Get firmware hash check error, or null if check was successful / skipped.
*/
export const selectFirmwareHashCheckError = (state: StateForFirmwareChecks) => {
const device = selectDevice(state);
if (!isDeviceAcquired(device) || !device.authenticityChecks) return false;
if (!isDeviceAcquired(device) || !device.authenticityChecks) return null;

const { isFirmwareHashCheckDisabled } = state.suite.settings;
const isDisabledByMessage = selectIsFeatureDisabled(state, Feature.firmwareHashCheck);
Expand All @@ -486,8 +496,9 @@ export const selectFirmwareHashCheckError = (state: StateForFirmwareChecks) => {
*/
const selectIsFirmwareHashCheckEnabledAndFailed = (state: StateForFirmwareChecks): boolean => {
const error = selectFirmwareHashCheckError(state);
const softErrors: FirmwareHashCheckError[] = ['check-skipped', 'check-unsupported'];

return error ? !['check-skipped', 'check-unsupported'].includes(error) : false;
return error !== null ? !softErrors.includes(error) : false;
};

/**
Expand Down

0 comments on commit a741e65

Please sign in to comment.