Skip to content

Commit

Permalink
fix(suite): display other-error in FirmwareRevisionCheckBanner
Browse files Browse the repository at this point in the history
  • Loading branch information
komret committed Sep 30, 2024
1 parent 00d7787 commit feac8db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe.each(DeviceNames)(`${checkFirmwareRevision.name} for device %s`, intern
expected: { success: false, error: 'cannot-perform-check-offline' },
},
{
it: 'fails with a generic error message when there is an error when reading the online verison of releases.json',
it: 'fails with a generic error message when there is an error when reading the online version of releases.json',
httpRequestMock: () => {
throw new Error('There is an unexpected error!');
},
Expand Down
2 changes: 0 additions & 2 deletions packages/connect/src/device/checkFirmwareRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const checkFirmwareRevision = async ({
deviceRevision,
expectedRevision,
}: CheckFirmwareRevisionParams): Promise<FirmwareRevisionCheckResult> => {
console.log(expectedRevision);
if (expectedRevision === undefined) {
if (firmwareVersion.length !== 3) {
return failFirmwareRevisionCheck('firmware-version-unknown');
Expand All @@ -70,7 +69,6 @@ export const checkFirmwareRevision = async ({
firmwareVersion,
internalModel,
});
console.log('onlineRelease', onlineRelease);

if (onlineRelease?.firmware_revision === undefined) {
return failFirmwareRevisionCheck('firmware-version-unknown');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { isDeviceAcquired } from '@suite-common/suite-utils';
import { selectDevice } from '@suite-common/wallet-core';
import { Banner } from '@trezor/components';
import { FirmwareRevisionCheckError } from '@trezor/connect';
import { HELP_CENTER_FIRMWARE_REVISION_CHECK } from '@trezor/urls';

import { Translation, TrezorLink } from 'src/components/suite';
import { useSelector } from 'src/hooks/suite';

const getMessage = (error: FirmwareRevisionCheckError) => {
switch (error) {
case 'cannot-perform-check-offline':
return 'TR_DEVICE_FIRMWARE_REVISION_CHECK_UNABLE_TO_PERFORM';
case 'other-error':
return 'TR_FIRMWARE_REVISION_CHECK_OTHER_ERROR';
default:
return 'TR_FIRMWARE_REVISION_CHECK_FAILED';
}
};

export const FirmwareRevisionCheckBanner = () => {
const device = useSelector(selectDevice);

if (
!isDeviceAcquired(device) ||
device.authenticityChecks?.firmwareRevision?.success !== false
) {
return null;
}

const message = getMessage(device.authenticityChecks.firmwareRevision.error);
const wasOffline =
device?.features &&
device.authenticityChecks?.firmwareRevision?.success === false &&
device.authenticityChecks.firmwareRevision.error === 'cannot-perform-check-offline';
const message = wasOffline
? 'TR_DEVICE_FIRMWARE_REVISION_CHECK_UNABLE_TO_PERFORM'
: 'TR_FIRMWARE_REVISION_CHECK_FAILED';

return (
<Banner
Expand Down
6 changes: 4 additions & 2 deletions packages/suite/src/reducers/suite/suiteReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@ export const selectIsFirmwareRevisionCheckEnabledAndFailed = (
isDeviceAcquired(device) &&
// If `check` is null, it means that it was not performed yet.
device.authenticityChecks?.firmwareRevision?.success === false &&
// If Suite is offline and we cannot perform check, the error banner shows to urge user to go online.
device.authenticityChecks.firmwareRevision.error !== 'cannot-perform-check-offline'
// If Suite is offline and cannot perform check or there is some unexpected error, an error banner is shown but Suite is otherwise unaffected.
!['cannot-perform-check-offline', 'other-error'].includes(
device.authenticityChecks.firmwareRevision.error,
)
);
};

Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7112,6 +7112,10 @@ export default defineMessages({
defaultMessage:
"Firmware revision check couldn't be performed. Go online to verify your firmware version.",
},
TR_FIRMWARE_REVISION_CHECK_OTHER_ERROR: {
id: 'TR_FIRMWARE_REVISION_CHECK_OTHER_ERROR',
defaultMessage: 'Firmware revision check could not be performed.',
},
TR_ONBOARDING_COINS_STEP: {
id: 'TR_ONBOARDING_COINS_STEP',
defaultMessage: 'Activate coins',
Expand Down

0 comments on commit feac8db

Please sign in to comment.