Skip to content

Commit

Permalink
feat(suite-native): log FW revision check result to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemonexe committed Jan 17, 2025
1 parent d6e5f97 commit f35c261
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion suite-native/app/src/hooks/useGlobalHooks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useDetectDeviceError, useHandleDeviceConnection } from '@suite-native/device';
import {
useDetectDeviceError,
useHandleDeviceConnection,
useReportDeviceCompromised,
} from '@suite-native/device';
import { useConnectPopupNavigation } from '@suite-native/module-connect-popup';

import { useCoinEnablingInitialCheck } from './useCoinEnablingInitialCheck';
Expand All @@ -14,4 +18,5 @@ export const useGlobalHooks = () => {

useHandleDeviceConnection();
useDetectDeviceError();
useReportDeviceCompromised();
};
1 change: 1 addition & 0 deletions suite-native/device/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@suite-native/navigation": "workspace:*",
"@suite-native/settings": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/device-utils": "workspace:*",
"@trezor/styles": "workspace:*",
"lottie-react-native": "^7.1.0",
"react": "18.2.0",
Expand Down
38 changes: 38 additions & 0 deletions suite-native/device/src/hooks/useReportDeviceCompromised.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useSelector } from 'react-redux';
import { useEffect, useMemo } from 'react';

import * as Sentry from '@sentry/react-native';

import { getFirmwareVersion } from '@trezor/device-utils';
import { selectSelectedDevice } from '@suite-common/wallet-core';

import { selectFirmwareRevisionCheckError } from '../selectors';

const reportCheckFail = (checkType: 'Firmware revision', contextData: any) => {
Sentry.captureException(`${checkType} check failed! ${JSON.stringify(contextData)}`);
};

const useCommonData = () => {
const device = useSelector(selectSelectedDevice);
const model = device?.features?.internal_model;
const revision = device?.features?.revision;
const version = getFirmwareVersion(device);
const vendor = device?.features?.fw_vendor;

return useMemo(
() => ({ model, revision, version, vendor }),
[model, revision, version, vendor],
);
};

export const useReportDeviceCompromised = () => {
const commonData = useCommonData();

const revisionCheckError = useSelector(selectFirmwareRevisionCheckError);

useEffect(() => {
if (revisionCheckError !== null) {
reportCheckFail('Firmware revision', { ...commonData, revisionCheckError });
}
}, [commonData, revisionCheckError]);
};
1 change: 1 addition & 0 deletions suite-native/device/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './middlewares/buttonRequestMiddleware';
export * from './hooks/useHandleDeviceConnection';
export * from './hooks/useDetectDeviceError';
export * from './hooks/useReportDeviceConnectToAnalytics';
export * from './hooks/useReportDeviceCompromised';
export * from './components/ConnectDeviceAnimation';
export * from './components/ConfirmOnTrezorImage';
export * from './components/ConnectorImage';
Expand Down
1 change: 1 addition & 0 deletions suite-native/device/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{ "path": "../navigation" },
{ "path": "../settings" },
{ "path": "../../packages/connect" },
{ "path": "../../packages/device-utils" },
{ "path": "../../packages/styles" }
],
"include": [".", "**/*.json"]
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10289,6 +10289,7 @@ __metadata:
"@suite-native/navigation": "workspace:*"
"@suite-native/settings": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/device-utils": "workspace:*"
"@trezor/styles": "workspace:*"
lottie-react-native: "npm:^7.1.0"
react: "npm:18.2.0"
Expand Down

0 comments on commit f35c261

Please sign in to comment.