Skip to content

Commit

Permalink
fix(suite-native): improve DAC error handling and report check result
Browse files Browse the repository at this point in the history
  • Loading branch information
yanascz committed Dec 2, 2024
1 parent ce41c4d commit 0b93197
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
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 {
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

0 comments on commit 0b93197

Please sign in to comment.