Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suite-native): improve DAC error handling and report check result #15677

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions suite-native/analytics/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export enum EventType {
SendTransactionDispatched = 'send/transaction_dispatched',
SendFlowExited = 'send/flow_exited',
DeviceSettingsPinProtectionChange = 'device_settings/pin_protection_change',
DeviceSettingsAuthenticityCheck = 'device_settings/authenticity_check',
}
8 changes: 7 additions & 1 deletion suite-native/analytics/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FeeLevelLabel, TokenAddress, TokenSymbol } from '@suite-common/wallet-t
import { DeviceModelInternal, VersionArray } from '@trezor/connect';

import { EventType } from './constants';
import { AnalyticsSendFlowStep } from './types';
import { AnalyticsSendFlowStep, DeviceAuthenticityCheckResult } from './types';

export type SuiteNativeAnalyticsEvent =
| {
Expand Down Expand Up @@ -310,4 +310,10 @@ export type SuiteNativeAnalyticsEvent =
payload: {
action: 'enable' | 'change' | 'disable';
};
}
| {
type: EventType.DeviceSettingsAuthenticityCheck;
payload: {
result: DeviceAuthenticityCheckResult;
};
};
2 changes: 2 additions & 0 deletions suite-native/analytics/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export type AnalyticsSendFlowStep =
| 'address_review'
| 'outputs_review'
| 'destination_tag_review';

export type DeviceAuthenticityCheckResult = 'successful' | 'compromised' | 'cancelled' | 'failed';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { analytics, DeviceAuthenticityCheckResult, EventType } from '@suite-native/analytics';
import { selectDevice } from '@suite-common/wallet-core';
import { requestPrioritizedDeviceAccess } from '@suite-native/device-mutex';
import { useAlert } from '@suite-native/alerts';
Expand Down Expand Up @@ -31,6 +32,15 @@ export const DeviceAuthenticityCard = () => {

const device = useSelector(selectDevice);

const reportCheckResult = useCallback(
(result: DeviceAuthenticityCheckResult) =>
analytics.report({
type: EventType.DeviceSettingsAuthenticityCheck,
payload: { result },
}),
[],
);

const checkAuthenticity = useCallback(async () => {
navigation.navigate(DeviceStackRoutes.DeviceAuthenticity);

Expand All @@ -48,13 +58,25 @@ export const DeviceAuthenticityCard = () => {

const { success, payload } = result.payload;
if (success) {
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, {
checkResult: payload.valid ? 'successful' : 'compromised',
});
} else if (payload.code === 'Failure_ActionCancelled') {
navigation.goBack();
const checkResult = payload.valid ? 'successful' : 'compromised';
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, { checkResult });
reportCheckResult(checkResult);
} else {
PeKne marked this conversation as resolved.
Show resolved Hide resolved
const errorCode = payload.code;
if (errorCode === 'Failure_ActionCancelled' || errorCode === 'Failure_PinCancelled') {
navigation.goBack();
reportCheckResult('cancelled');
} else if (errorCode === 'Method_Interrupted') {
// navigation.goBack() already called via the X button
reportCheckResult('cancelled');
} else {
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, {
checkResult: 'compromised',
});
reportCheckResult('failed');
}
}
}, [navigation, device]);
}, [device, navigation, reportCheckResult]);

const showInfoAlert = useCallback(() => {
showAlert({
Expand Down
Loading