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 ae23c46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
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 ae23c46

Please sign in to comment.